Skip to content

Attributes #7

@mik-jozef

Description

@mik-jozef

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions