chevrotain icon indicating copy to clipboard operation
chevrotain copied to clipboard

Support Lazy/Defered references in createToken function

Open bd82 opened this issue 4 years ago • 1 comments

See: https://github.com/matthew-dean/less.js/commit/ec5cf7778ae6f7def27a07ea4ca88e54ab2f41c4#r34664698

bd82 avatar Aug 12 '19 22:08 bd82

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
})


bd82 avatar Aug 14 '19 15:08 bd82

This would be "nice to have" but not worth the complexity...

bd82 avatar Jul 08 '23 20:07 bd82