soml-parser/lib/parser/operators.rb

49 lines
2.3 KiB
Ruby
Raw Normal View History

2014-06-04 18:55:04 +02:00
module Parser
module Operators
include Parslet
rule(:exponent) { str('**') >> space?}
rule(:multiply) { match['*/%'] >> space? }
rule(:plus) { match['+-'] >> space? }
rule(:shift) { str(">>") | str("<<") >> space?}
rule(:bit_and) { str('&') >> space?}
rule(:bit_or) { str('|') >> space?}
rule(:greater_equal) { str('>=') >> space?}
rule(:less_or_equal) { str('<=') >> space?}
rule(:larger) { str('>') >> space?}
rule(:smaller) { str('<') >> space?}
rule(:identity) { str('===') >> space?}
rule(:equal) { str('==') >> space?}
rule(:not_equal) { str('!=') >> space?}
rule(:boolean_and) { str('&&') | str("and") >> space?}
rule(:boolean_or) { str('||') | str("or") >> space?}
rule(:assign) { str('=') >> space?}
rule(:op_assign) { str('+=')|str('-=')|str('*=')|str('/=')|str('%=') >> space?}
rule(:eclipse) { str('..') |str("...") >> space?}
rule(:assign) { str('=') >> space?}
2015-09-15 17:57:31 +02:00
#infix doing the heavy lifting here,
2014-06-04 18:55:04 +02:00
# is defined as an expressions and array of [atoms,priority,binding] triples
2015-10-09 11:42:50 +02:00
rule(:operator_expression) do infix_expression(r_value,
2014-06-04 18:55:04 +02:00
[exponent, 120, :left] ,
[multiply, 120, :left] ,
[plus, 110, :left],
[shift, 100, :left],
[bit_and, 90, :left],
[bit_or, 90, :right],
[greater_equal, 80, :left],
[less_or_equal, 80, :left],
[larger, 80, :left],
[smaller, 80, :left],
[identity, 70, :right],
[equal, 70, :right],
[not_equal, 70, :right],
[boolean_and, 60, :left],
[boolean_or, 50, :right],
[eclipse, 40, :right],
2015-09-15 17:57:31 +02:00
[keyword_rescue, 30, :right],
2014-06-04 18:55:04 +02:00
[assign, 20, :right],
2015-09-15 17:57:31 +02:00
[op_assign, 20, :right] ) >> space?
2014-06-04 18:55:04 +02:00
end
end
end