Skip to content

Commit

Permalink
Rename ansii_c_string and string_expansion (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
verhovsky authored Oct 22, 2022
1 parent f55b039 commit 385a8e4
Show file tree
Hide file tree
Showing 6 changed files with 55,114 additions and 51,789 deletions.
4 changes: 2 additions & 2 deletions corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ echo "s$"
Strings with ANSI-C quoting
========================================

echo $'Here\'s johnny!\r\n'
echo $'Here\'s Johnny!\r\n'

---

(program (command (command_name (word)) (ansii_c_string)))
(program (command (command_name (word)) (ansi_c_string)))

=========================================
Arrays and array expansions
Expand Down
10 changes: 6 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@ module.exports = grammar({
$.word,
$.string,
$.raw_string,
$.ansii_c_string,
$.translated_string,
$.ansi_c_string,
$.expansion,
$.simple_expansion,
$.string_expansion,
$.command_substitution,
$.process_substitution
),
Expand Down Expand Up @@ -468,6 +468,8 @@ module.exports = grammar({

_string_content: $ => token(prec(-1, /([^"`$\\]|\\(.|\r?\n))+/)),

translated_string: $ => seq('$', $.string),

array: $ => seq(
'(',
repeat($._literal),
Expand All @@ -476,7 +478,7 @@ module.exports = grammar({

raw_string: $ => /'[^']*'/,

ansii_c_string: $ => /\$'([^']|\\')*'/,
ansi_c_string: $ => /\$'([^']|\\')*'/,

simple_expansion: $ => seq(
'$',
Expand All @@ -488,7 +490,7 @@ module.exports = grammar({
)
),

string_expansion: $ => seq('$', choice($.string, $.raw_string)),
string_expansion: $ => seq('$', $.string),

expansion: $ => seq(
'${',
Expand Down
36 changes: 20 additions & 16 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,19 +1845,19 @@
},
{
"type": "SYMBOL",
"name": "ansii_c_string"
"name": "translated_string"
},
{
"type": "SYMBOL",
"name": "expansion"
"name": "ansi_c_string"
},
{
"type": "SYMBOL",
"name": "simple_expansion"
"name": "expansion"
},
{
"type": "SYMBOL",
"name": "string_expansion"
"name": "simple_expansion"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -2063,6 +2063,19 @@
}
}
},
"translated_string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "SYMBOL",
"name": "string"
}
]
},
"array": {
"type": "SEQ",
"members": [
Expand All @@ -2087,7 +2100,7 @@
"type": "PATTERN",
"value": "'[^']*'"
},
"ansii_c_string": {
"ansi_c_string": {
"type": "PATTERN",
"value": "\\$'([^']|\\\\')*'"
},
Expand Down Expand Up @@ -2139,17 +2152,8 @@
"value": "$"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "raw_string"
}
]
"type": "SYMBOL",
"name": "string"
}
]
},
Expand Down
40 changes: 18 additions & 22 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"named": true,
"subtypes": [
{
"type": "ansii_c_string",
"type": "ansi_c_string",
"named": true
},
{
Expand Down Expand Up @@ -70,7 +70,7 @@
"named": true
},
{
"type": "string_expansion",
"type": "translated_string",
"named": true
},
{
Expand Down Expand Up @@ -1069,25 +1069,6 @@
]
}
},
{
"type": "string_expansion",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "raw_string",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "subscript",
"named": true,
Expand Down Expand Up @@ -1188,6 +1169,21 @@
]
}
},
{
"type": "translated_string",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "string",
"named": true
}
]
}
},
{
"type": "unary_expression",
"named": true,
Expand Down Expand Up @@ -1528,7 +1524,7 @@
"named": false
},
{
"type": "ansii_c_string",
"type": "ansi_c_string",
"named": true
},
{
Expand Down
Loading

0 comments on commit 385a8e4

Please sign in to comment.