-
Notifications
You must be signed in to change notification settings - Fork 68
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
Keywords match if they are prefixes of terminals using unicode flag #1732
Comments
Hm, that one is pretty annoying. For our tokenizer, we need to explicitly supply the
Computing that property can be done for RegExp (and we do it) however, adding the Fixing this in your own language is just a small matter of overriding the |
Thank you for the help! For anyone else encountering this issue in the meantime, I solved it by following the idea and ended up with a new import { TokenType } from "chevrotain";
import { DefaultTokenBuilder } from "langium";
interface Keyword {
value: string;
}
export class TokenBuilder extends DefaultTokenBuilder {
override findLongerAlt(keyword: Keyword, terminalTokens: TokenType[]): TokenType[] {
const result = super.findLongerAlt(keyword as any, terminalTokens);
if (terminalTokens && keyword.value.match(/[A-Za-z]+/)) {
const idToken = terminalTokens.find(it => it.name == "ID");
if (!idToken) {
throw new Error("ID token not found");
}
result.push(idToken);
}
return result;
}
} The |
@c-classen The real import type { GrammarAST } from "langium";
export class TokenBuilder extends DefaultTokenBuilder {
protected override findLongerAlt(keyword: GrammarAST.Keyword, terminalTokens: TokenType[]): TokenType[] {
// ...
}
} |
Langium version: 3.2.0
Steps To Reproduce
Use the following grammar:
and apply it to the following text:
This should show no errors. Now add a Unicode Flag ("u") behind the last slash of the
terminal ID
line. Now an error should show that complains that behind thekeyword
at the start of the text, an ID is expected, but anotherkeyword
was found.Link to code example:
https://langium.org/playground?grammar=OYJwhgthYgBAEgUwDbIPYHU0mQEwFD6IB2ALiAJ6wCyauKAXPrC7AOQDWiFA7trm1gA3MMgCuiALwBJACIBuQgAsAlrnrFYpRCAgrio2BgDKDWAHoAOgGcA1OcXbd%2Bw3LPmA2gEEAtAC0wHwAvAF17MXkgA&content=NYUwng7g9gTgJgAlJWcDKUC2I0FcBm%2BAlgB5A
The current behavior
An error is shown that complains that behind the
keyword
, an ID is expected, but anotherkeyword
was found.The expected behavior
The keyword should not be matched as it is not expected from the current rule and not isolated
The text was updated successfully, but these errors were encountered: