tags:

views:

83

answers:

1

I'm having a great time doing a lexer using flex. Problem is, my code editor doesn't color the syntax of the file, and it seems my rule has an error in it. Since I'm not too sure about how to use single quotes and double quotes inside intervals, I thought I'd share that snippet with you:

[^\\\'\n]+
{
    wchar_t* string;
    utf8_decode(yytext, &string);
    yyextra->append(string);
    free(string);
}

Flex tells me there's an 'unrecognized rule' on the utf8_decode line. If I remove the whole rule, things look fine again.

Can anyone tell what I'm doing wrong here?

+2  A: 

The action must begin on the same line as the pattern. So use

[^\\\'\n]+ {
    wchar_t* string;
    utf8_decode(yytext, &string);
    yyextra->append(string);
    free(string);
}
Peter Eisentraut
Yes, indeed. I just read that elsewhere. That's actually pretty uncool. :(
zneak