Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String embraced #25

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,19 @@ const rules = {

null: $ => choice('null', 'Null', 'NULL'),

// prettier-ignore
string: $ =>
token(
choice(
/'(\\'|\\\\|\\?[^'\\])*'/,
/"(\\"|\\\\|\\?[^"\\])*"/,
choice(
seq("'", alias($.single_quote_body, $.string_body), "'"),
seq(
'"',
repeat(choice($.string_body, $.variable, $.embedded_brace_expression)),
'"',
),
),

// Breakout single quoted string body for symmetry with double quoted strings.
single_quote_body: $ => /(\\'|\\\\|\\?[^'\\])*/,

prefixed_string: $ => seq(field('prefix', $.identifier), $.string),

// Types
Expand Down Expand Up @@ -1153,6 +1157,7 @@ module.exports = grammar({
$._heredoc_body,
$._heredoc_end_newline,
$._heredoc_end,
$.string_body,
],

supertypes: $ => [
Expand Down
80 changes: 66 additions & 14 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1941,20 +1941,68 @@
]
},
"string": {
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "'(\\\\'|\\\\\\\\|\\\\?[^'\\\\])*'"
},
{
"type": "PATTERN",
"value": "\"(\\\\\"|\\\\\\\\|\\\\?[^\"\\\\])*\""
}
]
}
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "single_quote_body"
},
"named": true,
"value": "string_body"
},
{
"type": "STRING",
"value": "'"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string_body"
},
{
"type": "SYMBOL",
"name": "variable"
},
{
"type": "SYMBOL",
"name": "embedded_brace_expression"
}
]
}
},
{
"type": "STRING",
"value": "\""
}
]
}
]
},
"single_quote_body": {
"type": "PATTERN",
"value": "(\\\\'|\\\\\\\\|\\\\?[^'\\\\])*"
},
"prefixed_string": {
"type": "SEQ",
Expand Down Expand Up @@ -8250,6 +8298,10 @@
{
"type": "SYMBOL",
"name": "_heredoc_end"
},
{
"type": "SYMBOL",
"name": "string_body"
}
],
"inline": [
Expand Down
41 changes: 36 additions & 5 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,29 @@
"named": true,
"fields": {}
},
{
"type": "string",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "embedded_brace_expression",
"named": true
},
{
"type": "string_body",
"named": true
},
{
"type": "variable",
"named": true
}
]
}
},
{
"type": "subscript_expression",
"named": true,
Expand Down Expand Up @@ -3808,6 +3831,10 @@
"type": "!==",
"named": false
},
{
"type": "\"",
"named": false
},
{
"type": "%",
"named": false
Expand All @@ -3828,6 +3855,10 @@
"type": "&=",
"named": false
},
{
"type": "'",
"named": false
},
{
"type": "(",
"named": false
Expand Down Expand Up @@ -4198,11 +4229,11 @@
},
{
"type": "float",
"named": false
"named": true
},
{
"type": "float",
"named": true
"named": false
},
{
"type": "for",
Expand Down Expand Up @@ -4370,11 +4401,11 @@
},
{
"type": "string",
"named": true
"named": false
},
{
"type": "string",
"named": false
"type": "string_body",
"named": true
},
{
"type": "super",
Expand Down
Loading