Fix expansion of repeat rules into recursive rules

Previously, the way repeat rules were expanded, the auxiliary
rule always needed to be reduced, even if the repeating content
was empty. This caused problems in parse states where some items
contained the repeat rule and some did not. To make those cases
work, the repeat rule had to explicitly be marked as optional.
With this change, that is no longer necessary.
This commit is contained in:
Max Brunsfeld 2014-09-07 08:50:42 -07:00
parent 43ecac2a1d
commit ed11ef557a
10 changed files with 48641 additions and 39051 deletions

View file

@ -20,9 +20,8 @@ if (isReady()) {
console.log(theData)
}
---
(program
(if_statement (function_call (identifier))
(statement_block (expression_statement (function_call (property_access (identifier) (identifier)) (identifier))))))
(if_statement (function_call (identifier))
(statement_block (expression_statement (function_call (property_access (identifier) (identifier)) (identifier)))))
==========================================
parses if-else statements
@ -33,10 +32,10 @@ if (theCondition) {
secondFunction();
}
---
(program (if_statement
(if_statement
(identifier)
(statement_block (expression_statement (function_call (identifier))))
(statement_block (expression_statement (function_call (identifier))))))
(statement_block (expression_statement (function_call (identifier)))))
==================================================
parses if-else statements with multiple conditions
@ -49,12 +48,11 @@ else {
thirdFunction();
}
---
(program
(if_statement (identifier)
(statement_block (expression_statement (function_call (identifier))))
(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)))))))
(expression_statement (function_call (identifier)))
(statement_block (expression_statement (function_call (identifier))))))
==========================================
parses for loops
@ -63,11 +61,11 @@ for (var i = 1; someCondition(i); i = next()) {
doSomething();
}
---
(program (for_statement
(for_statement
(var_declaration (identifier) (number))
(expression_statement (function_call (identifier) (identifier)))
(assignment (identifier) (function_call (identifier)))
(statement_block (expression_statement (function_call (identifier))))))
(statement_block (expression_statement (function_call (identifier)))))
==========================================
parses for-in loops
@ -92,9 +90,9 @@ while (someCondition(i)) {
doSomething();
}
---
(program (while_statement
(while_statement
(function_call (identifier) (identifier))
(statement_block (expression_statement (function_call (identifier))))))
(statement_block (expression_statement (function_call (identifier)))))
==========================================
parses try/catch statements
@ -126,8 +124,7 @@ parses throw statements
===========================================
throw new Error("wtf");
---
(program
(throw_statement (constructor_call (function_call (identifier) (string)))))
(throw_statement (constructor_call (function_call (identifier) (string))))
===========================================
parses indented code after blocks
@ -154,16 +151,14 @@ switch(x) {
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))))))
(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)))))

View file

@ -3,7 +3,7 @@ recovers from errors in function calls
==========================================
stuff(|||);
---
(program (expression_statement (function_call (identifier) (ERROR '|'))))
(expression_statement (function_call (identifier) (ERROR '|')))
==========================================
recovers from errors in if statements
@ -20,21 +20,3 @@ moreStuff();
(statement_block (expression_statement (ERROR '*'))))
(expression_statement (function_call (identifier))))
==========================================
recovers from errors in for loops
==========================================
stuff();
for (var i = 0; *nonsense*; i++) {
*more-nonsense*;
}
moreStuff();
---
(program
(expression_statement (function_call (identifier)))
(for_statement
(var_declaration (identifier) (number))
(expression_statement (ERROR '*'))
(math_op (identifier))
(statement_block (expression_statement (ERROR '*'))))
(expression_statement (function_call (identifier))))

View file

