add comment and remove newline from space (starting a long whitespace battle)

This commit is contained in:
Torsten Ruger 2014-05-08 18:38:49 +03:00
parent 4c585e415b
commit 034ae4f7ca

View File

@ -4,9 +4,15 @@ module Parser
# floats ?
module BasicTypes
include Parslet
rule(:space) { match('\s').repeat(1) }
# space really is just space. ruby is newline sensitive, so there is more whitespace footwork
# rule of thumb is that anything eats space behind it, but only space, no newlines
rule(:space) { (str('\t') | str(' ')).repeat(1) }
rule(:space?) { space.maybe }
rule(:eol) { (str("\n") >> space?) | any.absent? }
rule(:newline){ str('\n') }
rule(:comment){ match('#') >> (newline.absent? >> any).repeat.as(:comment) >> newline }
rule(:eol) { (newline >> space?) | any.absent? }
rule(:double_quote){ str('"') }
rule(:minus) { str('-') }
@ -24,15 +30,18 @@ module Parser
# identifier must start with lower case
rule(:name) { (match['a-z'] >> match['a-zA-Z0-9'].repeat).as(:name) >> space? }
rule(:string_special) { match['\0\t\n\r"\\\\'] }
rule(:escaped_special) { str("\\") >> match['0tnr"\\\\'] }
#anything in double quotes
rule(:string){
double_quote >>
( double_quote.absent? >> any ).repeat.as(:string) >>
( escaped_special | string_special.absent? >> any ).repeat.as(:string) >>
double_quote >> space?
}
rule(:integer) { sign.maybe >> digit.repeat(1).as(:integer) >> space? }
rule(:float) { integer >> dot >> integer >>
(exponent >> sign.maybe >> digit.repeat).maybe >> space?}
(exponent >> sign.maybe >> digit.repeat(1,3)).maybe >> space?}
end
end