Add brack argument

This commit is contained in:
Uy Ha 2021-04-10 21:55:47 +02:00
parent 9fefdcb89d
commit 1e1738a814
5 changed files with 1046 additions and 457 deletions

View file

@ -0,0 +1,42 @@
======================
Empty bracket argument
======================
message([[]])
---
(source_file
(command_invocation
(identifier)
(arguments
(argument
(bracket_argument
(bracket_open)
(bracket_close)
)
)
)
)
)
======================
One bracket argument
======================
message([[An argument]])
---
(source_file
(command_invocation
(identifier)
(arguments
(argument
(bracket_argument
(bracket_open)
(bracket_content)
(bracket_close)
)
)
)
)
)

View file

@ -5,15 +5,30 @@ module.exports = grammar({
source_file: $ => repeat($.command_invocation),
line_ending: $ => $.newline,
seperation: $ => choice($.space, $.line_ending),
space: $ => /[ \t]+/,
newline: $ => /\n/,
identifier: $ => /[A-Za-z_][A-Za-z0-9_]*/,
argument: $ => choice($.unquoted_argument),
seperation: $ => choice($.space, $.line_ending),
argument: $ => choice(
$.unquoted_argument,
$.bracket_argument,
),
unquoted_argument: $ => repeat1(/[^ ()#\"\\]/),
bracket_argument: $ => seq(
$.bracket_open,
optional($.bracket_content),
$.bracket_close,
),
bracket_open: $ => seq('[', repeat('='), '['),
bracket_content: $ => repeat1(/[^\]]/),
bracket_close: $ => seq(']', repeat('='), ']'),
arguments: $ => seq($.argument, repeat($._seperated_arguments)),
_seperated_arguments: $ => prec.left(1, seq(
_seperated_arguments: $ => prec.left(seq(
repeat1($.seperation),
optional($.argument)
)),
@ -28,6 +43,5 @@ module.exports = grammar({
')'
),
unquoted_argument: $ => /[^ ()#\"\\]+/,
}
})

View file

@ -12,6 +12,19 @@
"type": "SYMBOL",
"name": "newline"
},
"seperation": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "space"
},
{
"type": "SYMBOL",
"name": "line_ending"
}
]
},
"space": {
"type": "PATTERN",
"value": "[ \\t]+"
@ -30,19 +43,89 @@
{
"type": "SYMBOL",
"name": "unquoted_argument"
}
]
},
"seperation": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "space"
},
{
"type": "SYMBOL",
"name": "line_ending"
"name": "bracket_argument"
}
]
},
"unquoted_argument": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^ ()#\\\"\\\\]"
}
},
"bracket_argument": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "bracket_open"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "bracket_content"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "bracket_close"
}
]
},
"bracket_open": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": "="
}
},
{
"type": "STRING",
"value": "["
}
]
},
"bracket_content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^\\]]"
}
},
"bracket_close": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "]"
},
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": "="
}
},
{
"type": "STRING",
"value": "]"
}
]
},
@ -64,7 +147,7 @@
},
"_seperated_arguments": {
"type": "PREC_LEFT",
"value": 1,
"value": 0,
"content": {
"type": "SEQ",
"members": [
@ -139,10 +222,6 @@
"value": ")"
}
]
},
"unquoted_argument": {
"type": "PATTERN",
"value": "[^ ()#\\\"\\\\]+"
}
},
"extras": [

View file

@ -7,6 +7,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "bracket_argument",
"named": true
},
{
"type": "unquoted_argument",
"named": true
@ -33,6 +37,44 @@
]
}
},
{
"type": "bracket_argument",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "bracket_close",
"named": true
},
{
"type": "bracket_content",
"named": true
},
{
"type": "bracket_open",
"named": true
}
]
}
},
{
"type": "bracket_close",
"named": true,
"fields": {}
},
{
"type": "bracket_content",
"named": true,
"fields": {}
},
{
"type": "bracket_open",
"named": true,
"fields": {}
},
{
"type": "command_invocation",
"named": true,
@ -109,6 +151,11 @@
]
}
},
{
"type": "unquoted_argument",
"named": true,
"fields": {}
},
{
"type": "(",
"named": false
@ -117,6 +164,18 @@
"type": ")",
"named": false
},
{
"type": "=",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{
"type": "identifier",
"named": true
@ -128,9 +187,5 @@
{
"type": "space",
"named": true
},
{
"type": "unquoted_argument",
"named": true
}
]

File diff suppressed because it is too large Load diff