Add quoted argument
This commit is contained in:
parent
c81ec16963
commit
539e1dc77e
49
corpus/quoted_argument.txt
Normal file
49
corpus/quoted_argument.txt
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
=========================
|
||||||
|
One empty quoted argument
|
||||||
|
=========================
|
||||||
|
|
||||||
|
message("")
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(command_invocation
|
||||||
|
(identifier)
|
||||||
|
(arguments
|
||||||
|
(argument (quoted_argument))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
===================
|
||||||
|
One quoted argument
|
||||||
|
===================
|
||||||
|
|
||||||
|
message("An argument")
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(command_invocation
|
||||||
|
(identifier)
|
||||||
|
(arguments
|
||||||
|
(argument (quoted_argument))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
====================
|
||||||
|
Two quoted arguments
|
||||||
|
====================
|
||||||
|
|
||||||
|
message("First argument" "Second argument")
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(command_invocation
|
||||||
|
(identifier)
|
||||||
|
(arguments
|
||||||
|
(argument (quoted_argument))
|
||||||
|
(seperation (space))
|
||||||
|
(argument (quoted_argument))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
|
@ -22,6 +22,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
argument: $ => choice(
|
argument: $ => choice(
|
||||||
$.bracket_argument,
|
$.bracket_argument,
|
||||||
|
$.quoted_argument,
|
||||||
$.unquoted_argument,
|
$.unquoted_argument,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -35,6 +36,13 @@ module.exports = grammar({
|
||||||
_bracket_content: $ => repeat1(/[^\]]/),
|
_bracket_content: $ => repeat1(/[^\]]/),
|
||||||
_bracket_close: $ => seq(']', repeat('='), ']'),
|
_bracket_close: $ => seq(']', repeat('='), ']'),
|
||||||
|
|
||||||
|
quoted_argument: $ => seq('"', repeat($._quoted_element), '"'),
|
||||||
|
_quoted_element: $ => choice(
|
||||||
|
/[^\\"]/,
|
||||||
|
$.escape_sequence,
|
||||||
|
seq('\\', $.newline),
|
||||||
|
),
|
||||||
|
|
||||||
unquoted_argument: $ => repeat1(
|
unquoted_argument: $ => repeat1(
|
||||||
choice(
|
choice(
|
||||||
/[^ ()#\"\\]/,
|
/[^ ()#\"\\]/,
|
||||||
|
|
|
@ -86,6 +86,10 @@
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "bracket_argument"
|
"name": "bracket_argument"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "quoted_argument"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "unquoted_argument"
|
"name": "unquoted_argument"
|
||||||
|
@ -164,6 +168,52 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"quoted_argument": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_quoted_element"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"_quoted_element": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[^\\\\\"]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "escape_sequence"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\\"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "newline"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"unquoted_argument": {
|
"unquoted_argument": {
|
||||||
"type": "REPEAT1",
|
"type": "REPEAT1",
|
||||||
"content": {
|
"content": {
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
"type": "bracket_argument",
|
"type": "bracket_argument",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "quoted_argument",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "unquoted_argument",
|
"type": "unquoted_argument",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -89,6 +93,25 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "quoted_argument",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "escape_sequence",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "newline",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "seperation",
|
"type": "seperation",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -138,6 +161,10 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "\"",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "(",
|
"type": "(",
|
||||||
"named": false
|
"named": false
|
||||||
|
@ -154,6 +181,10 @@
|
||||||
"type": "[",
|
"type": "[",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "\\",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "\\n",
|
"type": "\\n",
|
||||||
"named": false
|
"named": false
|
||||||
|
|
1545
src/parser.c
1545
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue