-
Notifications
You must be signed in to change notification settings - Fork 207
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
Nested tokens #1268
Comments
Hello @JanBaklan I only partially understand the question. But I am not sure, if the link above does not help, please create a small reproducible example I can execute to understand the issue. |
@bd82 Thanks for your answer! |
O.k. firstly please in the future provide simpler reproduction repo, e.g the React parts are irrelevant... const { createToken, EmbeddedActionsParser, Lexer } = require( "chevrotain");
const CONTEXT = createToken({ name: "Context", pattern: Lexer.NA, label: "Context" })
const ATTRIBUTE = createToken({
name: "Attribute",
pattern: /hostname|os|os_family/
})
const WhiteSpace = createToken({
name: "WhiteSpace",
pattern: /\s+/,
group: Lexer.SKIPPED
})
const Comma = createToken({
name: "Comma",
pattern: /,/
})
const LeftPar = createToken({
name: "LeftPar",
pattern: /\(/
})
const RightPar = createToken({
name: "RightPar",
pattern: /\)/
})
// CONTEXT
const Consumer = createToken({
name: "Consumer",
pattern: /consumer/,
categories: CONTEXT
})
const Remote = createToken({
name: "Remote",
pattern: /remote/,
categories: CONTEXT
})
const allTokens = [
WhiteSpace,
Comma, LeftPar, RightPar,
CONTEXT,
Consumer, Remote,
ATTRIBUTE
]
class AutocalcParser extends EmbeddedActionsParser {
constructor() {
super(allTokens)
this.RULE("startRule", () => {
this.SUBRULE(this.atomRule)
})
this.RULE("atomRule", () => {
this.CONSUME(CONTEXT)
this.CONSUME(LeftPar)
this.CONSUME(ATTRIBUTE)
this.CONSUME(RightPar)
})
this.performSelfAnalysis()
}
}
const AutocalcLexer = new Lexer(allTokens);
const lexingResult = AutocalcLexer.tokenize("consumer(hostn")
console.log(lexingResult.tokens) Your issue is that the lexer automatically attempts to perform error recovery by dropping characters until it can recognize a new This feature is unfortunately not currently configurable. You seem to be implementing some kind of content assist logic. Which makes tends to make things more complex. Possible WorkaroundYou may be able to workaround the issue by only sending a subset of the tokens to your auto-complete request, Possible Workaround 2You may be able to define an "UnknownKeyword" token General Notes
Cheers. |
Hello! I have a little problem. And I cannot find any answer.
There is one of my tokens that can get a multiple values
const ATTRIBUTE = createToken( {name: 'Attribute', pattern: /hostname|os/, label: 'Attribute' } );
And when I try to parse something like this:
consumer(hostn
I expected to get only 2 tokens - consumer and ( but in reality I get 3 tokens: consumer , ( and os
I tried to change my ATTRIBUTE pattern to
/hostname|(?<!.)os(?!.)/
but have an error Error: Unable to use "first char" lexer optimizations:How can I get only 2 tokens from this string?
The text was updated successfully, but these errors were encountered: