Skip to content

Commit

Permalink
Add parsing of def-parameter default values
Browse files Browse the repository at this point in the history
  • Loading branch information
LhKipp committed Jul 10, 2022
1 parent db4e990 commit 695e3ec
Show file tree
Hide file tree
Showing 6 changed files with 10,656 additions and 7,505 deletions.
14 changes: 11 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const OPERATOR_PREC = [


const SPECIAL_CHARACTERS = [
"'", '"', '`',
"'", '"', '`', '@',
'{', '}',
'\\[', '\\]',
'(', ')',
Expand Down Expand Up @@ -148,13 +148,15 @@ module.exports = grammar({
$.identifier,
optional(seq(':', $.type)),
optional('?'),
optional($.default_parameter_assignment),
),
flag: $ => seq(
$.flag_name,
optional(
seq('(', $.flag_shorthand_name, ')')
),
optional(seq(':', $.type)),
optional($.default_parameter_assignment),
),
flag_name: $ => /--[a-zA-Z_]+[a-zA-Z_0-9]*/,
flag_shorthand_name: $ => /-[a-zA-Z0-9]/,
Expand All @@ -177,6 +179,11 @@ module.exports = grammar({
"error",
"binary",
),
default_parameter_assignment: $ => seq(
choice(
seq("=", $._cmd_expr),
seq("@", $.identifier))
),

variable_declaration: $ => seq(
'let',
Expand All @@ -187,10 +194,11 @@ module.exports = grammar({

command: $ => seq(
field('cmd_name', seq($.identifier, optional('?'))),
repeat(field('arg', $._cmd_expr)), // ITS OVER 9000
repeat(field('arg', $._cmd_expr)),
choice($._cmd_newline, $._terminator)
// prec(9002,$._terminator)
// repeat(field('arg', $._cmd_expr)) // ITS OVER 9000
// ITS OVER 9000
// ^- Thanks to my previous me for the meme. Had a good laugh for this random comment :)
),

_expression: $ => choice(
Expand Down
62 changes: 61 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "defaultParameterAssignment"
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -428,6 +440,18 @@
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "defaultParameterAssignment"
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -526,6 +550,42 @@
}
]
},
"defaultParameterAssignment": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "_cmd_expr"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "@"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
]
}
]
},
"variable_declaration": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -748,7 +808,7 @@
"members": [
{
"type": "PATTERN",
"value": "[^'\"`{}\\[\\]()\\\\\\s$;.|#\\-]"
"value": "[^'\"`@{}\\[\\]()\\\\\\s$;.|#\\-]"
},
{
"type": "SEQ",
Expand Down
75 changes: 75 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,69 @@
}
}
},
{
"type": "defaultParameterAssignment",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "array",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "cmd_invocation",
"named": true
},
{
"type": "file_path",
"named": true
},
{
"type": "flag_arg",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "number_literal",
"named": true
},
{
"type": "range",
"named": true
},
{
"type": "record_or_block",
"named": true
},
{
"type": "string",
"named": true
},
{
"type": "table",
"named": true
},
{
"type": "value_path",
"named": true
},
{
"type": "word",
"named": true
}
]
}
},
{
"type": "env_export",
"named": true,
Expand Down Expand Up @@ -720,6 +783,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "defaultParameterAssignment",
"named": true
},
{
"type": "flag_name",
"named": true
Expand Down Expand Up @@ -844,6 +911,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "defaultParameterAssignment",
"named": true
},
{
"type": "identifier",
"named": true
Expand Down Expand Up @@ -1423,6 +1494,10 @@
"type": "?",
"named": false
},
{
"type": "@",
"named": false
},
{
"type": "[",
"named": false
Expand Down
Loading

0 comments on commit 695e3ec

Please sign in to comment.