1
0

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() { for index in 1..node.child_count() {
let text_node = node.child(index).unwrap(); 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); command_texts.push(text);
} }

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff