Sha256: 32df568bd3175da801abdc4b086b9abed783ff17e8228e97b71b083eb1b3ef37
Contents?: true
Size: 1.33 KB
Versions: 8
Compression:
Stored size: 1.33 KB
Contents
module CEML grammar Lexer rule text (!eol .)+ end rule nl (ws? comment? eol)+ end rule ws [ \t\f]+ end rule comment '//' text end rule eol ("\r" "\n"?) / "\n" end rule number ([1-9]+ [0-9]* / '0' / 'an' / 'a' / 'the') { def value case text_value when 'a', 'an', 'the' then 1 else text_value.to_i end end } end rule and (ws? ',')? ws 'and' ws / ws? ',' ws? end rule reserved_word 'and' / 'within' end rule id !(reserved_word ws) [a-zA-Z_]+ end rule distance number ws? distance_unit:('miles' / 'mile' / 'mi' / 'km' / 'kilometers' / 'k' / 'meters' / 'm' / 'ft' / 'feet' / 'f' / 'blocks' / 'block') { def meters number.text_value.to_f * case distance_unit.text_value when /^mi/; 1600; when /^k/; 1000; when /^m/; 1; when /^f/; 0.35; when /^b/; 200; else 1; end end } end rule range min:number max:('+' / '-' number)? { def min super.value end def max return min if super.empty? return 10000 if super.text_value == '+' return super.number.text_value.to_i end } end end end
Version data entries
8 entries across 8 versions & 1 rubygems