-
Notifications
You must be signed in to change notification settings - Fork 201
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
CST location information #932
Comments
Awesome!! I'll gladly help implement or try out this feature shortly :) |
I would think the design could be something like this: class Parser {
// ...
constructor(
tokenVocabulary: TokenVocabulary,
config: IParserConfig = DEFAULT_PARSER_CONFIG
) {
const that: MixedInParser = this as any
that.initErrorHandler(config)
that.initLexerAdapter()
that.initLooksAhead(config)
that.initRecognizerEngine(tokenVocabulary, config)
that.initRecoverable(config)
that.initTreeBuilder(config)
that.initContentAssist()
// location info trait (returns immediately if locationInfo is NONE)
that.initLocationInfoDecorator()
this.ignoredIssues = has(config, "ignoredIssues")
? config.ignoredIssues
: DEFAULT_PARSER_CONFIG.ignoredIssues
}
// ...
}
enum LocationInfo = {
NONE,
FULL
}
export interface IParserConfig {
// ...
locationInfo: LocationInfo
}
export class LocationInfoDecorator {
initLocationInfoDecorator(this: MixedInParser, config: IParserConfig) {
if (config.locationInfo === LocationInfo.NONE) return
// initialize
}
public computeLocationInfo() {
// ... smart compute
// using memoized (cached) locations to achieve linear visits O(n) and thus good performance
}
} |
I don't think we need a new trait to compute the location info. because we can access the current CstNode being build there. Note:
|
Thanks. I will have another go next week using your suggestions, unless you beat me to it. Was is your estimate on how complicated/time it would be to add this? 2-3 working days? |
I think the base logic is pretty simple, but there would be some work around |
Released in 4.7.0 |
Released in 4.7.0
See: https://sap.github.io/chevrotain/docs/guide/concrete_syntax_tree.html#cstnodes-location
A CstNode currently contains all the data needed to compute it's location information as each terminal (IToken) contains it's own location information.
However the "aggregated" information is not available on the CstNode itself.
For example if we want to know what is the startOffset of a specific CstNode we must:
Perhaps Chevrotain could provide a toggle-able feature to perform this location collection on the fly.
Elements to Consider:
The text was updated successfully, but these errors were encountered: