Add dynamic property access to javascript grammar
This commit is contained in:
parent
5320cad065
commit
be1c8e0f17
4 changed files with 6162 additions and 4894 deletions
|
|
@ -12,6 +12,10 @@ namespace tree_sitter_examples {
|
|||
return seq({ str("{"), rule, str("}") });
|
||||
}
|
||||
|
||||
static rule_ptr in_brackets(rule_ptr rule) {
|
||||
return seq({ str("["), rule, str("]") });
|
||||
}
|
||||
|
||||
static rule_ptr comma_sep(rule_ptr element) {
|
||||
return choice({
|
||||
seq({ element, repeat(seq({ str(","), element })) }),
|
||||
|
|
@ -90,7 +94,10 @@ namespace tree_sitter_examples {
|
|||
|
||||
// Expressions
|
||||
{ "assignment", seq({
|
||||
sym("identifier"),
|
||||
choice({
|
||||
sym("identifier"),
|
||||
sym("property_access"),
|
||||
}),
|
||||
str("="),
|
||||
sym("expression") })},
|
||||
{ "function_expression", seq({
|
||||
|
|
@ -105,8 +112,11 @@ namespace tree_sitter_examples {
|
|||
str(")") }) },
|
||||
{ "property_access", seq({
|
||||
sym("expression"),
|
||||
str("."),
|
||||
sym("identifier") }) },
|
||||
choice({
|
||||
seq({
|
||||
str("."),
|
||||
sym("identifier") }),
|
||||
in_brackets(sym("expression")) }) }) },
|
||||
{ "formal_parameters", seq({
|
||||
str("("),
|
||||
comma_sep(sym("identifier")),
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
82
spec/runtime/languages/javascript/control_flow.txt
Normal file
82
spec/runtime/languages/javascript/control_flow.txt
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
==========================================
|
||||
parses if statements
|
||||
==========================================
|
||||
if (isReady()) {
|
||||
console.log(theData)
|
||||
}
|
||||
---
|
||||
(program
|
||||
(if_statement (function_call (identifier))
|
||||
(statement_block (expression_statement (function_call (property_access (identifier) (identifier)) (identifier))))))
|
||||
|
||||
==========================================
|
||||
parses if-else statements
|
||||
==========================================
|
||||
if (theCondition) {
|
||||
firstFunction();
|
||||
} else {
|
||||
secondFunction();
|
||||
}
|
||||
---
|
||||
(program (if_statement
|
||||
(identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==================================================
|
||||
parses if-else statements with multiple conditions
|
||||
==================================================
|
||||
if (firstValue) {
|
||||
firstFunction();
|
||||
} else if (secondValue)
|
||||
secondFunction();
|
||||
else {
|
||||
thirdFunction();
|
||||
}
|
||||
---
|
||||
(program
|
||||
(if_statement (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(if_statement (identifier)
|
||||
(expression_statement (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier)))))))
|
||||
|
||||
==========================================
|
||||
parses for loops
|
||||
==========================================
|
||||
for (var i = 1; someCondition(i); i = next()) {
|
||||
doSomething();
|
||||
}
|
||||
---
|
||||
(program (for_statement
|
||||
(var_declaration (assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(assignment (identifier) (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
===========================================
|
||||
parses switch statements
|
||||
===========================================
|
||||
switch(x) {
|
||||
case "hello":
|
||||
print("one");
|
||||
break;
|
||||
case z():
|
||||
print("two");
|
||||
break;
|
||||
default:
|
||||
print("three");
|
||||
}
|
||||
---
|
||||
(program
|
||||
(switch_statement (identifier)
|
||||
(switch_case
|
||||
(string)
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(switch_case
|
||||
(function_call (identifier))
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(switch_case
|
||||
(expression_statement (function_call (identifier) (string))))))
|
||||
|
|
@ -10,62 +10,6 @@ secondFunction(x);
|
|||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
|
||||
==========================================
|
||||
parses if statements
|
||||
==========================================
|
||||
if (isReady()) {
|
||||
console.log(theData)
|
||||
}
|
||||
---
|
||||
(program
|
||||
(if_statement (function_call (identifier))
|
||||
(statement_block (expression_statement (function_call (property_access (identifier) (identifier)) (identifier))))))
|
||||
|
||||
==========================================
|
||||
parses if-else statements
|
||||
==========================================
|
||||
if (theCondition) {
|
||||
firstFunction();
|
||||
} else {
|
||||
secondFunction();
|
||||
}
|
||||
---
|
||||
(program (if_statement
|
||||
(identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==================================================
|
||||
parses if-else statements with multiple conditions
|
||||
==================================================
|
||||
if (firstValue) {
|
||||
firstFunction();
|
||||
} else if (secondValue)
|
||||
secondFunction();
|
||||
else {
|
||||
thirdFunction();
|
||||
}
|
||||
---
|
||||
(program
|
||||
(if_statement (identifier)
|
||||
(statement_block (expression_statement (function_call (identifier))))
|
||||
(if_statement (identifier)
|
||||
(expression_statement (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier)))))))
|
||||
|
||||
==========================================
|
||||
parses for loops
|
||||
==========================================
|
||||
for (var i = 1; someCondition(i); i = next()) {
|
||||
doSomething();
|
||||
}
|
||||
---
|
||||
(program (for_statement
|
||||
(var_declaration (assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(assignment (identifier) (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
parses function expressions and calls
|
||||
==========================================
|
||||
|
|
@ -87,35 +31,32 @@ x.theMethod(5, 6);
|
|||
(property_access (identifier) (identifier))
|
||||
(number) (number))))
|
||||
|
||||
===========================================
|
||||
parses switch statements
|
||||
===========================================
|
||||
switch(x) {
|
||||
case "hello":
|
||||
print("one");
|
||||
break;
|
||||
case z():
|
||||
print("two");
|
||||
break;
|
||||
default:
|
||||
print("three");
|
||||
}
|
||||
==========================================
|
||||
parses property access with dot notation
|
||||
==========================================
|
||||
object.property = "the-value";
|
||||
print(object.property);
|
||||
---
|
||||
(program
|
||||
(switch_statement (identifier)
|
||||
(switch_case
|
||||
(string)
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(switch_case
|
||||
(function_call (identifier))
|
||||
(expression_statement (function_call (identifier) (string)))
|
||||
(break_statement))
|
||||
(switch_case
|
||||
(expression_statement (function_call (identifier) (string))))))
|
||||
|
||||
|
||||
|
||||
|
||||
(expression_statement (assignment
|
||||
(property_access (identifier) (identifier))
|
||||
(string)))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(property_access (identifier) (identifier)))))
|
||||
|
||||
===========================================
|
||||
parses dynamic property access
|
||||
==========================================
|
||||
object[propertName()] = propertyValue();
|
||||
print(object[propertyName()]);
|
||||
---
|
||||
(program
|
||||
(expression_statement (assignment
|
||||
(property_access (identifier) (function_call (identifier)))
|
||||
(function_call (identifier))))
|
||||
(expression_statement (function_call
|
||||
(identifier)
|
||||
(property_access (identifier) (function_call (identifier))))))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue