2014-05-10 10:14:34 +02:00
|
|
|
module Parser
|
2014-05-12 11:20:31 +02:00
|
|
|
module Control
|
2014-05-10 10:14:34 +02:00
|
|
|
include Parslet
|
2014-05-12 11:14:04 +02:00
|
|
|
rule(:conditional) do
|
2014-05-12 12:57:24 +02:00
|
|
|
keyword_if >>
|
2014-05-12 20:36:38 +02:00
|
|
|
(( (value_expression|operator_expression).as(:conditional) ) |
|
|
|
|
left_parenthesis >> (operator_expression|value_expression).as(:conditional) >> right_parenthesis) >>
|
2014-05-12 12:57:24 +02:00
|
|
|
newline >> expressions_else.as(:if_true) >> newline >> expressions_end.as(:if_false)
|
2014-05-12 11:14:04 +02:00
|
|
|
end
|
2014-05-10 18:02:51 +02:00
|
|
|
|
2014-05-12 11:14:04 +02:00
|
|
|
rule(:while_do) do
|
2014-05-12 20:36:38 +02:00
|
|
|
keyword_while >> left_parenthesis >> (operator_expression|value_expression).as(:while_cond) >>
|
2014-05-12 12:47:47 +02:00
|
|
|
right_parenthesis >> keyword_do >> newline >>
|
2014-05-12 11:26:38 +02:00
|
|
|
expressions_end.as(:body)
|
2014-05-12 11:14:04 +02:00
|
|
|
end
|
2014-05-27 15:33:24 +02:00
|
|
|
rule(:simple_return) do
|
2014-05-27 15:51:37 +02:00
|
|
|
keyword_return >> (operator_expression|value_expression).as(:return_expression)
|
2014-05-27 15:33:24 +02:00
|
|
|
end
|
2014-05-10 10:14:34 +02:00
|
|
|
end
|
|
|
|
end
|