[antlr-interest] handling quoted string

karan g gkarandeep at gmail.com
Thu Sep 29 23:15:34 PDT 2005


Hello,
I have a problem regarding handling of quoted strings. I shall elaborate my
problem and the requirements associated with it.

I have a key-value pair 'param=value'
value can be a..z|0..9|' '|'\t'|'.'|'$'|'@'|'#'|'\'|'/'

value can be enclosed in double quotes though it is not compulsary.
ie. valid scenarios for value are "abc" or "ab c" or abc etc..
invalid scenarios here could be "abc or "ab"c etc...
In other words, if the quote appears in the input, then it should be at the
beginning and at the end.

For this a straight forward lexer rule can be written. However, my
requirement here is that the value should be stored and I should be able to
throw an userdefined exception with the input given.

I have attempted a lexer rule which throws a Token stream exception when the
quoted string encounters an invalid scenario . Here I would like a way that
I catch that exception and throw my user defined exception with the exact
input given. I was not able to store the exact input before I sent the value
to lexer rule.

Please suggest me all the possible solutions.

Thanks,
karan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050930/cdc81262/attachment.html


More information about the antlr-interest mailing list