Skip to content
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

Token categories hide their sub-tokens in syntax diagrams #1971

Closed
lsq-ahaseeb opened this issue Jul 29, 2023 · 1 comment
Closed

Token categories hide their sub-tokens in syntax diagrams #1971

lsq-ahaseeb opened this issue Jul 29, 2023 · 1 comment
Labels

Comments

@lsq-ahaseeb
Copy link

Token categories are used to classify a bunch of tokens for ease of reference, among other things. I personally like classifying all binary operator tokens under one BinaryOp token, for instance, so that I only have to write one $.CONSUME() call in the parser as opposed to 10 alternations.

But in the generated syntax diagram the underlying tokens of a category are not shown. Instead the category token is shown as a terminal with NOT_APPLICABLE as its alt text. The expectation is that either the category is replaced with all its children as alternatives, or the category is considered a non-terminal with another railroad showing its sub-tokens, as if it were a production rule. Or some other way to show both that these sub-tokens exist and that they belong to this category.

For example, in the chevrotain playground for 'JSON Grammar and CST Output', True and False show up in the syntax diagram as they're supposed to with proper alt texts. Let's replace the tokens as such:

  const Boolean = createToken({ name: "Boolean", pattern: Lexer.NA });
  const True = createToken({ name: "True", pattern: /true/, categories: Boolean });
  const False = createToken({ name: "False", pattern: /false/, categories: Boolean });

and replace the True and False alterations in the parser with a single { ALT: () => $.CONSUME(Boolean) },. Let's add Boolean to jsonTokens as well.

As you can now see in the diagram, True and False are nowhere to be seen and Boolean, which could be just an internal implementation detail, takes their place in the diagram with an unhelpful alt text NOT_APPLICABLE.

There should be an option to allow expanding/collapsing categories or showing/not showing them as non-terminals.

@bd82 bd82 added the Diagrams label Aug 10, 2023
@bd82
Copy link
Member

bd82 commented Aug 10, 2023

Hello @lsq-ahaseeb

This is a known issue: #1137 which is up for grabs.
Lets continue the discussion there if you are interested in contributing a improvement to the diagrams rendering.

closing as duplicate

@bd82 bd82 closed this as completed Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants