add comment and remove newline from space (starting a long whitespace battle)
This commit is contained in:
parent
4c585e415b
commit
034ae4f7ca
@ -4,9 +4,15 @@ module Parser
|
|||||||
# floats ?
|
# floats ?
|
||||||
module BasicTypes
|
module BasicTypes
|
||||||
include Parslet
|
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(: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(:double_quote){ str('"') }
|
||||||
rule(:minus) { str('-') }
|
rule(:minus) { str('-') }
|
||||||
@ -24,15 +30,18 @@ module Parser
|
|||||||
# identifier must start with lower case
|
# identifier must start with lower case
|
||||||
rule(:name) { (match['a-z'] >> match['a-zA-Z0-9'].repeat).as(:name) >> space? }
|
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
|
#anything in double quotes
|
||||||
rule(:string){
|
rule(:string){
|
||||||
double_quote >>
|
double_quote >>
|
||||||
( double_quote.absent? >> any ).repeat.as(:string) >>
|
( escaped_special | string_special.absent? >> any ).repeat.as(:string) >>
|
||||||
double_quote >> space?
|
double_quote >> space?
|
||||||
}
|
}
|
||||||
rule(:integer) { sign.maybe >> digit.repeat(1).as(:integer) >> space? }
|
rule(:integer) { sign.maybe >> digit.repeat(1).as(:integer) >> space? }
|
||||||
|
|
||||||
rule(:float) { integer >> dot >> integer >>
|
rule(:float) { integer >> dot >> integer >>
|
||||||
(exponent >> sign.maybe >> digit.repeat).maybe >> space?}
|
(exponent >> sign.maybe >> digit.repeat(1,3)).maybe >> space?}
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user