grammar: remove shim again
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## 1.1.0 - not yet released
|
||||
## 1.1.0 - 2023-07-25
|
||||
|
||||
feature
|
||||
* add dialects so we can have different queries in `nvim-treesitter`
|
||||
* fix structure of comments in block bodies
|
||||
|
||||
fix:
|
||||
* fix ci acceptance workflow
|
||||
|
||||
@@ -2,21 +2,12 @@
|
||||
"name": "terraform",
|
||||
"rules": {
|
||||
"config_file": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "body"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
@@ -25,25 +16,6 @@
|
||||
"body": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_shim"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_shim"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
@@ -61,8 +33,6 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"attribute": {
|
||||
"type": "SEQ",
|
||||
@@ -1805,10 +1775,6 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "heredoc_identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_shim"
|
||||
}
|
||||
],
|
||||
"inline": [],
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "attribute",
|
||||
@@ -202,10 +202,6 @@
|
||||
{
|
||||
"type": "body",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,6 @@ enum TokenType {
|
||||
TEMPLATE_DIRECTIVE_START,
|
||||
TEMPLATE_DIRECTIVE_END,
|
||||
HEREDOC_IDENTIFIER,
|
||||
SHIM,
|
||||
};
|
||||
|
||||
enum ContextType {
|
||||
@@ -97,13 +96,6 @@ public:
|
||||
if (lexer->lookahead == '\0') {
|
||||
return false;
|
||||
}
|
||||
if (valid_symbols[SHIM]) {
|
||||
lexer->mark_end(lexer);
|
||||
while(skip_comment(lexer));
|
||||
if (lexer->lookahead != '}') {
|
||||
return accept_inplace(lexer, SHIM);
|
||||
}
|
||||
}
|
||||
// manage quoted context
|
||||
if (valid_symbols[QUOTED_TEMPLATE_START] && !in_quoted_context() &&
|
||||
lexer->lookahead == '"') {
|
||||
|
||||
@@ -24,20 +24,15 @@ module.exports = function make_grammar(dialect) {
|
||||
$.template_directive_start,
|
||||
$.template_directive_end,
|
||||
$.heredoc_identifier,
|
||||
$._shim,
|
||||
],
|
||||
|
||||
extras: ($) => [$.comment, $._whitespace],
|
||||
|
||||
rules: {
|
||||
// also allow objects to handle .tfvars in json format
|
||||
config_file: ($) => optional($.body),
|
||||
config_file: ($) => optional(choice($.body, $.object)),
|
||||
|
||||
body: ($) =>
|
||||
choice(
|
||||
$._shim,
|
||||
seq(optional($._shim), repeat1(choice($.attribute, $.block)))
|
||||
),
|
||||
body: ($) => choice(repeat1(choice($.attribute, $.block))),
|
||||
|
||||
attribute: ($) => seq($.identifier, "=", $.expression),
|
||||
|
||||
@@ -47,7 +42,7 @@ module.exports = function make_grammar(dialect) {
|
||||
repeat(choice($.string_lit, $.identifier)),
|
||||
$.block_start,
|
||||
optional($.body),
|
||||
$.block_end
|
||||
$.block_end,
|
||||
),
|
||||
|
||||
block_start: ($) => "{",
|
||||
@@ -57,8 +52,8 @@ module.exports = function make_grammar(dialect) {
|
||||
token(
|
||||
seq(
|
||||
choice(/\p{ID_Start}/, "_"),
|
||||
repeat(choice(/\p{ID_Continue}/, "-"))
|
||||
)
|
||||
repeat(choice(/\p{ID_Continue}/, "-")),
|
||||
),
|
||||
),
|
||||
|
||||
expression: ($) => prec.right(choice($._expr_term, $.conditional)),
|
||||
@@ -78,7 +73,7 @@ module.exports = function make_grammar(dialect) {
|
||||
seq($._expr_term, $.index),
|
||||
seq($._expr_term, $.get_attr),
|
||||
seq($._expr_term, $.splat),
|
||||
seq("(", $.expression, ")")
|
||||
seq("(", $.expression, ")"),
|
||||
),
|
||||
|
||||
literal_value: ($) =>
|
||||
@@ -97,8 +92,8 @@ module.exports = function make_grammar(dialect) {
|
||||
seq(
|
||||
$.quoted_template_start,
|
||||
optional($.template_literal),
|
||||
$.quoted_template_end
|
||||
)
|
||||
$.quoted_template_end,
|
||||
),
|
||||
),
|
||||
|
||||
collection_value: ($) => choice($.tuple, $.object),
|
||||
@@ -114,7 +109,7 @@ module.exports = function make_grammar(dialect) {
|
||||
seq(
|
||||
$.expression,
|
||||
repeat(seq($._comma, $.expression)),
|
||||
optional($._comma)
|
||||
optional($._comma),
|
||||
),
|
||||
|
||||
object: ($) =>
|
||||
@@ -127,14 +122,14 @@ module.exports = function make_grammar(dialect) {
|
||||
seq(
|
||||
$.object_elem,
|
||||
repeat(seq(optional($._comma), $.object_elem)),
|
||||
optional($._comma)
|
||||
optional($._comma),
|
||||
),
|
||||
|
||||
object_elem: ($) =>
|
||||
seq(
|
||||
field("key", $.expression),
|
||||
choice("=", ":"),
|
||||
field("val", $.expression)
|
||||
field("val", $.expression),
|
||||
),
|
||||
|
||||
index: ($) => choice($.new_index, $.legacy_index),
|
||||
@@ -160,7 +155,7 @@ module.exports = function make_grammar(dialect) {
|
||||
$.for_intro,
|
||||
$.expression,
|
||||
optional($.for_cond),
|
||||
$.tuple_end
|
||||
$.tuple_end,
|
||||
),
|
||||
|
||||
for_object_expr: ($) =>
|
||||
@@ -172,7 +167,7 @@ module.exports = function make_grammar(dialect) {
|
||||
$.expression,
|
||||
optional($.ellipsis),
|
||||
optional($.for_cond),
|
||||
$.object_end
|
||||
$.object_end,
|
||||
),
|
||||
|
||||
for_intro: ($) =>
|
||||
@@ -182,7 +177,7 @@ module.exports = function make_grammar(dialect) {
|
||||
optional(seq(",", $.identifier)),
|
||||
"in",
|
||||
$.expression,
|
||||
":"
|
||||
":",
|
||||
),
|
||||
|
||||
for_cond: ($) => seq("if", $.expression),
|
||||
@@ -194,7 +189,7 @@ module.exports = function make_grammar(dialect) {
|
||||
$.identifier,
|
||||
$._function_call_start,
|
||||
optional($.function_arguments),
|
||||
$._function_call_end
|
||||
$._function_call_end,
|
||||
),
|
||||
|
||||
_function_call_start: ($) => "(",
|
||||
@@ -205,8 +200,8 @@ module.exports = function make_grammar(dialect) {
|
||||
seq(
|
||||
$.expression,
|
||||
repeat(seq($._comma, $.expression)),
|
||||
optional(choice($._comma, $.ellipsis))
|
||||
)
|
||||
optional(choice($._comma, $.ellipsis)),
|
||||
),
|
||||
),
|
||||
|
||||
ellipsis: ($) => token("..."),
|
||||
@@ -231,8 +226,8 @@ module.exports = function make_grammar(dialect) {
|
||||
|
||||
return choice(
|
||||
...table.map(([precedence, operator]) =>
|
||||
prec.left(precedence, seq($._expr_term, operator, $._expr_term))
|
||||
)
|
||||
prec.left(precedence, seq($._expr_term, operator, $._expr_term)),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -244,8 +239,8 @@ module.exports = function make_grammar(dialect) {
|
||||
seq(
|
||||
$.quoted_template_start,
|
||||
optional($._template),
|
||||
$.quoted_template_end
|
||||
)
|
||||
$.quoted_template_end,
|
||||
),
|
||||
),
|
||||
|
||||
heredoc_template: ($) =>
|
||||
@@ -253,7 +248,7 @@ module.exports = function make_grammar(dialect) {
|
||||
$.heredoc_start,
|
||||
$.heredoc_identifier,
|
||||
optional($._template),
|
||||
$.heredoc_identifier
|
||||
$.heredoc_identifier,
|
||||
),
|
||||
|
||||
heredoc_start: ($) => choice("<<", "<<-"),
|
||||
@@ -265,8 +260,8 @@ module.exports = function make_grammar(dialect) {
|
||||
choice(
|
||||
$.template_interpolation,
|
||||
$.template_directive,
|
||||
$.template_literal
|
||||
)
|
||||
$.template_literal,
|
||||
),
|
||||
),
|
||||
|
||||
template_literal: ($) => prec.right(repeat1($._template_literal_chunk)),
|
||||
@@ -277,7 +272,7 @@ module.exports = function make_grammar(dialect) {
|
||||
optional($.strip_marker),
|
||||
optional($.expression),
|
||||
optional($.strip_marker),
|
||||
$.template_interpolation_end
|
||||
$.template_interpolation_end,
|
||||
),
|
||||
|
||||
template_directive: ($) => choice($.template_for, $.template_if),
|
||||
@@ -295,7 +290,7 @@ module.exports = function make_grammar(dialect) {
|
||||
"in",
|
||||
$.expression,
|
||||
optional($.strip_marker),
|
||||
$.template_directive_end
|
||||
$.template_directive_end,
|
||||
),
|
||||
|
||||
template_for_end: ($) =>
|
||||
@@ -304,7 +299,7 @@ module.exports = function make_grammar(dialect) {
|
||||
optional($.strip_marker),
|
||||
"endfor",
|
||||
optional($.strip_marker),
|
||||
$.template_directive_end
|
||||
$.template_directive_end,
|
||||
),
|
||||
|
||||
template_if: ($) =>
|
||||
@@ -312,7 +307,7 @@ module.exports = function make_grammar(dialect) {
|
||||
$.template_if_intro,
|
||||
optional($._template),
|
||||
optional(seq($.template_else_intro, optional($._template))),
|
||||
$.template_if_end
|
||||
$.template_if_end,
|
||||
),
|
||||
|
||||
template_if_intro: ($) =>
|
||||
@@ -322,7 +317,7 @@ module.exports = function make_grammar(dialect) {
|
||||
"if",
|
||||
$.expression,
|
||||
optional($.strip_marker),
|
||||
$.template_directive_end
|
||||
$.template_directive_end,
|
||||
),
|
||||
|
||||
template_else_intro: ($) =>
|
||||
@@ -331,7 +326,7 @@ module.exports = function make_grammar(dialect) {
|
||||
optional($.strip_marker),
|
||||
"else",
|
||||
optional($.strip_marker),
|
||||
$.template_directive_end
|
||||
$.template_directive_end,
|
||||
),
|
||||
|
||||
template_if_end: ($) =>
|
||||
@@ -340,7 +335,7 @@ module.exports = function make_grammar(dialect) {
|
||||
optional($.strip_marker),
|
||||
"endif",
|
||||
optional($.strip_marker),
|
||||
$.template_directive_end
|
||||
$.template_directive_end,
|
||||
),
|
||||
|
||||
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
||||
@@ -349,8 +344,8 @@ module.exports = function make_grammar(dialect) {
|
||||
choice(
|
||||
seq("#", /.*/),
|
||||
seq("//", /.*/),
|
||||
seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/")
|
||||
)
|
||||
seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/"),
|
||||
),
|
||||
),
|
||||
|
||||
_whitespace: ($) => token(/\s/),
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
"name": "hcl",
|
||||
"rules": {
|
||||
"config_file": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "body"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
@@ -16,25 +25,6 @@
|
||||
"body": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_shim"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_shim"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
@@ -52,8 +42,6 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"attribute": {
|
||||
"type": "SEQ",
|
||||
@@ -1796,10 +1784,6 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "heredoc_identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_shim"
|
||||
}
|
||||
],
|
||||
"inline": [],
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "attribute",
|
||||
@@ -202,6 +202,10 @@
|
||||
{
|
||||
"type": "body",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
29836
src/parser.c
29836
src/parser.c
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,6 @@ enum TokenType {
|
||||
TEMPLATE_DIRECTIVE_START,
|
||||
TEMPLATE_DIRECTIVE_END,
|
||||
HEREDOC_IDENTIFIER,
|
||||
SHIM,
|
||||
};
|
||||
|
||||
enum ContextType {
|
||||
@@ -97,13 +96,6 @@ public:
|
||||
if (lexer->lookahead == '\0') {
|
||||
return false;
|
||||
}
|
||||
if (valid_symbols[SHIM]) {
|
||||
lexer->mark_end(lexer);
|
||||
while(skip_comment(lexer));
|
||||
if (lexer->lookahead != '}') {
|
||||
return accept_inplace(lexer, SHIM);
|
||||
}
|
||||
}
|
||||
// manage quoted context
|
||||
if (valid_symbols[QUOTED_TEMPLATE_START] && !in_quoted_context() &&
|
||||
lexer->lookahead == '"') {
|
||||
|
||||
@@ -33,7 +33,6 @@ block {
|
||||
(block
|
||||
(identifier)
|
||||
(block_start)
|
||||
(body)
|
||||
(comment)
|
||||
(block_end))))
|
||||
|
||||
@@ -55,8 +54,8 @@ block {
|
||||
(block
|
||||
(identifier)
|
||||
(block_start)
|
||||
(body
|
||||
(comment)
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
@@ -80,8 +79,8 @@ block {
|
||||
(block
|
||||
(identifier)
|
||||
(block_start)
|
||||
(body
|
||||
(comment)
|
||||
(body
|
||||
(attribute
|
||||
(identifier)
|
||||
(expression
|
||||
@@ -153,5 +152,4 @@ comment at end of file
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(config_file
|
||||
(body)
|
||||
(comment))
|
||||
|
||||
27
test/corpus/json.txt
Normal file
27
test/corpus/json.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
================================================================================
|
||||
top level object
|
||||
================================================================================
|
||||
|
||||
{
|
||||
"foo": "bar"
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(config_file
|
||||
(object
|
||||
(object_start)
|
||||
(object_elem
|
||||
(expression
|
||||
(literal_value
|
||||
(string_lit
|
||||
(quoted_template_start)
|
||||
(template_literal)
|
||||
(quoted_template_end))))
|
||||
(expression
|
||||
(literal_value
|
||||
(string_lit
|
||||
(quoted_template_start)
|
||||
(template_literal)
|
||||
(quoted_template_end)))))
|
||||
(object_end)))
|
||||
Reference in New Issue
Block a user