skvadrik / re2c

Lexer generator for C, C++, D, Go, Haskell, Java, JS, OCaml, Python, Rust, V and Zig.
https://re2c.org
Other
1.11k stars 173 forks source link

overlapping trailling contexts #459

Closed lucas-mior closed 11 months ago

lucas-mior commented 1 year ago

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.

skvadrik commented 1 year ago

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).

lucas-mior commented 1 year ago

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.

skvadrik commented 1 year ago

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.

lucas-mior commented 1 year ago

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.

pmetzger commented 11 months ago

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

skvadrik commented 11 months ago

Yes, I think they can be closed. I usually wait until the author of the bug report closes it, or else I close all such bugs before release.

On Wed, 29 Nov 2023, 15:44 Perry E. Metzger, @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/skvadrik/re2c/issues/459#issuecomment-1832166376, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAISVJXDFAN2DD2AUVSYG4DYG5J7VAVCNFSM6AAAAAA7TYXSA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZSGE3DMMZXGY . You are receiving this because you commented.Message ID: @.***>