eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
665 stars 61 forks source link

Support terminal lookbehind #1356

Closed msujew closed 4 months ago

msujew commented 5 months ago

Closes https://github.com/eclipse-langium/langium/issues/1355

Allows adopters to write positive/negative lookbehind in both EBNF and Regex notation, with full support in the lexer/parser phase.

snarkipus commented 5 months ago

Yay - this cleans up my request from #591!

szarnekow commented 5 months ago

Do you plan to filter code completion based on the look-behind patterns, too?

msujew commented 5 months ago

@szarnekow Can you give an example? I don't think the completion takes the specific token pattern into account at all right now.

szarnekow commented 5 months ago

I see. The completion engine doesn't use the terminal rules to check inserted tokens for validity at all.

msujew commented 5 months ago

Yes, it will currently just insert whatever the scope provider returns, ignoring any potential parser/lexer error that this might result in.

szarnekow commented 5 months ago
grammar test
entry Main: things=AorB+;
AorB: A|B;
A: ('A' | 'C') b=[B:B_TERMINAL]? ';';
B: name=B_TERMINAL ';'
terminal B_TERMINAL: (?<!'A')'B';
hidden terminal WS: /\\s+/;

Model with cursor positions <1> and <2> where I'd invoke CA:

B;
A<1>;
C<2>;

I wouldn't expect B to show up at <1> but at <2> - though I wouldn't get any proposals in either case because of the default reg filter in the completion engine.

msujew commented 5 months ago

I see, thanks for the example. I have created a separate issue, see https://github.com/eclipse-langium/langium/issues/1368 👍