Add finally, instance of, typeof, in to js grammar
This commit is contained in:
parent
c91c5cb730
commit
4ad6278334
8 changed files with 47167 additions and 21103 deletions
|
|
@ -58,7 +58,7 @@ namespace tree_sitter_examples {
|
|||
|
||||
// Type expressions
|
||||
{ "pointer_type", seq({
|
||||
str("*"),
|
||||
keyword("*"),
|
||||
sym("type_expression") }) },
|
||||
{ "map_type", seq({
|
||||
keyword("map"),
|
||||
|
|
|
|||
|
|
@ -30,20 +30,20 @@ namespace tree_sitter_examples {
|
|||
rule_ptr infix_op(std::string op, std::string rule_name, int precedence) {
|
||||
return prec(precedence, seq({
|
||||
sym(rule_name),
|
||||
str(op),
|
||||
keyword(op),
|
||||
sym(rule_name) }));
|
||||
}
|
||||
|
||||
rule_ptr prefix_op(std::string op, std::string rule_name, int precedence) {
|
||||
return prec(precedence, seq({
|
||||
str(op),
|
||||
keyword(op),
|
||||
sym(rule_name) }));
|
||||
}
|
||||
|
||||
rule_ptr postfix_op(std::string op, std::string rule_name, int precedence) {
|
||||
return prec(precedence, seq({
|
||||
sym(rule_name),
|
||||
str(op) }));
|
||||
keyword(op) }));
|
||||
}
|
||||
|
||||
rule_ptr delimited(std::string delimiter) {
|
||||
|
|
|
|||
|
|
@ -45,9 +45,15 @@ namespace tree_sitter_examples {
|
|||
{ "try_statement", seq({
|
||||
keyword("try"),
|
||||
sym("statement"),
|
||||
optional(sym("catch_clause")),
|
||||
optional(sym("finally_clause")) }) },
|
||||
{ "catch_clause", seq({
|
||||
keyword("catch"),
|
||||
in_parens(err(sym("identifier"))),
|
||||
sym("statement") }) },
|
||||
{ "finally_clause", seq({
|
||||
keyword("finally"),
|
||||
sym("statement") }) },
|
||||
{ "switch_statement", seq({
|
||||
keyword("switch"),
|
||||
in_parens(err(sym("expression"))),
|
||||
|
|
@ -100,7 +106,13 @@ namespace tree_sitter_examples {
|
|||
sym("false"),
|
||||
sym("null"),
|
||||
sym("identifier"),
|
||||
sym("in_expression"),
|
||||
sym("instanceof_expression"),
|
||||
sym("typeof_expression"),
|
||||
in_parens(sym("expression")) }) },
|
||||
{ "in_expression", infix_op("in", "expression", 3) },
|
||||
{ "instanceof_expression", infix_op("instanceof", "expression", 3) },
|
||||
{ "typeof_expression", prefix_op("typeof", "expression", 3) },
|
||||
{ "math_op", choice({
|
||||
prefix_op("++", "expression", 3),
|
||||
prefix_op("--", "expression", 3),
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -322,7 +322,6 @@ LEX_FN() {
|
|||
ADVANCE(27);
|
||||
LEX_ERROR();
|
||||
case ts_lex_state_error:
|
||||
START_TOKEN();
|
||||
if (lookahead == '\0')
|
||||
ADVANCE(25);
|
||||
if (('\t' <= lookahead && lookahead <= '\n') ||
|
||||
|
|
|
|||
|
|
@ -73,11 +73,22 @@ try {
|
|||
} catch (e) {
|
||||
logError(e);
|
||||
}
|
||||
|
||||
try {
|
||||
doSomething();
|
||||
} finally {
|
||||
logError();
|
||||
}
|
||||
---
|
||||
(program (try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(identifier)
|
||||
(statement_block (expression_statement (function_call (identifier) (identifier))))))
|
||||
(program
|
||||
(try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(catch_clause (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier) (identifier))))))
|
||||
(try_statement
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(finally_clause
|
||||
(statement_block (expression_statement (function_call (identifier)))))))
|
||||
|
||||
===========================================
|
||||
parses indented code after blocks
|
||||
|
|
|
|||
|
|
@ -29,4 +29,21 @@ parses boolean operators
|
|||
(bool_op
|
||||
(bool_op (identifier))
|
||||
(bool_op
|
||||
(expression (bool_op (identifier) (identifier)))))))
|
||||
(expression (bool_op (identifier) (identifier)))))))
|
||||
|
||||
===========================================
|
||||
parses the type operators
|
||||
===========================================
|
||||
print((x instanceof Array) || (typeof x == "string"))
|
||||
---
|
||||
(program (expression_statement (function_call (identifier)
|
||||
(bool_op
|
||||
(expression (instanceof_expression (identifier) (identifier)))
|
||||
(expression (typeof_expression (bool_op (identifier) (string))))))))
|
||||
|
||||
============================================
|
||||
parses the 'in' operator
|
||||
===========================================
|
||||
print(x in y)
|
||||
---
|
||||
(program (expression_statement (function_call (identifier) (in_expression (identifier) (identifier)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue