chevrotain
chevrotain copied to clipboard
Support Lazy/Defered references in createToken function
See: https://github.com/matthew-dean/less.js/commit/ec5cf7778ae6f7def27a07ea4ca88e54ab2f41c4#r34664698
Basically this will prevent cyclic dependencies between tokens during their definition. Specifically in regards to the longer_alt and the categories properties of the createToken options.
const For = createToken({
name: "For",
pattern: /for/,
// Reference via textual name, can be resolved later and be defined before **or** after
// The Identifier Token
longer_alt: "Identifier"
})
const Identifier = createToken({ name: "Identifier", pattern: /[a-zA-z]\w+/ })
const While = createToken({
name: "While",
pattern: /while/,
// Reference via variable, so Identifier must be defined before the Identifier token.
longer_alt: Identifier
})
This would be "nice to have" but not worth the complexity...