Allow $ in strings

This commit is contained in:
Max Brunsfeld 2018-03-01 09:54:08 -08:00
parent c7e42b8e96
commit 384d920af5
4 changed files with 61556 additions and 60091 deletions

View File

@ -252,6 +252,19 @@ echo "\"The great escape\`\${var}"
(program (command (command_name (word)) (string)))
======================================
Strings containing special characters
======================================
echo "s/$/'/"
echo "#"
---
(program
(command (command_name (word)) (string))
(command (command_name (word)) (string)))
=========================================
Variable declaration: declare & typeset
=========================================

View File

@ -293,6 +293,7 @@ module.exports = grammar({
$.raw_string,
$.expansion,
$.simple_expansion,
$.string_expansion,
$.command_substitution,
$.process_substitution
),
@ -317,7 +318,7 @@ module.exports = grammar({
'"',
repeat(seq(
choice(
$._string_content,
seq(optional('$'), $._string_content),
$.expansion,
$.simple_expansion,
$.command_substitution
@ -327,7 +328,7 @@ module.exports = grammar({
'"'
),
_string_content: $ => /([^"`$]|\\.)+/,
_string_content: $ => token(prec(-1, /([^"`$]|\\.)+/)),
array: $ => seq(
'(',
@ -342,11 +343,12 @@ module.exports = grammar({
choice(
$._simple_variable_name,
$._special_variable_name,
alias('#', $.special_variable_name),
$.string
alias('#', $.special_variable_name)
)
),
string_expansion: $ => seq('$', $.string),
expansion: $ => seq(
'${',
optional('#'),
@ -382,7 +384,7 @@ module.exports = grammar({
')'
),
comment: $ => token(prec(-1, /#.*/)),
comment: $ => token(prec(-10, /#.*/)),
_simple_variable_name: $ => alias(/\w+/, $.variable_name),

121
src/grammar.json vendored
View File

@ -610,8 +610,35 @@
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_expression"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "=~"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
}
]
}
},
{
@ -630,8 +657,35 @@
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_expression"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "=~"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "regex"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
}
]
}
},
{
@ -1042,6 +1096,10 @@
"type": "SYMBOL",
"name": "simple_expansion"
},
{
"type": "SYMBOL",
"name": "string_expansion"
},
{
"type": "SYMBOL",
"name": "command_substitution"
@ -1150,8 +1208,25 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_string_content"
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_string_content"
}
]
},
{
"type": "SYMBOL",
@ -1189,8 +1264,15 @@
]
},
"_string_content": {
"type": "PATTERN",
"value": "([^\"`$]|\\\\.)+"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"content": {
"type": "PATTERN",
"value": "([^\"`$]|\\\\.)+"
}
}
},
"array": {
"type": "SEQ",
@ -1242,15 +1324,24 @@
},
"named": true,
"value": "special_variable_name"
},
{
"type": "SYMBOL",
"name": "string"
}
]
}
]
},
"string_expansion": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "SYMBOL",
"name": "string"
}
]
},
"expansion": {
"type": "SEQ",
"members": [
@ -1445,7 +1536,7 @@
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"value": -10,
"content": {
"type": "PATTERN",
"value": "#.*"
@ -1527,6 +1618,10 @@
}
}
},
"regex": {
"type": "PATTERN",
"value": "\\S+"
},
"_terminator": {
"type": "CHOICE",
"members": [

121501
src/parser.c vendored

File diff suppressed because it is too large Load Diff