2014-06-04 18:55:04 +02:00
|
|
|
module Parser
|
|
|
|
module Keywords
|
|
|
|
include Parslet
|
2015-09-15 17:57:31 +02:00
|
|
|
|
2014-06-04 18:55:04 +02:00
|
|
|
rule(:keyword_begin) { str('begin').as(:begin) >> space?}
|
|
|
|
rule(:keyword_class) { str('class') >> space? }
|
|
|
|
rule(:keyword_do) { str('do').as(:do) >> space?}
|
|
|
|
rule(:keyword_else) { str('else').as(:else) >> space? }
|
2015-09-15 17:57:31 +02:00
|
|
|
rule(:keyword_end) { str('end').as(:end) >> space? }
|
|
|
|
rule(:keyword_false) { str('false').as(:false) }
|
2015-09-27 11:05:35 +02:00
|
|
|
rule(:keyword_field) { str('field').as(:field) >> space? }
|
2015-09-15 17:57:31 +02:00
|
|
|
rule(:keyword_if) { str('if').as(:if) }
|
2014-06-04 18:55:04 +02:00
|
|
|
rule(:keyword_rescue) { str('rescue').as(:rescue) >> space?}
|
|
|
|
rule(:keyword_return) { str('return').as(:return) >> space?}
|
2015-09-15 17:57:31 +02:00
|
|
|
rule(:keyword_true) { str('true').as(:true) }
|
2014-06-04 18:55:04 +02:00
|
|
|
rule(:keyword_module) { str('module') >> space? }
|
2015-09-15 17:57:31 +02:00
|
|
|
rule(:keyword_nil) { str('nil').as(:nil) }
|
2014-06-04 18:55:04 +02:00
|
|
|
rule(:keyword_unless) { str('unless').as(:unless) >> space?}
|
|
|
|
rule(:keyword_until) { str('until').as(:until) >> space?}
|
2015-09-15 17:57:31 +02:00
|
|
|
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
|
2014-06-04 18:55:04 +02:00
|
|
|
# space in above rules, so just make sure to add any here too.
|
2015-09-15 17:57:31 +02:00
|
|
|
rule(:keyword){ str('begin') | str('def') | str('do') | str('else') | str('end') |
|
2014-06-04 18:55:04 +02:00
|
|
|
str('false')| str('if')| str('rescue')| str('true')| str('nil') |
|
2015-09-27 11:05:35 +02:00
|
|
|
str('unless')| str('until')| str('while') | str('field')}
|
2014-06-04 18:55:04 +02:00
|
|
|
end
|
2015-09-15 17:57:31 +02:00
|
|
|
end
|