Skip to content

Allow escaped hyphens in character classes ([\-]) #62

@goodmami

Description

@goodmami

As mentioned in #59 (comment), escaping a hyphen is the recommended way to get a literal - in a character class but it is not actually allowed in Pe's PEG metasyntax:

>>> pe.match(r'[a\-]', "-")
Traceback (most recent call last):
  [...]
pe._errors.ParseError:
  line 0, character 3
    [a\-]
       ^
ParseError: `[tnvfr"'\[\]\\\\]`, `[0-7]`, `x`, `u`, `U`, `U`

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  [...]
pe._errors.GrammarError: invalid grammar

This should be allowed. Furthermore, it's probably time to have separate escaping/unescaping rules for character classes and regular strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions