skvadrik/re2c

overlapping trailling contexts

Closed this issue · 6 comments

Related to #458 .
I'm having trouble with the following:

static int f(const char *YYCURSOR)
{
    const char *YYMARKER;
    /*!re2c
       re2c:define:YYCTYPE = char;
       re2c:yyfill:enable = 0;

       foo.+/.+bar { return 9; }
    */
}

when compiling with --flex-syntax, I get the error index_mime.c:4:4: error: overlapping trailing contexts need multiple context markers, use '-t, --tags' option and '/*!stags:re2c ... */' directive

It seems that the slash is causing the problem, but if I try to escape it I get a syntax error.

This is because slash is the lookahead operator (a.k.a. trailing context). If you need literal slash, put it into square brackets like this: [/] (a character class with a single character).

Thank you very much.
It seems that what I want is the regex to be parsed as a posix extended one.
Do you know of any program which operates this way?
The reason is because I want to generate C code based on human readable text config,
so having to remember re2c (or which standard it uses) specific syntax for that when most programs I know use posix extended, is a bit confusing.
If it was only the slash issue, I might preprocess my config into re2c syntax, but I don't think that's the case.
Anyway, thanks again for the support.

No worries.

Do you know of any program which operates this way?

I'm not aware of any lexer generator that would use Posix ERE syntax. And it's not just a question of syntactic sugar, some Posix features are difficult or impossible to implement on a DFA based engine, e.g. submatch extraction (I don't know of any DFA based lexer generator other than re2c that could do Posix compliant submatch extraction). Of course, if you don't care about such features, it's not a problem for you.

You may want to look at http://www.colm.net/open-source/ragel, it's not Posix ERE but you may like its syntax better.

Thanks for the hints. Indeed, I don't need most features (I think the intersection of features between posix regexes and re2c regexes would be more than enough. I will look into ragel.

Should this (and the other related request) be closed?