soml-parser/lib/parser/control.rb

25 lines
836 B
Ruby
Raw Normal View History

2014-06-04 18:55:04 +02:00
module Parser
module Control
include Parslet
rule(:conditional) do
2015-09-15 17:57:31 +02:00
keyword_if >>
left_parenthesis >> (operator_expression|value_expression).as(:conditional) >> right_parenthesis >>
expressions_else.as(:if_true) >> expressions_end.as(:if_false)
end
rule(:small_conditional) do
keyword_if >>
left_parenthesis >> (operator_expression|value_expression).as(:conditional) >> right_parenthesis >>
expressions_end.as(:if_true)
2014-06-04 18:55:04 +02:00
end
2015-09-15 17:57:31 +02:00
2014-06-04 18:55:04 +02:00
rule(:while_do) do
keyword_while >> left_parenthesis >> (operator_expression|value_expression).as(:while_cond) >>
2015-09-15 17:57:31 +02:00
right_parenthesis >> expressions_end.as(:body)
2014-06-04 18:55:04 +02:00
end
rule(:simple_return) do
keyword_return >> (operator_expression|value_expression).as(:return_expression)
end
end
end