Fix quoted string parsing for commands

This commit is contained in:
Jeff 2024-01-25 08:57:55 -05:00
parent 70ad08128c
commit 9a65afa083
5 changed files with 23023 additions and 21832 deletions

View File

@ -17,7 +17,14 @@ impl AbstractTree for Command {
for index in 1..node.child_count() {
let text_node = node.child(index).unwrap();
let text = source[text_node.byte_range()].to_string();
let mut text = source[text_node.byte_range()].to_string();
if (text.starts_with('\'') && text.ends_with('\''))
|| (text.starts_with('"') && text.ends_with('"'))
|| (text.starts_with('`') && text.ends_with('`'))
{
text = text[1..text.len() - 1].to_string();
}
command_texts.push(text);
}

View File

@ -90,7 +90,11 @@ module.exports = grammar({
),
),
command_text: $ => /\S+/,
command_text: $ =>
choice(
/\S+/,
/("[^"]*?")|('[^']*?')|(`[^`]*?`)/,
),
block: $ =>
seq(

View File

@ -246,8 +246,17 @@
}
},
"command_text": {
"type": "PATTERN",
"value": "\\S+"
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\S+"
},
{
"type": "PATTERN",
"value": "(\"[^\"]*?\")|('[^']*?')|(`[^`]*?`)"
}
]
},
"block": {
"type": "SEQ",

View File

@ -71,6 +71,11 @@
]
}
},
{
"type": "command_text",
"named": true,
"fields": {}
},
{
"type": "else",
"named": true,
@ -621,6 +626,11 @@
]
}
},
{
"type": "string",
"named": true,
"fields": {}
},
{
"type": "structure",
"named": true,
@ -899,10 +909,6 @@
"type": "collection",
"named": false
},
{
"type": "command_text",
"named": true
},
{
"type": "else",
"named": false
@ -1011,10 +1017,6 @@
"type": "string",
"named": false
},
{
"type": "string",
"named": true
},
{
"type": "struct",
"named": false

File diff suppressed because it is too large Load Diff