Re: [Flex-help] Regular expressions match everything except
flex is a tool for generating scanners
Brought to you by:
wlestes
From: Marcel L. <ma...@la...> - 2009-08-04 05:46:39
|
You're using character classes incorrectly. I suggest taking some time to reread the "Patterns" section in the Flex manual very carefully. You're going to have a hard time in the future without fully understanding patterns :). http://flex.sourceforge.net/manual/Patterns.html My suggestion is to change that to something like this: "ENDCODE" { BEGIN(INTITIAL); yytext[yyleng - 7] = 0; // remove "ENDCODE" from yytext yylval->stringVal = new std::string(yytext); return token::ENDCODE; } [^E]+|E { yymore(); } On Tue, 04 Aug 2009 00:24:25 +0100, Alex Duller <al...@pi...> wrote: > Hi, > I'm trying to extract text between two boundary keywords as shown below: > > CODE > std::cout << "Hello, world" << std::endl; > ENDCODE; > > So I want to get the text between CODE and ENDCODE but don't want to end > up parsing it. At the moment I'm trying to use start conditions like so: > <cpp>{ > "ENDCODE" { BEGIN(INITIAL); return token::ENDCODE; } > [^ENDCODE]+ { > yylval->stringVal = new std::string(yytext); > } > } > > It sort of works except that the second pattern isn't quite correct and > breaks whenever anything like 'END' or 'ND' is found... > > Any suggestions will be greatly appreciated. > > thanks, > Alex > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Flex-help mailing list > Fle...@li... > https://lists.sourceforge.net/lists/listinfo/flex-help |