Skip to content

Commit

Permalink
Merge pull request #10 from SWAT-engineering/merge-char-ranges
Browse files Browse the repository at this point in the history
Keep single char-classes single char-classes in regex
  • Loading branch information
sungshik authored Aug 20, 2024
2 parents 36975db + cd2997b commit cd31e74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ RegExp toRegExp(Grammar _, \lit(string))
= regExp("(?:<encode(chars(string), withBounds = /^\w+$/ := string)>)", []);
RegExp toRegExp(Grammar _, \cilit(string))
= regExp("(?i:<encode(chars(string), withBounds = /^\w+$/ := string)>)", []);
RegExp toRegExp(Grammar g, \char-class(ranges))
= infix("|", toRegExps(g, ranges));
// `ParseTree`: Regular expressions
RegExp toRegExp(Grammar _, \empty())
Expand Down Expand Up @@ -158,10 +156,11 @@ default RegExp toRegExp(Grammar _, Condition c) {
Converts a character range to a regular expression.
}
RegExp toRegExp(Grammar _, range(char, char))
= regExp("<encode(char)>", []);
default RegExp toRegExp(Grammar _, range(begin, end))
= regExp("[<encode(begin)>-<encode(end)>]", []);
RegExp toRegExp(Grammar _, \char-class([range(int char, char)])) = regExp(encode(char), []);
RegExp toRegExp(Grammar _, \char-class(ranges))
= regExp("[<("" | it + ((begin == end) ? encode(begin) : "<encode(begin)>-<encode(end)>") | range(int begin, int end) <- ranges)>]", [])
;
@synopsis{
Encodes a (list of) char(s) to a (list of) code unit(s).
Expand Down
Loading

0 comments on commit cd31e74

Please sign in to comment.