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
+25-34
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,12 @@
6
6
7
7
# TypeScript Runtime for ANTLR 4
8
8
9
-
This package is a fork of the official ANTLR4 JavaScript runtime and has been fully transformed to TypeScript. Other improvements are:
9
+
This package started as a fork of the official ANTLR4 JavaScript runtime and has been fully implemented in TypeScript. It implements everything what the Java runtime does, except for the `UnbufferedCharStream` class, which requires a streaming source compatible with both Node.js and browsers. Other notable differences from the original JS source.
10
10
11
-
- XPath implementation.
12
-
- Vocabulary implementation.
13
-
- Complete Interval implementation.
14
-
- Parser and lexer interpreters.
15
-
- Profiler implementation.
16
11
- Numerous bug fixes and other changes.
17
-
- Smaller node package (no test specs or other unnecessary files).
18
12
- No differentiation between node and browser environments.
19
-
- InterpreterDataReader implementation.
20
13
- Includes the `antlr4ng-cli` tool to generate parser files compatible with this runtime. This tool uses a custom build of the ANTLR4 tool.
21
14
22
-
This package is a blend of the original JS implementation and antlr4ts, which is a TypeScript implementation of the ANTLR4 runtime, but was abandoned. It tries to keep the best of both worlds, while following the Java runtime as close as possible. It's a bit slower than the JS runtime, but faster than antlr4ts.
23
-
24
15
## Installation
25
16
26
17
To install the package, run the following command:
@@ -128,7 +119,7 @@ npm run generate-runtime-tests
128
119
and the build of the package:
129
120
130
121
```bash
131
-
npm run build-minified
122
+
npm run build
132
123
```
133
124
134
125
After that you can either execute different suites separately or as a whole.
@@ -140,35 +131,33 @@ After that you can either execute different suites separately or as a whole.
140
131
|Real world example|`npm run run-benchmarks`|
141
132
| All together|`npm run full-test`|
142
133
143
-
The unit tests consist of tests for individual classes in the runtime (API tests) and the runtime test suite ported from Java. They execute in about 10s.
144
-
145
-
### Real World Example
134
+
The unit tests consist of tests for individual classes in the runtime (API tests) and the runtime test suite ported from Java.
146
135
147
-
The following tables show the results of the benchmarks previously run on the JS runtime and on last release of this one. Warm times were taken from 5 runs with the 2 slowest stripped off and averaged.
136
+
This suite consists of 530 tests and runs in about 9s.
148
137
149
-
Pure JavaScript release (with type definitions):
138
+
### Real World Example
150
139
151
-
| Test | Cold Run | Warm Run|
152
-
| ---- | -------- | ------- |
153
-
| Query Collection| 8464 ms | 230 ms |
154
-
| Example File | 1043 ms | 112 ms |
155
-
| Large Inserts | 11022 ms | 10616 ms |
156
-
| Total | 20599 ms | 10978 ms |
140
+
The following table shows the results of the benchmarks that were executed in the [antlr4wasm project](https://github.com/mike-lischke/antlr4wasm/tree/master/benchmarks/mysql). The column for antlr4ng, howevever, contains the current results of this runtime.
Underlined entries are the smallest (not counting C++, which beats them all). For antlr4ng, the times are split into lexing and parsing. Note the high lexer execution times, caused by the large number of predicates (126) + lexer actions (40) in the MySQL lexer.
166
155
167
-
The benchmarks consist of a set of query files, which are parsed by a MySQL parser. The MySQL grammar is one of the largest and most complex grammars you can find for ANTLR4, which, I think, makes it a perfect test case for parser tests.
156
+
The benchmarks consist of a set of query filesparsed by a MySQL parser. The MySQL grammar is one of the largest and most complex grammars you can find for ANTLR4, which I think makes it a perfect test case for parser testing.
168
157
169
-
The query collection file contains more than 900 MySQL queries of all kinds, from very simple comments-only statements to complex stored procedures, including some deeply nested select queries that can easily exhaust the available stack space (in certain situations, such as parsing in a thread with default stack size). The minimum MySQL server version used was 8.0.0.
158
+
The query collection file contains more than 900 MySQL queries of all kinds, from very simple comments-only statements to complex stored procedures, including some deeply nested select queries that can easily exhaust the available stack space (in certain situations, such as parsing in a thread with default stack size). The MySQL server version used was 8.2 (the grammar allows dynamic switching of server versions).
170
159
171
-
The large binary inserts file contains only a few dozen queries, but they are really large with deep recursions, so they stress the prediction engine of the parser. In addition, one query contains binary (image) data containing input characters from the entire UTF-8 range.
160
+
The large binary inserts file contains only a few dozen queries, but they are really large with deep recursions, so they stress the parser's prediction engine and often touch uncached DFA states because of the lexer predicates. In addition, one query contains binary (image) data with input characters from the entire UTF-8 range.
172
161
173
162
The example file is a copy of the largest test file in [this repository](https://github.com/antlr/grammars-v4/tree/master/sql/mysql/Positive-Technologies/examples), and is known to be very slow to parse with other MySQL grammars. The one used here, however, is fast.
174
163
@@ -212,6 +201,8 @@ The execute times on last release of this runtime have been measured as:
212
201
lexNewGraphemeUTF8 average time 387µs over 400 runs of 85 symbols from emoji.txt DFA cleared
213
202
```
214
203
204
+
Note: Some of the corpus sizes differ due to the restructuring of the test. However, the numbers are not directly comparable anyway, as they were taken on different machines.
0 commit comments