wrapping root array as class ExpressionList

This commit is contained in:
Torsten Ruger
2014-06-25 22:45:09 +03:00
parent 0ed11b507f
commit 7e1c0d7f57
6 changed files with 38 additions and 16 deletions

View File

@ -32,6 +32,6 @@ module Parser
include ModuleDef
rule(:root_body) {(module_definition | class_definition | function_definition | expression | call_site )}
rule(:root) { root_body.repeat() }
rule(:root) { root_body.repeat.as(:expression_list) }
end
end

View File

@ -81,6 +81,9 @@ module Parser
Ast::ClassExpression.new(module_name , derived_name ? derived_name.name : nil , class_expressions)
end
rule(:expression_list => sequence(:expression_list)) {
Ast::ExpressionList.new(expression_list)
}
#shortcut to get the ast tree for a given string
# optional second arguement specifies a rule that will be parsed (mainly for testing)
def self.ast string , rule = :root