Add for-in loops and math assignment operators to js grammar
This commit is contained in:
parent
f4287c07d0
commit
1c7d2d2d03
6 changed files with 59121 additions and 49463 deletions
|
|
@ -1,3 +1,18 @@
|
|||
==========================================
|
||||
parses multiple statements
|
||||
==========================================
|
||||
var x = {}, z, i = 0;
|
||||
firstFunction(x)
|
||||
secondFunction(x);
|
||||
---
|
||||
(program
|
||||
(var_declaration
|
||||
(identifier) (object)
|
||||
(identifier)
|
||||
(identifier) (number))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
|
||||
==========================================
|
||||
js parses if statements
|
||||
==========================================
|
||||
|
|
@ -49,11 +64,27 @@ for (var i = 1; someCondition(i); i = next()) {
|
|||
}
|
||||
---
|
||||
(program (for_statement
|
||||
(var_declaration (assignment (identifier) (number)))
|
||||
(var_declaration (identifier) (number))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(assignment (identifier) (function_call (identifier)))
|
||||
(statement_block (expression_statement (function_call (identifier))))))
|
||||
|
||||
==========================================
|
||||
parses for-in loops
|
||||
==========================================
|
||||
for (var key in someObject)
|
||||
doSomething();
|
||||
for (key in someObject)
|
||||
doSomethingElse();
|
||||
---
|
||||
(program
|
||||
(for_in_statement
|
||||
(identifier) (identifier)
|
||||
(expression_statement (function_call (identifier))))
|
||||
(for_in_statement
|
||||
(identifier) (identifier)
|
||||
(expression_statement (function_call (identifier)))))
|
||||
|
||||
==========================================
|
||||
parses while loops
|
||||
==========================================
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ moreStuff();
|
|||
(program
|
||||
(expression_statement (function_call (identifier)))
|
||||
(for_statement
|
||||
(var_declaration (assignment (identifier) (number)))
|
||||
(var_declaration (identifier) (number))
|
||||
(expression_statement (ERROR '*'))
|
||||
(math_op (identifier))
|
||||
(statement_block (expression_statement (ERROR '*'))))
|
||||
|
|
|
|||
|
|
@ -22,21 +22,6 @@ theFunction('', "", 'single-quoted-string', "double-quoted-string");
|
|||
(program (expression_statement (function_call (identifier)
|
||||
(string) (string) (string) (string))))
|
||||
|
||||
==========================================
|
||||
parses multiple statements
|
||||
==========================================
|
||||
var x = {}, z, i = 0;
|
||||
firstFunction(x)
|
||||
secondFunction(x);
|
||||
---
|
||||
(program
|
||||
(var_declaration
|
||||
(assignment (identifier) (object))
|
||||
(identifier)
|
||||
(assignment (identifier) (number)))
|
||||
(expression_statement (function_call (identifier) (identifier)))
|
||||
(expression_statement (function_call (identifier) (identifier))))
|
||||
|
||||
==========================================
|
||||
parses function expressions
|
||||
==========================================
|
||||
|
|
@ -47,11 +32,11 @@ var x = {
|
|||
};
|
||||
---
|
||||
(program
|
||||
(var_declaration (assignment
|
||||
(var_declaration
|
||||
(identifier)
|
||||
(object (identifier) (function_expression
|
||||
(formal_parameters (identifier) (identifier))
|
||||
(statement_block (var_declaration (assignment (identifier) (identifier)))))))))
|
||||
(statement_block (var_declaration (identifier) (identifier)))))))
|
||||
|
||||
==========================================
|
||||
parses comments
|
||||
|
|
@ -72,14 +57,14 @@ var thing = {
|
|||
(program
|
||||
(comment)
|
||||
(comment)
|
||||
(var_declaration (assignment (identifier) (object
|
||||
(var_declaration (identifier) (object
|
||||
(comment)
|
||||
(comment)
|
||||
(identifier) (function_expression
|
||||
(formal_parameters (identifier) (comment))
|
||||
(statement_block
|
||||
(comment)
|
||||
(expression_statement (function_call (identifier)))))))))
|
||||
(expression_statement (function_call (identifier))))))))
|
||||
|
||||
==========================================
|
||||
parses comments within expressions
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ parses constructor calls
|
|||
var x = new Node(5, new Node(3, null));
|
||||
---
|
||||
(program (var_declaration
|
||||
(assignment (identifier)
|
||||
(identifier)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(constructor_call (function_call (identifier)
|
||||
(number)
|
||||
(null))))))))
|
||||
(null)))))))
|
||||
|
||||
==========================================
|
||||
parses property access with dot notation
|
||||
|
|
@ -116,6 +116,20 @@ print(x in y)
|
|||
(identifier)
|
||||
(in_expression (identifier) (identifier)))))
|
||||
|
||||
============================================
|
||||
parses assignment operators
|
||||
============================================
|
||||
x += 1;
|
||||
x -= 1;
|
||||
x *= 2;
|
||||
x /= 2;
|
||||
---
|
||||
(program
|
||||
(expression_statement (assignment (identifier) (number)))
|
||||
(expression_statement (assignment (identifier) (number)))
|
||||
(expression_statement (assignment (identifier) (number)))
|
||||
(expression_statement (assignment (identifier) (number))))
|
||||
|
||||
============================================
|
||||
parses property access and operators
|
||||
============================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue