goodmami / goodmami/pe

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

Open
#62 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
51
Forks
4
PR merge metrics
No merged PRs in 30d

Description

As mentioned in https://github.com/goodmami/pe/issues/59#issuecomment-3186903306, 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:

```pycon
>>> 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.