Skip to content

Precedence When Matching/Lexing #50

@cgbsu

Description

@cgbsu

Possible to use precedence in pattern matching step?

I have 3 terms on for digits ("[0-9]+"), "u" and one for identifiers "[a-zA-Z_][a-zA-Z_0-9]+"

I "u" to identify an unsigned integer and I can specify its bit arity with a number after it

e.g "100u8" is an an unsigned 8-bit integer with value 100.

100u works fine (unsigned integer with value 100 and unspecified bit-arity)

However 100 is pared as "Digits" <- "Base10Digits", (I do this because I can parse digits in different bases) then "u8" is parsed as an identifier, and there is no rule to match this.

Right now "u" has a higher precedence than "Identifier" but identifier gets matched first.

Would it be possible to:
A ) Try matching patterns with higher precedence first
B ) If there is no suitable rule for the matched term, fallback and see if there is a suitable term (case: Unexpected Identifier)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions