comment and keyword handling in treetop

# whitespace
rule white
[ \r\t\n]+
end

# mandatory space
rule SPACE
(white / comment)+
end

# optional space
rule space
SPACE?
end

# anything but not white
rule non_white_char
!white .
end

# typical keyword rule
rule var_keyword
'var' !non_white_char
end

rule comment
comment_to_eol / multiline_comment
end

rule multiline_comment
'/*' (!'*/' . )* '*/'
end

rule comment_to_eol
# TODO find out why this doesn't work in specs
#'#' (!"\n" .)+ "\n"

'#' (!"\n" .)*
end


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>