The parser is no longer hard-coded to skip whitespace. Tokens such as newlines, whose characters overlap with the separator characters, can now be correctly recognized.
89 lines
2.7 KiB
Text
89 lines
2.7 KiB
Text
==========================================
|
|
parses multiple statements
|
|
==========================================
|
|
var x = {}
|
|
firstFunction(x);
|
|
secondFunction(x);
|
|
---
|
|
(program
|
|
(var_declaration (assignment (identifier) (object)))
|
|
(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
|
|
==========================================
|
|
var x = {
|
|
theMethod: function(argA, argB) {
|
|
var x = argA;
|
|
}
|
|
};
|
|
|
|
x.theMethod(5, 6);
|
|
---
|
|
(program
|
|
(var_declaration (assignment
|
|
(identifier)
|
|
(object (identifier) (function_expression
|
|
(formal_parameters (identifier) (identifier))
|
|
(statement_block (var_declaration (assignment (identifier) (identifier))))))))
|
|
(expression_statement (function_call
|
|
(property_access (identifier) (identifier))
|
|
(number) (number))))
|
|
|