File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change 1
1
{raw} = import './str'
2
2
3
3
4
- regex = fn pattern, flags:
5
- new RegExp pattern, flags
4
+ regex = fn pattern, flags='' :
5
+ new RegExp pattern, 'u${ flags}'
6
6
7
7
8
8
---
@@ -18,11 +18,15 @@ reg = rx'
18
18
```
19
19
---
20
20
rx = fn strings, ...exprs:
21
- ingorables = regex raw'(\s*#.*\n)|(\n\s*)'
21
+ # implement in loxia or larix for optimization
22
+ ingorables = regex raw'(\s+#.*\n)|(\n\s*)'
23
+ esc = regex raw`(^|[^\\])((\\{2})*)\\(?=[#'"${'`'}'])`
22
24
23
25
[...parts] = pipe strings.raw:
24
26
map part:
25
- replace_all part, ingorables, ''
27
+ pipe part:
28
+ replace_all ?, ingorables, ''
29
+ replace_all ?, esc, '$1$3'
26
30
27
31
regex raw {raw: parts}, ...exprs
28
32
Original file line number Diff line number Diff line change @@ -62,22 +62,25 @@ describe 'string templates', fn:
62
62
it 'handles multiline commented regex', fn:
63
63
expect
64
64
rx'
65
- (?<year>\d{4})- # year part of a date
65
+ (?<year>\d{4})- # year part of a date
66
66
(?<month>\d{2})- # month part of a date
67
- (?<day>\d{2}) # day part of a date
67
+ (?<day>\d{2}) # day part of a date
68
68
'
69
69
to_equal rx'(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})'
70
70
71
71
72
- it 'handles escaping comment ', fn:
72
+ it 'handles escaping', fn:
73
73
expect
74
- rx'foo\#bar'
75
- to_equal regex 'foo\\#bar'
74
+ rx'
75
+ \'\"\`
76
+ foo \# bar
77
+ \${2}
78
+ \\*
79
+ '
80
+ to_equal regex `'"\`foo # bar\\\${2}\\\\*`
76
81
77
82
78
83
it 'handles spaces', fn:
79
84
expect
80
85
rx'[ ]{3}'
81
86
to_equal regex '[ ]{3}'
82
-
83
-
You can’t perform that action at this time.
0 commit comments