2014-07-07 13:35:55 -07:00
|
|
|
==========================================
|
|
|
|
|
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))))
|
|
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
==========================================
|
2014-06-26 08:52:42 -07:00
|
|
|
js parses if statements
|
2014-04-05 15:55:20 -07:00
|
|
|
==========================================
|
|
|
|
|
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
|
2014-07-07 13:35:55 -07:00
|
|
|
(var_declaration (identifier) (number))
|
2014-04-05 15:55:20 -07:00
|
|
|
(expression_statement (function_call (identifier) (identifier)))
|
|
|
|
|
(assignment (identifier) (function_call (identifier)))
|
|
|
|
|
(statement_block (expression_statement (function_call (identifier))))))
|
|
|
|
|
|
2014-07-07 13:35:55 -07:00
|
|
|
==========================================
|
|
|
|
|
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)))))
|
|
|
|
|
|
2014-05-09 21:36:18 -07:00
|
|
|
==========================================
|
|
|
|
|
parses while loops
|
|
|
|
|
==========================================
|
|
|
|
|
while (someCondition(i)) {
|
|
|
|
|
doSomething();
|
|
|
|
|
}
|
|
|
|
|
---
|
|
|
|
|
(program (while_statement
|
|
|
|
|
(function_call (identifier) (identifier))
|
|
|
|
|
(statement_block (expression_statement (function_call (identifier))))))
|
|
|
|
|
|
|
|
|
|
==========================================
|
|
|
|
|
parses try/catch statements
|
|
|
|
|
==========================================
|
|
|
|
|
try {
|
|
|
|
|
doSomething();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
logError(e);
|
|
|
|
|
}
|
2014-06-11 11:28:49 -07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
doSomething();
|
|
|
|
|
} finally {
|
|
|
|
|
logError();
|
|
|
|
|
}
|
2014-05-09 21:36:18 -07:00
|
|
|
---
|
2014-06-11 11:28:49 -07:00
|
|
|
(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)))))))
|
2014-05-09 21:36:18 -07:00
|
|
|
|
2014-04-05 15:55:20 -07:00
|
|
|
===========================================
|
2014-07-03 08:20:43 -07:00
|
|
|
parses throw statements
|
|
|
|
|
===========================================
|
|
|
|
|
throw new Error("wtf");
|
|
|
|
|
---
|
|
|
|
|
(program
|
|
|
|
|
(throw_statement (constructor_call (function_call (identifier) (string)))))
|
|
|
|
|
|
|
|
|
|
===========================================
|
2014-05-30 13:29:54 -07:00
|
|
|
parses indented code after blocks
|
|
|
|
|
===========================================
|
|
|
|
|
function x() {}
|
|
|
|
|
return z;
|
|
|
|
|
---
|
|
|
|
|
(program
|
|
|
|
|
(expression_statement
|
|
|
|
|
(function_expression (identifier) (formal_parameters) (statement_block)))
|
|
|
|
|
(return_statement (identifier)))
|
2014-06-11 14:01:38 -07:00
|
|
|
|
2014-05-30 13:29:54 -07:00
|
|
|
===========================================
|
2014-04-05 15:55:20 -07:00
|
|
|
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))))))
|
2014-06-11 14:01:38 -07:00
|
|
|
|