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

View file

@ -12,6 +12,19 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "newline" "name": "newline"
}, },
"seperation": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "space"
},
{
"type": "SYMBOL",
"name": "line_ending"
}
]
},
"space": { "space": {
"type": "PATTERN", "type": "PATTERN",
"value": "[ \\t]+" "value": "[ \\t]+"
@ -30,19 +43,89 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "unquoted_argument" "name": "unquoted_argument"
}
]
},
"seperation": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "space"
}, },
{ {
"type": "SYMBOL", "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": { "_seperated_arguments": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 1, "value": 0,
"content": { "content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -139,10 +222,6 @@
"value": ")" "value": ")"
} }
] ]
},
"unquoted_argument": {
"type": "PATTERN",
"value": "[^ ()#\\\"\\\\]+"
} }
}, },
"extras": [ "extras": [

View file

@ -7,6 +7,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "bracket_argument",
"named": true
},
{ {
"type": "unquoted_argument", "type": "unquoted_argument",
"named": true "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", "type": "command_invocation",
"named": true, "named": true,
@ -109,6 +151,11 @@
] ]
} }
}, },
{
"type": "unquoted_argument",
"named": true,
"fields": {}
},
{ {
"type": "(", "type": "(",
"named": false "named": false
@ -117,6 +164,18 @@
"type": ")", "type": ")",
"named": false "named": false
}, },
{
"type": "=",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "]",
"named": false
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -128,9 +187,5 @@
{ {
"type": "space", "type": "space",
"named": true "named": true
},
{
"type": "unquoted_argument",
"named": true
} }
] ]

File diff suppressed because it is too large Load diff