move control into statements

This commit is contained in:
Torsten Ruger 2015-10-19 14:57:03 +03:00
parent ab0a94bd51
commit 72ed05254e
3 changed files with 21 additions and 27 deletions

View File

@ -1,25 +0,0 @@
module Parser
module Control
include Parslet
rule(:while_statement) do
keyword_while >> left_parenthesis >> r_value.as(:condition) >>
right_parenthesis >> statements_end.as(:body)
end
rule(:if_statement) do
keyword_if >>
left_parenthesis >> r_value.as(:conditional) >> right_parenthesis >>
statements_else.as(:true_statements) >> statements_end.as(:false_statements)
end
rule(:small_conditional) do
keyword_if >>
left_parenthesis >> r_value.as(:conditional) >> right_parenthesis >>
statements_end.as(:true_statements)
end
rule(:return_statement) do
keyword_return >> r_value.as(:return_statement)
end
end
end

View File

@ -2,7 +2,6 @@ require_relative "basic_types"
require_relative "compound_types"
require_relative "tokens"
require_relative "keywords"
require_relative "control"
require_relative "statement"
require_relative "call_site"
require_relative "function_definition"
@ -24,7 +23,6 @@ module Parser
include CompoundTypes
include Tokens
include Keywords
include Control
include Statement
include CallSite
include FunctionDefinition

View File

@ -2,6 +2,27 @@ module Parser
module Statement
include Parslet
rule(:while_statement) do
keyword_while >> left_parenthesis >> r_value.as(:condition) >>
right_parenthesis >> statements_end.as(:body)
end
rule(:if_statement) do
keyword_if >>
left_parenthesis >> r_value.as(:conditional) >> right_parenthesis >>
statements_else.as(:true_statements) >> statements_end.as(:false_statements)
end
rule(:small_conditional) do
keyword_if >>
left_parenthesis >> r_value.as(:conditional) >> right_parenthesis >>
statements_end.as(:true_statements)
end
rule(:return_statement) do
keyword_return >> r_value.as(:return_statement)
end
rule(:statement) { (return_statement | while_statement | small_conditional | if_statement |
assignment | class_field | field_def | call_site |
hash_constant | array_constant) }