antlr / antlr/antlr4

New option for : lexer keyword=true

Open
#492 0 comments 0 reactions 0 assignees View on GitHub
type:feature
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

This option is complementary to the option emitOnMatch, but I think more complicated to implement.

If I want to parse
http://www.lemonde.frhttp://www.bbc.co.ukhttp://www.httpsite.com => SITE (www.lemonde.fr) SITE ( www.bbc.co.uk ) SITE (www.httpsite.com)
with rules

```
HTTP : ( option keyword = true : 'http://' ) -> skip;
SITE : SITECHAR+;
fragment SITECHAR : [a-zA-Z0-9\.];
```

`http://` would be considered as a keyword and would act as a delimiter. If matched then the lexer matches the first rule with characters before the 'h' of `http://`.
It means the sequence `http://` is tried for each new character read by the lexer, and the rule HTTP is never discarded.

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Start by reviewing the lexer handling for the existing emitOnMatch option and how lexer rules are retained or discarded; done means the keyword rule is tried at each new character and delimits the preceding SITE text as shown in the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.