Skip to content

Commit a78e829

Browse files
fix: support forward slash in regexp character classes and single-character escapes (#149)
Co-authored-by: Michael Ficarra <[email protected]>
1 parent 6c4f103 commit a78e829

File tree

4 files changed

+391
-115
lines changed

4 files changed

+391
-115
lines changed

grammar.pegjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ attr
9797
path = i:identifierName { return { type: 'literal', value: i }; }
9898
type = "type(" _ t:[^ )]+ _ ")" { return { type: 'type', value: t.join('') }; }
9999
flags = [imsu]+
100-
regex = "/" d:[^/]+ "/" flgs:flags? { return {
101-
type: 'regexp', value: new RegExp(d.join(''), flgs ? flgs.join('') : '') };
100+
regex = "/" pattern:(re_character_class / re_escape / re_chars)+ "/" flgs:flags? {
101+
return {
102+
type: 'regexp', value: new RegExp(pattern.join(''), flgs ? flgs.join('') : '')
103+
};
102104
}
105+
re_character_class = "[" cs:([^\]\\] / re_escape)+ "]" { return '[' + cs.join('') + ']'; }
106+
re_escape = "\\" a:. { return '\\' + a; }
107+
re_chars = cs:[^/\\[]+ { return cs.join(''); }
103108

104109
field = "." i:identifierName is:("." identifierName)* {
105110
return { type: 'field', name: is.reduce(function(memo, p){ return memo + p[0] + p[1]; }, i)};

0 commit comments

Comments
 (0)