jzimmerman / langcc

langcc: A Next-Generation Compiler Compiler
https://langcc.io
Apache License 2.0
1.73k stars 58 forks source link

[QUESTION] Do you support "look ahead" operation? #12

Closed DanielMazurkiewicz closed 2 years ago

DanielMazurkiewicz commented 2 years ago

Eg. Match everything till '\n'|'*/'|eof

jzimmerman commented 2 years ago

Can you say more precisely what kind of lookahead operation you're looking for, and an example of how you might use it?

(Also, I've enabled GitHub Discussions, so in the future, for questions, you can start a thread there instead of creating an issue.)

DanielMazurkiewicz commented 2 years ago

Lets say I want a content of hpp multiline comment, each line separately

/* bla 0
bla bla bla 1
bla bla 2
bla 3 */

so in this case once I find comment opening I want to match zero or more times everything till occurrence of new line or string "*/" or end of file (but without these delimiters)

jzimmerman commented 2 years ago

Yes, this is supported in the lexer modes -- take a look at grammars/go.lang for an example, specifically the following lines:

`/*` => { push comment; pass; }

// ...

mode comment {
    `*/` => { pass; pop_extract; }
    _ => { pass; }
}
DanielMazurkiewicz commented 2 years ago

cool, thanks!