Skip to content

Syntax for patterns #1

@JOT85

Description

@JOT85

We should decide on the syntax for defining patterns.
It should be designed considering:

  • Readability
  • Ease to parse the rules
  • Ease to parse based of the rules
  • Efficiency of parsing from the rules

Current syntax

[ optional ]
*<pat>: repeat 0 or more times
+<pat>: repeat 1 or more times
{i,j}<pat>: repeat i to j times (inclusive)
{i,}<pat>: repeat i or more times
{,j}<pat>: repeat 0 to j times (inclusive)
(a | b | c): a or b or c
<|0-9,a-z,A-Z,-,+|>: character in the range 0-9 (inclusive), a-z (inclusive), A-Z (inclusive), character is - or character is +.
.: matches anything
a~<pat>: parse <pat>, but within the rules scope, a is a string literal pattern which matches the syntax that <pat> consumed.
a@rule: parse the given rule and make a and evaluatable which, when used with eval, gives the value from applying the rule to the syntax.
pattern: parse the named pattern pattern
?=<pat>: <pat> must match what follows, but no data is consumed (look ahead)
?!=<pat>``<pat> must not match what follows - no data is consumed (negative look ahead)
#err: if the pattern fails to match after this, the error message referenced by err should be used.

Coming soon...

  • intersperse

Possible, but probably not required

!<pat>: not <pat> (note that <pat> must have a pre-determined length)

Note that the amount white-space between syntax elements does not matter - although it cannot contain a newline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions