Skip to content

Commit

Permalink
updates to kleenes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 4, 2024
1 parent 2f5bb0c commit 308e4cc
Show file tree
Hide file tree
Showing 6 changed files with 2,922 additions and 2,889 deletions.
51 changes: 12 additions & 39 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = grammar({
inline: (
$,
) => [
$._dependency_call,
$._dependency_with_args,
$._expression_braced,
$._expression_recurse,
],
Expand Down Expand Up @@ -204,6 +204,7 @@ module.exports = grammar({
attribute: ($) =>
seq("[", field("contents", comma_sep1($.identifier)), "]", $.eol),

// A complete recipe
// recipe : attribute? '@'? NAME parameter* variadic_parameters? ':' dependency* body?
recipe: ($) =>
seq(
Expand All @@ -223,7 +224,7 @@ module.exports = grammar({
),

parameters: ($) =>
seq(repeat1($.parameter), optional($.variadic_parameter)),
seq(repeat($.parameter), choice($.parameter, $.variadic_parameter)),

// parameter : '$'? NAME
// | '$'? NAME '=' value
Expand All @@ -237,7 +238,7 @@ module.exports = grammar({
// variadic_parameters : '*' parameter
// | '+' parameter
variadic_parameter: ($) =>
seq(field("kleen", choice("*", "+")), $.parameter),
seq(field("kleene", choice("*", "+")), $.parameter),

dependencies: ($) => repeat1($.dependency),

Expand All @@ -246,10 +247,11 @@ module.exports = grammar({
dependency: ($) =>
choice(
field("recipe", $.identifier),
field("call", seq("(", $._dependency_call, ")")),
field("call", seq("(", $._dependency_with_args, ")")),
),

_dependency_call: ($) =>
// contents of `(recipe expression)`
_dependency_with_args: ($) =>
seq(
field("recipe", $.identifier),
repeat(field("expression", $.expression)),
Expand All @@ -272,20 +274,9 @@ module.exports = grammar({

recipe_line_prefix: (_) => choice("@-", "-@", "@", "-"),

// recipe_line_inl: ($) =>
// seq(
// $.notcomment,
// // repeat(choice($.interpolation, $.notinterpolation)),
// repeat(choice($.interpolation, $.text)),
// $._newline,
// ),
shebang: ($) =>
seq(
/\s*#!.*/,
$._newline,
),
// notcomment: ($) => /[^#\s{]\S*/,
// notcomment: (_) => /[^#\s]\S*/,
shebang: ($) => seq(/\s*#!.*/, $._newline),

// `# ...` comment
comment: ($) => seq(/#.*/, $._newline),

// notinterpolation: ($) => /[^{][^{]\S*/,
Expand All @@ -301,28 +292,10 @@ module.exports = grammar({
raw_string: (_) => /'[^']*'/,
raw_string_indented: (_) => seq("'''", repeat(/./), "'''"),
basic_string: ($) =>
seq(
'"',
repeat(
choice(
$.string_escape,
/[^\\"]+/,
),
),
'"',
),
seq('"', repeat(choice($.string_escape, /[^\\"]+/)), '"'),
// string_basic: (_) => /".*"/m, // # also processes \n \r \t \" \\ escapes
basic_string_indented: ($) =>
seq(
'"""',
repeat(
choice(
$.string_escape,
/[^\\"]+/,
),
),
'"""',
),
seq('"""', repeat(choice($.string_escape, /[^\\"]+/)), '"""'),
string_escape: (_) => /\\[nrt"\\]/,
text: (_) => /.+/, //recipe TEXT, only matches in a recipe body
// text: (_) => /\S+/, //recipe TEXT, only matches in a recipe body
Expand Down
15 changes: 8 additions & 7 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "parameter"
Expand All @@ -982,10 +982,11 @@
"members": [
{
"type": "SYMBOL",
"name": "variadic_parameter"
"name": "parameter"
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "variadic_parameter"
}
]
}
Expand Down Expand Up @@ -1046,7 +1047,7 @@
"members": [
{
"type": "FIELD",
"name": "kleen",
"name": "kleene",
"content": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -1097,7 +1098,7 @@
},
{
"type": "SYMBOL",
"name": "_dependency_call"
"name": "_dependency_with_args"
},
{
"type": "STRING",
Expand All @@ -1108,7 +1109,7 @@
}
]
},
"_dependency_call": {
"_dependency_with_args": {
"type": "SEQ",
"members": [
{
Expand Down Expand Up @@ -1436,7 +1437,7 @@
}
],
"inline": [
"_dependency_call",
"_dependency_with_args",
"ReferenceError",
"_expression_recurse"
],
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@
"type": "variadic_parameter",
"named": true,
"fields": {
"kleen": {
"kleene": {
"multiple": false,
"required": true,
"types": [
Expand Down
Loading

0 comments on commit 308e4cc

Please sign in to comment.