Skip to content

[Feature request] Additional parsing functions for the 'yue'-module #196

@SkyyySi

Description

@SkyyySi

It would be nice to have the following functions be added to the yue module:

  • yue.to_tokens(code: string): string[]: Turns a chunk of YueScript code into a list of tokens, so local even_nums = [i for 1, 10 when (i % 2) == 0] would become something like [ "local", " ", "even_nums", " ", "=", " ", "[", "i", " ", "for", " ", "i", " ", "=", " ", "1", ",", " ", "10", " ", "when", " ", "(", "i", " ", "%", " ", "2", ")", " ", "==", " ", "0", "]" ]. This would be particularly useful for macros because the input might not make sense when parsed into a YueScript AST.
  • yue.to_cst(code: string): yue.CstNode: A CST (concrete syntax tree) is similar to an AST, but unlike an AST, it contains all information required to reconstruct the exact source code that it was generated from. An AST would discard information like whitespace and comments, while a CST would keep them. A CST should also ideally be a strict superset of an AST, so that a node visitor for an AST can also operate on the same node when used with a CST.

As a side note: It may be worth considering replacing the current macro semantics with something more like Rust's approach of taking a single list of tokens and returning a list of tokens, instead of working with source code. Doing it this way is easier to use as well as more reliable than trying to monkey-patch some strings with Lua patterns / regular expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions