Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bracket expressions #12

Merged
merged 2 commits into from
Jan 10, 2019
Merged

Add support for bracket expressions #12

merged 2 commits into from
Jan 10, 2019

Conversation

yallop
Copy link
Owner

@yallop yallop commented Jan 10, 2019

This PR adds basic support for POSIX bracket expressions such as:

  • [a-zA-Z0-9]
  • [^\n\r\t]
  • [aceghi-z]

Both parsing (parsing a bracket expression as part of a regular expression) and unparsing (turning a set of char into a bracket expression are supported. Both directions involve some care to correctly handle characters that have special meaning either in regular expressions (e.g. ., |, *) or in bracket expressions (], ^, -). For example,

  • ^ has a special meaning (complement) at the beginning of a bracket expression, but not elsewhere
  • - has a special meaning (range) except at the beginning or end of a bracket expression
  • ] has a special meaning (terminate the bracket expression) except at the beginning of a bracket expression (i.e. after the opening [ or [^)

Unparsing prefers shorter output expressions: for example, for the set of all characters except e unparsing returns [^e], not [\000-df-\255].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant