same syntax change for while_xxx
xxx can be any string for the parser the language will restrict if somewhat later
This commit is contained in:
parent
7cc7ab5c18
commit
3061ddfed9
@ -11,11 +11,10 @@ module Parser
|
||||
rule(:keyword_return) { str('return').as(:return) >> space?}
|
||||
rule(:keyword_true) { str('true').as(:true) }
|
||||
rule(:keyword_nil) { str('nil').as(:nil) }
|
||||
rule(:keyword_while) { str('while').as(:while) }
|
||||
|
||||
# this rule is just to make sure identifiers can't be keywords. Kind of duplication here, but we need the
|
||||
# space in above rules, so just make sure to add any here too.
|
||||
rule(:keyword){ str('if_') | str('else') | str('end') | str('while') |
|
||||
rule(:keyword){ str('if_') | str('else') | str('end') | str('while_') |
|
||||
str('false') | str('true')| str('nil') | str("class") |
|
||||
str('return')| str('int')| str('field')}
|
||||
end
|
||||
|
@ -2,8 +2,12 @@ module Parser
|
||||
module Statement
|
||||
include Parslet
|
||||
|
||||
rule( :keyword_while) do
|
||||
str("while_") >> alpha.repeat.as(:condition) >> space
|
||||
end
|
||||
|
||||
rule(:while_statement) do
|
||||
keyword_while >> left_parenthesis >> r_value.as(:condition) >>
|
||||
keyword_while >> left_parenthesis >> r_value.as(:conditional) >>
|
||||
right_parenthesis >> statements_end.as(:body)
|
||||
end
|
||||
|
||||
|
@ -63,10 +63,10 @@ module Parser
|
||||
s(:field_access , s(:receiver , receiver) , s(:field , field) )
|
||||
end
|
||||
|
||||
rule(:while => simple(:while),
|
||||
:condition => simple(:condition) ,
|
||||
rule(:condition => simple(:condition) ,
|
||||
:conditional => simple(:conditional),
|
||||
:body => {:statements => sequence(:body) , :end => simple(:e) }) do
|
||||
s(:while_statement , s(:condition , condition), s(:statements , *body))
|
||||
s(:while_statement,condition.to_s.to_sym, s(:conditional , conditional), s(:statements , *body))
|
||||
end
|
||||
|
||||
rule(:condition => simple(:condition), :conditional => simple(:conditional),
|
||||
@ -80,7 +80,7 @@ module Parser
|
||||
|
||||
rule(:condition => simple(:condition), :conditional => simple(:conditional),
|
||||
:true_statements => {:statements => sequence(:true_statements) , :end => simple(:e) }) do
|
||||
s(:if_statement, condition.to_s.to_sym, s(:condition, conditional),
|
||||
s(:if_statement, condition.to_s.to_sym, s(:condition, conditional),
|
||||
s(:true_statements, *true_statements), s(:false_statements , nil) )
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user