Re: [Flex-help] help with dangerous trailing context warning
flex is a tool for generating scanners
Brought to you by:
wlestes
|
From: Aaron S. <aa...@se...> - 2007-10-18 18:18:53
|
First, please let us know what version of flex you're using. There are some new features available in 2.5.33 and that's important. This specific message and its causes are documented here: http://flex.sourceforge.net/manual/Limitations.html Flex does not implement non-greedy matching, as explained here: http://flex.sourceforge.net/manual/Why-doesnt-flex-have-non_002dgreedy-operators-like-perl-does_003f.html What you probably want to do is use a lexer state. For example, here's how I handle comments in one of my lexers: %state QSTRING %% <QSTRING>([^\"]|\\\"|{CRLF})+ { yylval.sval = strndup(yytext, yyleng); return STRING; } <QSTRING>\" { BEGIN INITIAL; } <INITIAL>\" { BEGIN QSTRING; } Right, so in the INITIAL state, when we see a quote we go into the QSTRING state. In QSTRING, we match anything that isn't a quote, is a quoted quote, or is whitespace. That match stops when it sees an unquoted quote and returns the string. The next character must be a quote, and the lexer eats that quote and returns to the INITIAL state. Aaron On Thu, Oct 18, 2007, inhahe <in...@gm...> said: > help!! i'm trying to make a rule that matches r'.*' and captures only > what's between the quotes and you can also do r'foo\'bar' but not r'foo\' > > no matter how i try to construct this I get a "dangerous trailing context" > warning. |