You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-12Lines changed: 37 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,39 @@
1
-
# as-regex
1
+
# assemblyscript-regex
2
2
3
-
A regex engine built with AssemblyScript
3
+
A regex engine for AssemblyScript.
4
4
5
-
Currently AssemblyScript lacks Regex support. For a bit of fun I thought I'd try implementing a simple regex engine, based on [Denis Kyashif's blog post](https://deniskyashif.com/2019/02/17/implementing-a-regular-expression-engine/). The implementation is relatively simplistic, I've focussed on functionality rather than performance. However, it might be of use to someone.
5
+
[AssemblyScript](https://www.assemblyscript.org/) is a new language, based on TypeScript, that runs on WebAssembly. AssemblyScript has a lightweight standard library, but lacks support for Regular Expression. The project fills that gap!
6
6
7
-
## Feature support
7
+
This project exposes an API that mirrors the JavaScript [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) class:
8
8
9
-
based on the [MDN cheatsheet](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet)
9
+
~~~javascript
10
+
constregex=newRegExp("fo*", "g");
11
+
conststr="table football, foul";
10
12
11
-
### Character classes
13
+
let match: Match |null=regex.exec(str);
14
+
while (match !=null) {
15
+
// first iteration
16
+
// match.index = 6
17
+
// match.matches[0] = "foo"
18
+
19
+
// second iteration
20
+
// match.index = 16
21
+
// match.matches[0] = "fo"
22
+
match =regex.exec(str);
23
+
}
24
+
~~~
25
+
26
+
## Project status
27
+
28
+
The initial focus of this implementation has been feature support and functionality over performance. It currently supports a sufficient number of regex features to be considered useful, including most character classes, common assertions, groups, alternations, capturing groups and quantifiers.
29
+
30
+
The next phase of development will focussed on more extensive testing and performance. The project currently has reasonable unit test coverage, focussed on positive and negative test cases on a per-feature basis. It also includes a more exhaustive test suite with test cases borrowed from another regex library.
31
+
32
+
### Feature support
33
+
34
+
Based on the classfication within the [MDN cheatsheet](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet)
35
+
36
+
**Character classes**
12
37
13
38
-[x] .
14
39
-[x] \d
@@ -30,21 +55,21 @@ based on the [MDN cheatsheet](https://developer.mozilla.org/en-US/docs/Web/JavaS
30
55
-[ ] \u{hhhh} or \u{hhhhh}
31
56
-[x]\
32
57
33
-
### Assertions
58
+
**Assertions**
34
59
35
60
-[x] ^
36
61
-[x] $
37
62
-[ ] \b
38
63
-[ ] \B
39
64
40
-
### Other assertions
65
+
**Other assertions**
41
66
42
67
-[ ] x(?=y) Lookahead assertion
43
68
-[ ] x(?!y) Negative lookahead assertion
44
69
-[ ] (?<=y)x Lookbehind assertion
45
70
-[ ] (?<!y)x Negative lookbehind assertion
46
71
47
-
### Groups and ranges
72
+
**Groups and ranges**
48
73
49
74
-[x] x|y
50
75
-[x][xyz][a-c]
@@ -54,7 +79,7 @@ based on the [MDN cheatsheet](https://developer.mozilla.org/en-US/docs/Web/JavaS
54
79
-[ ] (?<Name>x) named capturing group
55
80
-[ ] (?:x) Non-capturing group
56
81
57
-
### Quantifiers
82
+
**Quantifiers**
58
83
59
84
-[x] x*
60
85
-[x] x+
@@ -64,13 +89,13 @@ based on the [MDN cheatsheet](https://developer.mozilla.org/en-US/docs/Web/JavaS
64
89
-[x] x{n,m}
65
90
-[ ] x*? / x+? / ...
66
91
67
-
### RegExp
92
+
**RegExp**
68
93
69
94
-[x] global
70
95
-[ ] case insensitive
71
96
-[ ] multiline
72
97
73
-
## Testing
98
+
###Testing
74
99
75
100
Currently passes 181 of the 217 tests from the Rust regex test suite:
0 commit comments