lex-parser
lex-parser copied to clipboard
end of line ($) doesn't work as expected
just tried to use jison, and this got me lost for hours.
$ doesn't seem to work.
jison documentation points to bison, where $ is widely used.
in the samples here the \n+ is been used instead.
Could you provide a link to the bison docs and jison samples you're referring to? I may have totally missed this.
Yes of course:
From Jison's Lexical Analysis docs you can follow "pattern matchers" into this URL:
http://dinosaur.compilertools.net/flex/flex_7.html#SEC7
And there you find:
`r$'
an r, but only at the end of a line (i.e., just before a newline). Equivalent to "r/\n".
Note that flex's notion of "newline" is exactly whatever the C compiler used to
compile flex interprets '\n' as; in particular, on some DOS systems you must
either filter out \r's in the input yourself, or explicitly use r/\r\n for "r$".
I was testing to write an HTTP parser where end of line is used to delimiter headers, etc. ^ and $ are very convenient in those cases.