Skip to content

Pattern for mode in multimode lexer #1999

Closed

Description

@dhowe

I'm sure this is quite simple, but I have a mode that should start with @{ and end with }@, and should accept anything else inside including }. My tokens are as below. How would I define the pattern for my Gate token ?

 const EnterGate = createToken({
    name: "EnterGate",
    pattern: /@{/
    push_mode: "gate_mode"
  });

  const ExitGate = createToken({
    name: "ExitGate",
    pattern: /}@/
    pop_mode: true
  });

  const Gate = createToken({
    name: "Gate",
    pattern: ??
  });

Activity

  1. msujew commented on Nov 16, 2023

    @msujew
    Collaborator

    You can probably use something like (?:(?!}@).)*. It uses a negative lookahead group (?!) to prevent matching }@ and then attempts to match any character .. This is repeating until it arrives at the end of the input or the }@ sequence.

  2. locked and limited conversation to collaborators on Nov 16, 2023
  3. converted this issue into a discussion #2000 on Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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