wikipeg 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/lib/compiler/language/javascript.js +1 -1
- package/lib/peg.js +1 -1
- package/package.json +2 -2
- package/src/DefaultTracer.php +18 -18
- package/src/PEGParserBase.php +28 -39
- package/src/SyntaxError.php +4 -4
- package/src/Tracer.php +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
1
|
+
4.0.2
|
|
@@ -225,7 +225,7 @@ let javascript = {
|
|
|
225
225
|
if (opts.params.length) {
|
|
226
226
|
keyParts = keyParts.concat(opts.params);
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
let storeRefs = opts.storeRefs.filter(function(part) {
|
|
229
229
|
return part !== '';
|
|
230
230
|
}).map(function(part) {
|
|
231
231
|
return ' ' + part;
|
package/lib/peg.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikipeg",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Parser generator for JavaScript and PHP",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://gerrit.wikimedia.org/r/plugins/gitiles/wikipeg/",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"url": "https://gerrit.wikimedia.org/r/wikipeg"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"eslint": "8.
|
|
43
|
+
"eslint": "8.31.0",
|
|
44
44
|
"jasmine-node": "3.0.0"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
package/src/DefaultTracer.php
CHANGED
|
@@ -5,31 +5,31 @@ namespace Wikimedia\WikiPEG;
|
|
|
5
5
|
use InvalidArgumentException;
|
|
6
6
|
|
|
7
7
|
class DefaultTracer implements Tracer {
|
|
8
|
-
|
|
8
|
+
private $indentLevel = 0;
|
|
9
9
|
|
|
10
|
-
public function trace(
|
|
10
|
+
public function trace( $event ) {
|
|
11
11
|
switch ( $event['type'] ) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
case 'rule.enter':
|
|
13
|
+
$this->log( $event );
|
|
14
|
+
$this->indentLevel++;
|
|
15
|
+
break;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
case 'rule.match':
|
|
18
|
+
$this->indentLevel--;
|
|
19
|
+
$this->log( $event );
|
|
20
|
+
break;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
case 'rule.fail':
|
|
23
|
+
$this->indentLevel--;
|
|
24
|
+
$this->log( $event );
|
|
25
|
+
break;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
default:
|
|
28
|
+
throw new InvalidArgumentException( "Invalid event type {$event['type']}" );
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
private function log( $event ) {
|
|
33
33
|
print str_pad(
|
|
34
34
|
'' . $event['location'],
|
|
35
35
|
20
|
|
@@ -40,7 +40,7 @@ class DefaultTracer implements Tracer {
|
|
|
40
40
|
. "\n";
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
private function formatArgs( $argMap ) {
|
|
44
44
|
if ( !$argMap ) {
|
|
45
45
|
return '';
|
|
46
46
|
}
|
package/src/PEGParserBase.php
CHANGED
|
@@ -2,31 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
namespace Wikimedia\WikiPEG;
|
|
4
4
|
|
|
5
|
-
use stdClass;
|
|
6
|
-
|
|
7
5
|
abstract class PEGParserBase {
|
|
8
|
-
protected static
|
|
9
|
-
protected static
|
|
10
|
-
protected
|
|
11
|
-
protected
|
|
12
|
-
protected
|
|
13
|
-
protected
|
|
14
|
-
protected
|
|
15
|
-
/** @var array */
|
|
6
|
+
protected static $FAILED;
|
|
7
|
+
protected static $UNDEFINED;
|
|
8
|
+
protected $currPos;
|
|
9
|
+
protected $savedPos;
|
|
10
|
+
protected $input;
|
|
11
|
+
protected $inputLength;
|
|
12
|
+
protected $options;
|
|
16
13
|
protected $cache;
|
|
17
14
|
|
|
18
15
|
/** @var array<int,array{line:int,column:int,seenCR:bool}> */
|
|
19
|
-
protected
|
|
20
|
-
protected
|
|
21
|
-
protected
|
|
16
|
+
protected $posDetailsCache;
|
|
17
|
+
protected $maxFailPos;
|
|
18
|
+
protected $maxFailExpected;
|
|
22
19
|
|
|
23
20
|
/** @var array Associative arrays of expectation info */
|
|
24
21
|
protected $expectations;
|
|
25
22
|
|
|
26
23
|
/** @var Expectation[] */
|
|
27
|
-
private
|
|
24
|
+
private $expectationCache;
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
/** @var Tracer */
|
|
27
|
+
protected $tracer;
|
|
30
28
|
|
|
31
29
|
public function __construct() {
|
|
32
30
|
if ( !self::$FAILED ) {
|
|
@@ -37,8 +35,7 @@ abstract class PEGParserBase {
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
protected function traceCall( callable $parseFunc, string $name, array $argNames, array $args ) {
|
|
38
|
+
protected function traceCall( $parseFunc, $name, $argNames, $args ) {
|
|
42
39
|
$argMap = [];
|
|
43
40
|
foreach ( $args as $i => $argValue ) {
|
|
44
41
|
$argMap[$argNames[$i]] = $argValue;
|
|
@@ -50,7 +47,7 @@ abstract class PEGParserBase {
|
|
|
50
47
|
'location' => $this->computeLocation( $startPos, $startPos ),
|
|
51
48
|
'args' => $argMap
|
|
52
49
|
] );
|
|
53
|
-
$result = $parseFunc
|
|
50
|
+
$result = call_user_func_array( $parseFunc, $args );
|
|
54
51
|
if ( $result !== self::$FAILED ) {
|
|
55
52
|
$this->tracer->trace( [
|
|
56
53
|
'type' => 'rule.match',
|
|
@@ -68,11 +65,11 @@ abstract class PEGParserBase {
|
|
|
68
65
|
return $result;
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
protected function text()
|
|
68
|
+
protected function text() {
|
|
72
69
|
return substr( $this->input, $this->savedPos, $this->currPos - $this->savedPos );
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
protected function location()
|
|
72
|
+
protected function location() {
|
|
76
73
|
return $this->computeLocation( $this->savedPos, $this->currPos );
|
|
77
74
|
}
|
|
78
75
|
|
|
@@ -102,7 +99,7 @@ abstract class PEGParserBase {
|
|
|
102
99
|
);
|
|
103
100
|
}
|
|
104
101
|
|
|
105
|
-
public static function charAt(
|
|
102
|
+
public static function charAt( $s, $byteOffset ) {
|
|
106
103
|
if ( !isset( $s[$byteOffset] ) ) {
|
|
107
104
|
return '';
|
|
108
105
|
}
|
|
@@ -120,7 +117,7 @@ abstract class PEGParserBase {
|
|
|
120
117
|
return $char;
|
|
121
118
|
}
|
|
122
119
|
|
|
123
|
-
public static function charsAt(
|
|
120
|
+
public static function charsAt( $s, $byteOffset, $numChars ) {
|
|
124
121
|
$ret = '';
|
|
125
122
|
for ( $i = 0; $i < $numChars; $i++ ) {
|
|
126
123
|
$ret .= self::consumeChar( $s, $byteOffset );
|
|
@@ -128,7 +125,7 @@ abstract class PEGParserBase {
|
|
|
128
125
|
return $ret;
|
|
129
126
|
}
|
|
130
127
|
|
|
131
|
-
public static function consumeChar(
|
|
128
|
+
public static function consumeChar( $s, &$byteOffset ) {
|
|
132
129
|
if ( !isset( $s[$byteOffset] ) ) {
|
|
133
130
|
return '';
|
|
134
131
|
}
|
|
@@ -146,10 +143,6 @@ abstract class PEGParserBase {
|
|
|
146
143
|
return $char;
|
|
147
144
|
}
|
|
148
145
|
|
|
149
|
-
/**
|
|
150
|
-
* @param mixed $value
|
|
151
|
-
* @return mixed
|
|
152
|
-
*/
|
|
153
146
|
public static function &newRef( $value ) {
|
|
154
147
|
return $value;
|
|
155
148
|
}
|
|
@@ -172,8 +165,7 @@ abstract class PEGParserBase {
|
|
|
172
165
|
while ( $p < $pos ) {
|
|
173
166
|
$ch = self::charAt( $this->input, $p );
|
|
174
167
|
if ( $ch === "\n" ) {
|
|
175
|
-
if ( !$details['seenCR'] ) {
|
|
176
|
-
$details['line']++;
|
|
168
|
+
if ( !$details['seenCR'] ) { $details['line']++;
|
|
177
169
|
}
|
|
178
170
|
$details['column'] = 1;
|
|
179
171
|
$details['seenCR'] = false;
|
|
@@ -193,7 +185,7 @@ abstract class PEGParserBase {
|
|
|
193
185
|
return $details;
|
|
194
186
|
}
|
|
195
187
|
|
|
196
|
-
protected function computeLocation(
|
|
188
|
+
protected function computeLocation( $startPos, $endPos ) {
|
|
197
189
|
if ( $endPos > $this->inputLength ) {
|
|
198
190
|
$endPos--;
|
|
199
191
|
}
|
|
@@ -210,7 +202,7 @@ abstract class PEGParserBase {
|
|
|
210
202
|
);
|
|
211
203
|
}
|
|
212
204
|
|
|
213
|
-
protected function fail(
|
|
205
|
+
protected function fail( $expected ) {
|
|
214
206
|
if ( $this->currPos < $this->maxFailPos ) {
|
|
215
207
|
return;
|
|
216
208
|
}
|
|
@@ -242,7 +234,7 @@ abstract class PEGParserBase {
|
|
|
242
234
|
return $expanded;
|
|
243
235
|
}
|
|
244
236
|
|
|
245
|
-
private function buildMessage(
|
|
237
|
+
private function buildMessage( $expected, $found ) {
|
|
246
238
|
$expectedDescs = [];
|
|
247
239
|
|
|
248
240
|
foreach ( $expected as $info ) {
|
|
@@ -259,9 +251,7 @@ abstract class PEGParserBase {
|
|
|
259
251
|
return "Expected " . $expectedDesc . " but " . $foundDesc . " found.";
|
|
260
252
|
}
|
|
261
253
|
|
|
262
|
-
protected function buildException(
|
|
263
|
-
?string $message, ?array $expected, ?string $found, LocationRange $location
|
|
264
|
-
): SyntaxError {
|
|
254
|
+
protected function buildException( $message, $expected, $found, $location ) {
|
|
265
255
|
if ( $expected !== null ) {
|
|
266
256
|
sort( $expected );
|
|
267
257
|
$expected = array_unique( $expected );
|
|
@@ -281,7 +271,7 @@ abstract class PEGParserBase {
|
|
|
281
271
|
);
|
|
282
272
|
}
|
|
283
273
|
|
|
284
|
-
protected function buildParseException()
|
|
274
|
+
protected function buildParseException() {
|
|
285
275
|
$char = self::charAt( $this->input, $this->maxFailPos );
|
|
286
276
|
return $this->buildException(
|
|
287
277
|
null,
|
|
@@ -294,7 +284,7 @@ abstract class PEGParserBase {
|
|
|
294
284
|
protected function initialize() {
|
|
295
285
|
}
|
|
296
286
|
|
|
297
|
-
protected function initInternal(
|
|
287
|
+
protected function initInternal( $input, $options ) {
|
|
298
288
|
$this->currPos = 0;
|
|
299
289
|
$this->savedPos = 0;
|
|
300
290
|
$this->input = $input;
|
|
@@ -309,6 +299,5 @@ abstract class PEGParserBase {
|
|
|
309
299
|
$this->initialize();
|
|
310
300
|
}
|
|
311
301
|
|
|
312
|
-
|
|
313
|
-
abstract public function parse( string $input, array $options = [] );
|
|
302
|
+
abstract public function parse( $input, $options = [] );
|
|
314
303
|
}
|
package/src/SyntaxError.php
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
namespace Wikimedia\WikiPEG;
|
|
4
4
|
|
|
5
5
|
class SyntaxError extends \Exception implements \JsonSerializable {
|
|
6
|
-
public
|
|
7
|
-
public
|
|
8
|
-
public
|
|
6
|
+
public $expected;
|
|
7
|
+
public $found;
|
|
8
|
+
public $location;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @param string $message
|
|
@@ -13,7 +13,7 @@ class SyntaxError extends \Exception implements \JsonSerializable {
|
|
|
13
13
|
* @param string|null $found
|
|
14
14
|
* @param LocationRange $location
|
|
15
15
|
*/
|
|
16
|
-
public function __construct( string $message, array $expected,
|
|
16
|
+
public function __construct( string $message, array $expected, $found, LocationRange $location ) {
|
|
17
17
|
parent::__construct( $message );
|
|
18
18
|
$this->expected = $expected;
|
|
19
19
|
$this->found = $found;
|
package/src/Tracer.php
CHANGED