Add concise method syntax to javascript fixture grammar
This exposes an ambiguity handling bug that I discovered while adding ES6 support to tree-sitter-javascript
This commit is contained in:
parent
8747e2d3b9
commit
9bff4d0b06
3 changed files with 23223 additions and 22976 deletions
43
spec/fixtures/corpus/javascript/control_flow.txt
vendored
43
spec/fixtures/corpus/javascript/control_flow.txt
vendored
|
|
@ -30,6 +30,49 @@ if (isReady()) {
|
|||
(statement_block (expression_statement
|
||||
(function_call (member_access (identifier) (identifier)) (arguments (identifier)))))))
|
||||
|
||||
==========================================
|
||||
if statements whose bodies are objects
|
||||
==========================================
|
||||
|
||||
if (a) {
|
||||
b()
|
||||
{
|
||||
c();
|
||||
},
|
||||
|
||||
d: 'e'
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(program (if_statement (identifier)
|
||||
(expression_statement (object
|
||||
(method_definition (identifier) (statement_block (expression_statement (function_call (identifier) (arguments)))))
|
||||
(pair (identifier) (string))))))
|
||||
|
||||
============================================
|
||||
if statements whose bodies look like objects
|
||||
============================================
|
||||
|
||||
if (f) {
|
||||
g()
|
||||
{
|
||||
h();
|
||||
i();
|
||||
}
|
||||
j()
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(program (if_statement (identifier)
|
||||
(statement_block
|
||||
(expression_statement (function_call (identifier) (arguments)))
|
||||
(statement_block
|
||||
(expression_statement (function_call (identifier) (arguments)))
|
||||
(expression_statement (function_call (identifier) (arguments))))
|
||||
(expression_statement (function_call (identifier) (arguments))))))
|
||||
|
||||
==========================================
|
||||
if-else statements
|
||||
==========================================
|
||||
|
|
|
|||
12
spec/fixtures/grammars/javascript.cc
vendored
12
spec/fixtures/grammars/javascript.cc
vendored
|
|
@ -202,7 +202,9 @@ extern const Grammar javascript = Grammar({
|
|||
sym("true"),
|
||||
sym("_paren_expression") }) },
|
||||
|
||||
{ "object", in_braces(comma_sep(err(sym("pair")))) },
|
||||
{ "object", in_braces(comma_sep(err(choice({
|
||||
sym("pair"),
|
||||
sym("method_definition") })))) },
|
||||
|
||||
{ "array", in_brackets(comma_sep(err(sym("_expression")))) },
|
||||
|
||||
|
|
@ -340,12 +342,20 @@ extern const Grammar javascript = Grammar({
|
|||
str(":"),
|
||||
sym("_expression") }) },
|
||||
|
||||
{ "method_definition", seq({
|
||||
sym("identifier"),
|
||||
str("("),
|
||||
comma_sep(sym("identifier")),
|
||||
str(")"),
|
||||
sym("statement_block") }) },
|
||||
|
||||
}).ubiquitous_tokens({
|
||||
sym("comment"),
|
||||
sym("_line_break"),
|
||||
pattern("[ \t\r]"),
|
||||
}).expected_conflicts({
|
||||
{ "for_in_statement", "_expression" },
|
||||
{ "method_definition", "_expression" },
|
||||
});
|
||||
|
||||
} // namespace tree_sitter_examples
|
||||
|
|
|
|||
46144
spec/fixtures/parsers/javascript.c
vendored
46144
spec/fixtures/parsers/javascript.c
vendored
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue