WIP add heredoc templates; only EOF marker at the moment

This commit is contained in:
mhoffm
2021-06-21 22:04:28 +02:00
parent d57a44c2c3
commit 5a58000ba1
7 changed files with 12426 additions and 10739 deletions

View File

@@ -1163,6 +1163,10 @@
{
"type": "SYMBOL",
"name": "quoted_template"
},
{
"type": "SYMBOL",
"name": "heredoc_template"
}
]
},
@@ -1203,6 +1207,56 @@
]
}
},
"heredoc_template": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "heredoc_start"
},
{
"type": "SYMBOL",
"name": "heredoc_identifier"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "template_literal"
},
{
"type": "SYMBOL",
"name": "template_interpolation"
},
{
"type": "SYMBOL",
"name": "template_directive"
}
]
}
},
{
"type": "SYMBOL",
"name": "heredoc_identifier"
}
]
},
"heredoc_start": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "<<"
},
{
"type": "STRING",
"value": "<<-"
}
]
},
"strip_marker": {
"type": "STRING",
"value": "~"
@@ -1354,6 +1408,10 @@
{
"type": "SYMBOL",
"name": "_template_interpolation_end"
},
{
"type": "SYMBOL",
"name": "heredoc_identifier"
}
],
"inline": [],

View File

@@ -426,6 +426,42 @@
]
}
},
{
"type": "heredoc_start",
"named": true,
"fields": {}
},
{
"type": "heredoc_template",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "heredoc_identifier",
"named": true
},
{
"type": "heredoc_start",
"named": true
},
{
"type": "template_directive",
"named": true
},
{
"type": "template_interpolation",
"named": true
},
{
"type": "template_literal",
"named": true
}
]
}
},
{
"type": "index",
"named": true,
@@ -616,6 +652,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "heredoc_template",
"named": true
},
{
"type": "quoted_template",
"named": true
@@ -792,6 +832,14 @@
"type": "<",
"named": false
},
{
"type": "<<",
"named": false
},
{
"type": "<<-",
"named": false
},
{
"type": "<=",
"named": false
@@ -848,6 +896,10 @@
"type": "for",
"named": false
},
{
"type": "heredoc_identifier",
"named": true
},
{
"type": "identifier",
"named": true

23006
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,7 @@ enum TokenType {
TEMPLATE_LITERAL_CHUNK,
TEMPLATE_INTERPOLATION_START,
TEMPLATE_INTERPOLATION_END,
HEREDOC_IDENTIFIER,
};
static void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
@@ -202,8 +203,24 @@ bool scanner_scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
}
}
// handle heredoc identifier
if (valid_symbols[HEREDOC_IDENTIFIER]) {
if (lexer->lookahead != 'E') {
if (valid_symbols[TEMPLATE_LITERAL_CHUNK]) return accept_and_advance(lexer, TEMPLATE_LITERAL_CHUNK);
}
advance(lexer);
if (lexer->lookahead != 'O') {
if (valid_symbols[TEMPLATE_LITERAL_CHUNK]) return accept_and_advance(lexer, TEMPLATE_LITERAL_CHUNK);
}
advance(lexer);
if (lexer->lookahead != 'F') {
if (valid_symbols[TEMPLATE_LITERAL_CHUNK]) return accept_and_advance(lexer, TEMPLATE_LITERAL_CHUNK);
}
return accept_and_advance(lexer, HEREDOC_IDENTIFIER);
}
// handle all other quoted template or string literal characters
if (valid_symbols[TEMPLATE_LITERAL_CHUNK] && scanner->in_quoted_context) {
if (valid_symbols[TEMPLATE_LITERAL_CHUNK]) {
return accept_and_advance(lexer, TEMPLATE_LITERAL_CHUNK);
}