Ignore unreachable token error #1832
jonestristand
started this conversation in
General
Replies: 3 comments 7 replies
-
@jonestristand I don't think that you can deactivate specific lexer validations, but that shouldn't be too much of an issue in development anyway. For production use of your lexer/parser it's either way recommended to disable all validations. See this documentation page. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hello @jonestristand can you be more specific ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Sure, here you go! export function matchOnlyAtStart(regex: RegExp) {
const matcher: CustomPatternMatcherFunc = (
text,
offset,
tokens
): CustomPatternMatcherReturn | null => {
const prevToken = _.last(tokens);
if (
offset === 0 ||
prevToken?.tokenType.name === BasicTokens.NEWLINE.name
) {
regex.lastIndex = offset;
const match = regex.exec(text);
return match ? [match[0]] : null;
} else {
return null;
}
};
return matcher;
}
const ASTERISK = createToken({
name: 'ASTERISK',
pattern: '*'
});
const ASTERISK_AT_START = createToken({
name: 'ASTERISK_AT_START',
pattern: matchOnlyAtStart(/\*/y),
line_breaks: false,
start_chars_hint: ['*'],
push_mode: 'comment_mode'
});
const tokens = [
ASTERISK_AT_START,
ASTERISK
];
const lexer = new Lexer(tokens); |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a custom matcher that matches a regex pattern (e.g. "#") only if it is at the start of a line. Unfortunately I also need to match that token elsewhere (if not at start of line) and as a result get the unreachable error, since the lexer can't account for the custom logic in the matcher. Is there any way to disable this since I know that the other token will match sometimes?
Beta Was this translation helpful? Give feedback.
All reactions