@ -3,24 +3,24 @@ parses regexes
==========================================
theFunction(/regex1/, /regex2/g);
---
(program (expression_statement (function_call (identifier)
(regex) (regex))))
(expression_statement (function_call (identifier)
(regex) (regex)))
==========================================
parses numbers
==========================================
theFunction(100.0, 200);
---
(program (expression_statement (function_call (identifier)
(number) (number))))
(expression_statement (function_call (identifier)
(number) (number)))
==========================================
parses strings
==========================================
theFunction('', "", 'single-quoted-string', "double-quoted-string");
---
(program (expression_statement (function_call (identifier)
(string) (string) (string) (string))))
(expression_statement (function_call (identifier)
(string) (string) (string) (string)))
==========================================
parses function expressions
@ -31,12 +31,11 @@ var x = {
}
};
---
(program
(var_declaration
(identifier)
(object (identifier) (function_expression
(formal_parameters (identifier) (identifier))
(statement_block (var_declaration (identifier) (identifier)))))))
(var_declaration
(identifier)
(object (identifier) (function_expression
(formal_parameters (identifier) (identifier))
(statement_block (var_declaration (identifier) (identifier))))))
==========================================
parses comments
@ -56,15 +55,14 @@ var thing = {
---
(comment)
(comment)
(program
(var_declaration (identifier) (object
(comment)
(comment)
(identifier) (function_expression
(formal_parameters (identifier) (comment))
(statement_block
(comment)
(expression_statement (function_call (identifier))))))))
(var_declaration (identifier) (object
(comment)
(comment)
(identifier) (function_expression
(formal_parameters (identifier) (comment))
(statement_block
(comment)
(expression_statement (function_call (identifier)))))))
==========================================
parses comments within expressions
@ -72,5 +70,4 @@ parses comments within expressions
y // comment
* z;
---
(program
(expression_statement (math_op (expression (identifier) (comment)) (identifier))))
(expression_statement (math_op (expression (identifier) (comment)) (identifier)))

View file

@ -3,22 +3,22 @@ parses function calls
==========================================
x.theMethod(5, 6);
---
(program (expression_statement (function_call
(expression_statement (function_call
(property_access (identifier) (identifier))
(number) (number))))
(number) (number)))
==========================================
parses constructor calls
==========================================
var x = new Node(5, new Node(3, null));
---
(program (var_declaration
(var_declaration
(identifier)
(constructor_call (function_call (identifier)
(number)
(constructor_call (function_call (identifier)
(number)
(null)))))))
(null))))))
==========================================
parses property access with dot notation
@ -41,10 +41,10 @@ object
.someProperty
.otherProperty
---
(program (expression_statement
(expression_statement
(property_access
(property_access (identifier) (identifier))
(identifier))))
(identifier)))
===========================================
parses dynamic property access
@ -65,10 +65,10 @@ parses ternary expressions
==========================================
print(isDone() ? stuff : otherStuff);
---
(program (expression_statement
(expression_statement
(function_call
(identifier)
(ternary (function_call (identifier)) (identifier) (identifier)))))
(ternary (function_call (identifier)) (identifier) (identifier))))
==========================================
parses mathematical operators
@ -76,12 +76,12 @@ parses mathematical operators
-a + b * c - d / +e
---
(program (expression_statement
(expression_statement
(math_op
(math_op (identifier))
(math_op
(math_op (identifier) (identifier))
(math_op (identifier) (math_op (identifier)))))))
(math_op (identifier) (math_op (identifier))))))
==========================================
parses boolean operators
@ -89,11 +89,11 @@ parses boolean operators
!a || !(b && c)
---
(program (expression_statement
(expression_statement
(bool_op
(bool_op (identifier))
(bool_op
(expression (bool_op (identifier) (identifier)))))))
(expression (bool_op (identifier) (identifier))))))
===========================================
parses the type operators
@ -101,10 +101,10 @@ parses the type operators
print((x instanceof Array) || (typeof x == "string"))
---
(program (expression_statement (function_call (identifier)
(expression_statement (function_call (identifier)
(bool_op
(expression (instanceof_expression (identifier) (identifier)))
(expression (typeof_expression (bool_op (identifier) (string))))))))
(expression (typeof_expression (bool_op (identifier) (string)))))))
============================================
parses the 'in' operator
@ -112,9 +112,9 @@ parses the 'in' operator
print(x in y)
---
(program (expression_statement (function_call
(expression_statement (function_call
(identifier)
(in_expression (identifier) (identifier)))))
(in_expression (identifier) (identifier))))
============================================
parses assignment operators
@ -136,7 +136,7 @@ parses property access and operators
print(x.y.z && a.b.c)
---
(program (expression_statement (function_call (identifier)
(expression_statement (function_call (identifier)
(bool_op
(property_access (property_access (identifier) (identifier)) (identifier))
(property_access (property_access (identifier) (identifier)) (identifier))))))
(property_access (property_access (identifier) (identifier)) (identifier)))))