Handle ubiquitous tokens at the beginning of programs

As a final step before returning the finished parse tree, check if
there are still multiple nodes on the stack. If so, make the inner
nodes children of the top node.
This commit is contained in:
Max Brunsfeld 2014-05-09 12:46:36 -07:00
parent 3f374c6547
commit e4be585c43
3 changed files with 42 additions and 19 deletions

View file

@ -97,6 +97,8 @@ print(object[propertyName()]);
==========================================
parses comments
==========================================
// this is the beginning of the script.
// here we go.
var thing = {
// this is a property.
@ -108,14 +110,17 @@ var thing = {
}
};
---
(program (var_declaration (assignment (identifier) (object
(program
(comment)
(comment)
(identifier) (function_expression
(formal_parameters (identifier) (comment))
(statement_block
(comment)
(expression_statement (function_call (identifier)))))))))
(var_declaration (assignment (identifier) (object
(comment)
(comment)
(identifier) (function_expression
(formal_parameters (identifier) (comment))
(statement_block
(comment)
(expression_statement (function_call (identifier)))))))))
======================================
parses real code