add a simple return, ie the normal kind, not with trailing statements
This commit is contained in:
@ -6,6 +6,7 @@ This includes the parser and generated ast.
|
||||
Parslet is really great in that it:
|
||||
- does not generate code but instean gives a clean dsl to define a grammar
|
||||
- uses ruby modules so one can split the grammars up
|
||||
- has support for binary operators with presedence and binding
|
||||
- has a seperate tranform stage to generate an ast layer
|
||||
|
||||
Especially the last point is great. Since it is seperate it does not clutter up the actual grammar.
|
||||
|
@ -13,5 +13,8 @@ module Parser
|
||||
right_parenthesis >> keyword_do >> newline >>
|
||||
expressions_end.as(:body)
|
||||
end
|
||||
rule(:simple_return) do
|
||||
keyword_return >> (operator_expression|value_expression).as(:return_expression) >> eol
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -10,6 +10,7 @@ module Parser
|
||||
rule(:keyword_false) { str('false').as(:false) >> space?}
|
||||
rule(:keyword_if) { str('if').as(:if) >> space? }
|
||||
rule(:keyword_rescue) { str('rescue').as(:rescue) >> space?}
|
||||
rule(:keyword_return) { str('return').as(:return) >> space?}
|
||||
rule(:keyword_true) { str('true').as(:true) >> space?}
|
||||
rule(:keyword_nil) { str('nil').as(:nil) >> space?}
|
||||
rule(:keyword_unless) { str('unless').as(:unless) >> space?}
|
||||
|
@ -36,6 +36,10 @@ module Parser
|
||||
Ast::WhileExpression.new(while_cond, body)
|
||||
end
|
||||
|
||||
rule(:return => simple(:return) , :return_expression => simple(:return_expression))do
|
||||
Ast::ReturnExpression.new(return_expression)
|
||||
end
|
||||
|
||||
rule(:parmeter => simple(:parmeter)) { parmeter }
|
||||
rule(:parmeter_list => sequence(:parmeter_list)) { parmeter_list }
|
||||
|
||||
|
Reference in New Issue
Block a user