librelist archives

« back to archive

Problem with parsing a relational operator

Problem with parsing a relational operator

From:
Thiel Chang
Date:
2011-04-18 @ 10:49
Hi guys,

I am testing to parse relational expressions and defined  the following  
relational operators:

rule(:gt_op)      { str('>') >> space? }
rule(:ge_op)     { str('<=') >> space? }
rule(:lt_op)       { str('<') >> space? }
rule(:le_op)       { str('<=') >> space? }
rule(:eq_op)     { str('==') >> space? }


To test them I used the following parse statements:

Parser.new.rel_operation.parse_with_debug(' ( a - b ) < c ')            
=>  Parsing succeds

Parser.new.rel_operation.parse_with_debug(' ( a + b ) >   c ')          
=>  Parsing succeeds

Parser.new.rel_operation.parse_with_debug(' ( a + b ) == c' )          
=>   Parsing succeeds

Parser.new.rel_operation.parse_with_debug(' ( a + b ) >=  c' )         
=>   Parsing does NOT succeeds

Parser.new.rel_operation.parse_with_debug(' ( a + b ) <=  c' )         
=>   Parsing does NOT succeeds

Because of the parsing failures of the '>=' and '<=' operators  I 
replaced the relational operator '>='  with ':='  just to know if Parslet
could parse those two tokens as a  relational operator.

Parser.new.rel_operation.parse_with_debug(' ( a + b ) :=  c' )           
    =>   Parsing DOES succeeds!

Can anyone explain why  parsing with e.g. '==',  '<', '>' and ':=' went 
well and '>=' and '<=' does not.

Is there an 'undocumented' feature ;-)     in Parslet which does not 
allow using '>=' and '<=' as symbols in Parslet or did I made a mistake?

Thanks in advance,

Thiel