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

Attributes #7

Open
mik-jozef opened this issue Nov 26, 2023 · 0 comments
Open

Attributes #7

mik-jozef opened this issue Nov 26, 2023 · 0 comments
Labels
feature request New feature or request

Comments

@mik-jozef
Copy link
Owner

Attributes restrict the possible values a syntax tree node can have in given properties.

class LetDeclaration extends SyntaxTreeNode {
  static pattern = new Caten(
    new Maybe(
      new Equals('topLevel', true),
      'export',
    ),
    'let',
    'identifier',
    '=',
    '...',
  );
}

// Allows matching "export let foo = ..."
Match('variable', LetDeclaration, { topLevel: true })

// Does not match "export let foo = ..."
Match('variable', LetDeclaration, { topLevel: false })

// Grammar conflict between reducing with `topLevel: false` and `topLevel: true`.
Match('variable', LetDeclaration)

Attributes can be nested and can restrict nested syntax tree nodes.

Match('prop', Symbol, { variable: { topLevel: true } })
@mik-jozef mik-jozef added the feature request New feature or request label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant