Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PreferredRules Question: Candidate rules miss some preferred rules. #158

Open
vczyh opened this issue Oct 22, 2024 · 0 comments
Open

PreferredRules Question: Candidate rules miss some preferred rules. #158

vczyh opened this issue Oct 22, 2024 · 0 comments

Comments

@vczyh
Copy link

vczyh commented Oct 22, 2024

I don't know if it's a BUG.

Example1 results only contain functionRef, Example2 contain functionRef and variableRef.

Example code is here: https://github.com/vczyh/antlr-c3-maybe-bug-examples

Completion

const inputStream = CharStream.fromString("a.b");

core.preferredRules = new Set([
  ExprParser.RULE_variableRef,
  ExprParser.RULE_functionRef,
]);

const candidates = core.collectCandidates(2);

Example1

Expr.g4

grammar Expr;

expression:
    variableRef
    | functionRef
;

variableRef: identifier dotIdentifier;

functionRef: identifier dotIdentifier OPEN_PAR CLOSE_PAR;

identifier: ID;

dotIdentifier: DOT identifier;

OPEN_PAR:  '(';
CLOSE_PAR: ')';
DOT:      '.';
ID:        [a-zA-Z] [a-zA-Z0-9_]*;
WS:        [ \n\r\t] -> channel(HIDDEN);

Result:

This is example1.
States processed: 17


Collected rules:

functionRef, path:  expression 


Collected tokens:




CandidatesCollection {
  tokens: Map(0) {},
  rules: Map(1) { 2 => { startTokenIndex: 0, ruleList: [Array] } }
}

Example2

Expr.g4

grammar Expr;

expression:
    variableRef
    | functionRef
;

variableRef: identifier DOT identifier;

functionRef: identifier dotIdentifier OPEN_PAR CLOSE_PAR;

identifier: ID;

dotIdentifier: DOT identifier;

OPEN_PAR:  '(';
CLOSE_PAR: ')';
DOT:      '.';
ID:        [a-zA-Z] [a-zA-Z0-9_]*;
WS:        [ \n\r\t] -> channel(HIDDEN);

Result:

This is example2.
States processed: 18


Collected rules:

functionRef, path:  expression 
variableRef, path:  expression 


Collected tokens:




CandidatesCollection {
  tokens: Map(0) {},
  rules: Map(2) {
    2 => { startTokenIndex: 0, ruleList: [Array] },
    1 => { startTokenIndex: 0, ruleList: [Array] }
  }
}

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants