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_return) { str('return').as(:return) >> space?}
|
||||||
rule(:keyword_true) { str('true').as(:true) }
|
rule(:keyword_true) { str('true').as(:true) }
|
||||||
rule(:keyword_nil) { str('nil').as(:nil) }
|
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
|
# 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.
|
# 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('false') | str('true')| str('nil') | str("class") |
|
||||||
str('return')| str('int')| str('field')}
|
str('return')| str('int')| str('field')}
|
||||||
end
|
end
|
||||||
|
@ -2,8 +2,12 @@ module Parser
|
|||||||
module Statement
|
module Statement
|
||||||
include Parslet
|
include Parslet
|
||||||
|
|
||||||
|
rule( :keyword_while) do
|
||||||
|
str("while_") >> alpha.repeat.as(:condition) >> space
|
||||||
|
end
|
||||||
|
|
||||||
rule(:while_statement) do
|
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)
|
right_parenthesis >> statements_end.as(:body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ module Parser
|
|||||||
s(:field_access , s(:receiver , receiver) , s(:field , field) )
|
s(:field_access , s(:receiver , receiver) , s(:field , field) )
|
||||||
end
|
end
|
||||||
|
|
||||||
rule(:while => simple(:while),
|
rule(:condition => simple(:condition) ,
|
||||||
:condition => simple(:condition) ,
|
:conditional => simple(:conditional),
|
||||||
:body => {:statements => sequence(:body) , :end => simple(:e) }) do
|
: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
|
end
|
||||||
|
|
||||||
rule(:condition => simple(:condition), :conditional => simple(:conditional),
|
rule(:condition => simple(:condition), :conditional => simple(:conditional),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user