@zigsterz/parzing 1.0.0 → 1.2.0
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/README.md +24 -18
- package/dist/builder.d.ts +5 -3
- package/dist/builder.js +48 -60
- package/dist/combinators/AstBuilder.js +8 -19
- package/dist/combinators/AttemptParser.js +6 -7
- package/dist/combinators/ChooseCombinator.d.ts +1 -1
- package/dist/combinators/ChooseCombinator.js +10 -11
- package/dist/combinators/ManyCombinator.d.ts +2 -2
- package/dist/combinators/ManyCombinator.js +21 -42
- package/dist/combinators/MapParser.js +7 -8
- package/dist/combinators/OptionalCombinator.js +10 -11
- package/dist/combinators/ParserWithIndices.d.ts +1 -1
- package/dist/combinators/ParserWithIndices.js +9 -10
- package/dist/combinators/SequenceCombinator.d.ts +2 -2
- package/dist/combinators/SequenceCombinator.js +12 -30
- package/dist/core.d.ts +11 -7
- package/dist/core.js +96 -99
- package/dist/operators.js +12 -12
- package/dist/parsers/AnyOfParser.js +18 -20
- package/dist/parsers/RegexParser.d.ts +7 -0
- package/dist/parsers/RegexParser.js +21 -0
- package/dist/parsers/TokenParser.js +12 -10
- package/dist/parsers/WhitespaceParser.d.ts +2 -2
- package/dist/parsers/WhitespaceParser.js +11 -11
- package/dist/parzing.js +5 -1
- package/package.json +11 -11
|
@@ -1,39 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.SequenceCombinator = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_this._parsers = _parsers;
|
|
25
|
-
return _this;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
class SequenceCombinator extends core_1.ParserWithInternalWhitespaceSupport {
|
|
6
|
+
constructor(_parsers) {
|
|
7
|
+
super();
|
|
8
|
+
this._parsers = _parsers;
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (
|
|
10
|
+
parse(parserContext) {
|
|
11
|
+
const results = [];
|
|
12
|
+
for (let i = 0; i < this._parsers.length; i++) {
|
|
30
13
|
if (i) {
|
|
31
|
-
|
|
14
|
+
const wsr = this.parseWhitespace(parserContext);
|
|
32
15
|
if (!wsr.successful) {
|
|
33
16
|
return wsr;
|
|
34
17
|
}
|
|
35
18
|
}
|
|
36
|
-
|
|
19
|
+
const psr = this._parsers[i].parse(parserContext);
|
|
37
20
|
if (psr.successful) {
|
|
38
21
|
if (psr.result !== undefined) {
|
|
39
22
|
results.push(psr.result);
|
|
@@ -44,7 +27,6 @@ var SequenceCombinator = /** @class */ (function (_super) {
|
|
|
44
27
|
}
|
|
45
28
|
}
|
|
46
29
|
return core_1.ParseResult.successful(results);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}(core_1.ParserWithInternalWhitespaceSupport));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
50
32
|
exports.SequenceCombinator = SequenceCombinator;
|
package/dist/core.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export interface ParserInputBookmark {
|
|
|
3
3
|
export interface ParserInput {
|
|
4
4
|
read(readLen: number): string;
|
|
5
5
|
peek(peekLen: number): string;
|
|
6
|
+
readRegex?(regex: RegExp): string | null;
|
|
7
|
+
peekRegex?(regex: RegExp): string | null;
|
|
6
8
|
getBookmark(): ParserInputBookmark;
|
|
7
|
-
seekToBookmark(bm: ParserInputBookmark):
|
|
9
|
+
seekToBookmark(bm: ParserInputBookmark): void;
|
|
8
10
|
eof(): boolean;
|
|
9
11
|
tell(): number;
|
|
10
12
|
}
|
|
@@ -14,6 +16,8 @@ export declare class StringParserInput implements ParserInput {
|
|
|
14
16
|
constructor(_text: String);
|
|
15
17
|
read(readLen: number): string;
|
|
16
18
|
peek(readLen: number): string;
|
|
19
|
+
readRegex(regex: RegExp): string | null;
|
|
20
|
+
peekRegex(regex: RegExp): string | null;
|
|
17
21
|
getBookmark(): ParserInputBookmark;
|
|
18
22
|
seekToBookmark(bm: ParserInputBookmark): void;
|
|
19
23
|
eof(): boolean;
|
|
@@ -29,7 +33,7 @@ export declare class ParserContext {
|
|
|
29
33
|
get input(): ParserInput;
|
|
30
34
|
cutEncountered: boolean;
|
|
31
35
|
}
|
|
32
|
-
export
|
|
36
|
+
export type ParseResult<T> = {
|
|
33
37
|
successful: true;
|
|
34
38
|
failed: false;
|
|
35
39
|
result: T;
|
|
@@ -48,10 +52,10 @@ export interface Parser<T> {
|
|
|
48
52
|
parse(parserContext: ParserContext): ParseResult<T>;
|
|
49
53
|
}
|
|
50
54
|
export declare function isParser(p: any): p is Parser<unknown>;
|
|
51
|
-
export declare class FailParser implements Parser<
|
|
55
|
+
export declare class FailParser implements Parser<unknown> {
|
|
52
56
|
private _message;
|
|
53
|
-
constructor(_message
|
|
54
|
-
parse(parserContext: ParserContext):
|
|
57
|
+
constructor(_message: string);
|
|
58
|
+
parse(parserContext: ParserContext): ParseResult<unknown>;
|
|
55
59
|
}
|
|
56
60
|
export declare class PassParser implements Parser<void> {
|
|
57
61
|
parse(parserContext: ParserContext): ParseResult<void>;
|
|
@@ -63,9 +67,9 @@ export declare class RefParser<T> implements Parser<T> {
|
|
|
63
67
|
private _parserProvider;
|
|
64
68
|
constructor(_parserProvider: () => Parser<T>);
|
|
65
69
|
parse(parserContext: ParserContext): ParseResult<T>;
|
|
66
|
-
private _parser
|
|
70
|
+
private _parser?;
|
|
67
71
|
}
|
|
68
|
-
export
|
|
72
|
+
export type ParserType<pt> = pt extends Parser<infer T> ? T : never;
|
|
69
73
|
export declare class ParserWithInternalWhitespaceSupport<T> implements Parser<T> {
|
|
70
74
|
parse(parserContext: ParserContext): ParseResult<T>;
|
|
71
75
|
whitespace(whitespaceParser: Parser<unknown> | null): ParserWithInternalWhitespaceSupport<T>;
|
package/dist/core.js
CHANGED
|
@@ -1,65 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParseError = exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.ParseError = exports.ParserWithInternalWhitespaceSupport = exports.RefParser = exports.CutParser = exports.PassParser = exports.FailParser = exports.ParseResult = exports.ParserContext = exports.StringParserInput = void 0;
|
|
4
|
+
exports.isParser = isParser;
|
|
5
|
+
exports.parse = parse;
|
|
6
|
+
class StringParserInput {
|
|
7
|
+
constructor(_text) {
|
|
6
8
|
this._text = _text;
|
|
7
9
|
this._index = 0;
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
read(readLen) {
|
|
10
12
|
if (this._index + readLen > this._text.length) {
|
|
11
13
|
this._index = this._text.length;
|
|
12
|
-
throw new ParseError(this, this.getBookmark(), null,
|
|
14
|
+
throw new ParseError(this, this.getBookmark(), null, `Attempt to read beyond EOF`);
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
const ret = this._text.substr(this._index, readLen);
|
|
15
17
|
this._index += readLen;
|
|
16
18
|
return ret;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
+
}
|
|
20
|
+
peek(readLen) {
|
|
19
21
|
return this._text.substr(this._index, readLen);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
+
}
|
|
23
|
+
readRegex(regex) {
|
|
24
|
+
const ret = this.peekRegex(regex);
|
|
25
|
+
if (ret) {
|
|
26
|
+
this._index += ret.length;
|
|
27
|
+
}
|
|
28
|
+
return ret;
|
|
29
|
+
}
|
|
30
|
+
peekRegex(regex) {
|
|
31
|
+
let matchResult = regex.exec(this._text.substring(this._index));
|
|
32
|
+
if (!matchResult) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (matchResult.index != 0) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return matchResult[0];
|
|
39
|
+
}
|
|
40
|
+
getBookmark() {
|
|
22
41
|
return this._index;
|
|
23
|
-
}
|
|
24
|
-
|
|
42
|
+
}
|
|
43
|
+
seekToBookmark(bm) {
|
|
25
44
|
this._index = bm;
|
|
26
|
-
}
|
|
27
|
-
|
|
45
|
+
}
|
|
46
|
+
eof() {
|
|
28
47
|
return this._index >= this._text.length;
|
|
29
|
-
}
|
|
30
|
-
|
|
48
|
+
}
|
|
49
|
+
remainder() {
|
|
31
50
|
return this._text.substr(this._index);
|
|
32
|
-
}
|
|
33
|
-
|
|
51
|
+
}
|
|
52
|
+
skip(howMuch) {
|
|
34
53
|
this._index += howMuch;
|
|
35
|
-
}
|
|
36
|
-
|
|
54
|
+
}
|
|
55
|
+
tell() {
|
|
37
56
|
return this._index;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
41
59
|
exports.StringParserInput = StringParserInput;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (_whitespaceParser === void 0) { _whitespaceParser = null; }
|
|
60
|
+
class ParserContext {
|
|
61
|
+
constructor(_input, _whitespaceParser = null) {
|
|
45
62
|
this._input = _input;
|
|
46
63
|
this._whitespaceParser = _whitespaceParser;
|
|
47
64
|
this.cutEncountered = false;
|
|
48
65
|
}
|
|
49
|
-
|
|
66
|
+
parseWhitespace() {
|
|
50
67
|
if (this._whitespaceParser) {
|
|
51
68
|
this._whitespaceParser.parse(this);
|
|
52
69
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
enumerable: false,
|
|
59
|
-
configurable: true
|
|
60
|
-
});
|
|
61
|
-
return ParserContext;
|
|
62
|
-
}());
|
|
70
|
+
}
|
|
71
|
+
get input() {
|
|
72
|
+
return this._input;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
exports.ParserContext = ParserContext;
|
|
64
76
|
var ParseResult;
|
|
65
77
|
(function (ParseResult) {
|
|
@@ -68,7 +80,7 @@ var ParseResult;
|
|
|
68
80
|
}
|
|
69
81
|
ParseResult.successful = successful;
|
|
70
82
|
function voidSuccessful() {
|
|
71
|
-
return { successful: true, failed: false, result:
|
|
83
|
+
return { successful: true, failed: false, result: void 0 };
|
|
72
84
|
}
|
|
73
85
|
ParseResult.voidSuccessful = voidSuccessful;
|
|
74
86
|
function failed(r) {
|
|
@@ -79,108 +91,93 @@ var ParseResult;
|
|
|
79
91
|
if (p.successful) {
|
|
80
92
|
return p.result;
|
|
81
93
|
}
|
|
82
|
-
else
|
|
94
|
+
else {
|
|
83
95
|
throw p.parseError;
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
98
|
ParseResult.resultOrThrow = resultOrThrow;
|
|
87
|
-
})(ParseResult
|
|
88
|
-
;
|
|
99
|
+
})(ParseResult || (exports.ParseResult = ParseResult = {}));
|
|
89
100
|
function isParser(p) {
|
|
90
|
-
return
|
|
101
|
+
return "parse" in p;
|
|
91
102
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
function FailParser(_message) {
|
|
95
|
-
if (_message === void 0) { _message = null; }
|
|
103
|
+
class FailParser {
|
|
104
|
+
constructor(_message) {
|
|
96
105
|
this._message = _message;
|
|
97
106
|
}
|
|
98
|
-
|
|
107
|
+
parse(parserContext) {
|
|
99
108
|
return ParseResult.failed(ParseError.parserRejected(this, parserContext, this._message));
|
|
100
|
-
};
|
|
101
|
-
return FailParser;
|
|
102
|
-
}());
|
|
103
|
-
exports.FailParser = FailParser;
|
|
104
|
-
var PassParser = /** @class */ (function () {
|
|
105
|
-
function PassParser() {
|
|
106
109
|
}
|
|
107
|
-
|
|
110
|
+
}
|
|
111
|
+
exports.FailParser = FailParser;
|
|
112
|
+
class PassParser {
|
|
113
|
+
parse(parserContext) {
|
|
108
114
|
return ParseResult.voidSuccessful();
|
|
109
|
-
};
|
|
110
|
-
return PassParser;
|
|
111
|
-
}());
|
|
112
|
-
exports.PassParser = PassParser;
|
|
113
|
-
var CutParser = /** @class */ (function () {
|
|
114
|
-
function CutParser() {
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
}
|
|
117
|
+
exports.PassParser = PassParser;
|
|
118
|
+
class CutParser {
|
|
119
|
+
parse(parserContext) {
|
|
117
120
|
parserContext.cutEncountered = true;
|
|
118
121
|
return ParseResult.voidSuccessful();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
}());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
122
124
|
exports.CutParser = CutParser;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
class RefParser {
|
|
126
|
+
constructor(_parserProvider) {
|
|
125
127
|
this._parserProvider = _parserProvider;
|
|
126
128
|
}
|
|
127
|
-
|
|
129
|
+
parse(parserContext) {
|
|
128
130
|
if (!this._parser) {
|
|
129
131
|
this._parser = this._parserProvider();
|
|
130
132
|
}
|
|
131
133
|
return this._parser.parse(parserContext);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}());
|
|
134
|
+
}
|
|
135
|
+
}
|
|
135
136
|
exports.RefParser = RefParser;
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
class ParserWithInternalWhitespaceSupport {
|
|
138
|
+
constructor() {
|
|
138
139
|
this._whitespace = null;
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
-
throw new Error(
|
|
142
|
-
}
|
|
143
|
-
|
|
141
|
+
parse(parserContext) {
|
|
142
|
+
throw new Error("Method not implemented");
|
|
143
|
+
}
|
|
144
|
+
whitespace(whitespaceParser) {
|
|
144
145
|
this._whitespace = whitespaceParser;
|
|
145
146
|
return this;
|
|
146
|
-
}
|
|
147
|
-
|
|
147
|
+
}
|
|
148
|
+
parseWhitespace(parserContext) {
|
|
148
149
|
if (this._whitespace) {
|
|
149
150
|
return this._whitespace.parse(parserContext);
|
|
150
151
|
}
|
|
151
152
|
else {
|
|
152
153
|
return ParseResult.voidSuccessful();
|
|
153
154
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
}());
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
157
|
exports.ParserWithInternalWhitespaceSupport = ParserWithInternalWhitespaceSupport;
|
|
158
|
-
function parse(parser, input, allowPartial) {
|
|
159
|
-
if (
|
|
160
|
-
if (typeof (input) === 'string') {
|
|
158
|
+
function parse(parser, input, allowPartial = false) {
|
|
159
|
+
if (typeof input === "string") {
|
|
161
160
|
input = new StringParserInput(input);
|
|
162
161
|
}
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
let context = new ParserContext(input);
|
|
163
|
+
const ret = parser.parse(context);
|
|
165
164
|
if (!allowPartial && !input.eof()) {
|
|
166
|
-
throw new ParseError(input, input.getBookmark(), null,
|
|
165
|
+
throw new ParseError(input, input.getBookmark(), null, `End of input expected`);
|
|
167
166
|
}
|
|
168
167
|
return ParseResult.resultOrThrow(ret);
|
|
169
168
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
function ParseError(input, bookmark, parser, contentMessage) {
|
|
169
|
+
class ParseError {
|
|
170
|
+
constructor(input, bookmark, parser, contentMessage) {
|
|
173
171
|
this.message = contentMessage;
|
|
174
172
|
if (bookmark) {
|
|
175
|
-
this.message = this.message
|
|
173
|
+
this.message = `${this.message} at ${bookmark} ('${input.peek(5)}')`;
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
|
-
|
|
179
|
-
return
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return new ParseError(context.input, context.input.getBookmark(), parser, message ||
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
}());
|
|
176
|
+
toString() {
|
|
177
|
+
return `Error: ${this.message}`;
|
|
178
|
+
}
|
|
179
|
+
static parserRejected(parser, context, message) {
|
|
180
|
+
return new ParseError(context.input, context.input.getBookmark(), parser, message || `Parser rejected input`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
186
183
|
exports.ParseError = ParseError;
|
package/dist/operators.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParserOperators = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const AstBuilder_1 = require("./combinators/AstBuilder");
|
|
5
|
+
const MapParser_1 = require("./combinators/MapParser");
|
|
6
|
+
const OptionalCombinator_1 = require("./combinators/OptionalCombinator");
|
|
7
|
+
const ParserWithIndices_1 = require("./combinators/ParserWithIndices");
|
|
8
8
|
var ParserOperators;
|
|
9
9
|
(function (ParserOperators) {
|
|
10
10
|
function map(mapper) {
|
|
11
|
-
return
|
|
11
|
+
return (p) => {
|
|
12
12
|
return new MapParser_1.MapParser(p, mapper);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
ParserOperators.map = map;
|
|
16
16
|
function optional() {
|
|
17
|
-
return
|
|
17
|
+
return (p) => {
|
|
18
18
|
return new OptionalCombinator_1.OptionalCombinator(p);
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
ParserOperators.optional = optional;
|
|
22
22
|
function build(ctor) {
|
|
23
|
-
return
|
|
23
|
+
return (p) => {
|
|
24
24
|
return new AstBuilder_1.AstBuilder(p, ctor);
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
ParserOperators.build = build;
|
|
28
28
|
function omit() {
|
|
29
|
-
return
|
|
30
|
-
return new MapParser_1.MapParser(p,
|
|
29
|
+
return (p) => {
|
|
30
|
+
return new MapParser_1.MapParser(p, (a) => { });
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
ParserOperators.omit = omit;
|
|
34
34
|
function whitespace(ws) {
|
|
35
|
-
return
|
|
35
|
+
return (p) => {
|
|
36
36
|
return p.whitespace(ws);
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
ParserOperators.whitespace = whitespace;
|
|
40
40
|
function withIndices() {
|
|
41
|
-
return
|
|
41
|
+
return (p) => {
|
|
42
42
|
return new ParserWithIndices_1.ParserWithIndices(p);
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
ParserOperators.withIndices = withIndices;
|
|
46
|
-
})(ParserOperators
|
|
46
|
+
})(ParserOperators || (exports.ParserOperators = ParserOperators = {}));
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AnyOfParser = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (_minLen === void 0) { _minLen = 1; }
|
|
8
|
-
if (_maxLen === void 0) { _maxLen = null; }
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
class AnyOfParser {
|
|
6
|
+
constructor(_characters, _minLen = 1, _maxLen = null) {
|
|
9
7
|
this._characters = _characters;
|
|
10
8
|
this._minLen = _minLen;
|
|
11
9
|
this._maxLen = _maxLen;
|
|
12
|
-
|
|
10
|
+
const charBitmap = [];
|
|
13
11
|
this._charBitmap = charBitmap;
|
|
14
|
-
for (
|
|
15
|
-
|
|
12
|
+
for (let i = 0; i < _characters.length; i++) {
|
|
13
|
+
const ccode = _characters.charCodeAt(i);
|
|
16
14
|
if (ccode < 256) {
|
|
17
|
-
charBitmap[ccode >> 3] =
|
|
15
|
+
charBitmap[ccode >> 3] =
|
|
16
|
+
(charBitmap[ccode >> 3] || 0) | (1 << (ccode & 7));
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
19
|
this._charBitmap = null;
|
|
@@ -22,14 +21,14 @@ var AnyOfParser = /** @class */ (function () {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
parse(parserContext) {
|
|
25
|
+
let ret = [];
|
|
26
|
+
let cont = true;
|
|
27
|
+
const input = parserContext.input;
|
|
29
28
|
while (cont && !input.eof()) {
|
|
30
|
-
|
|
29
|
+
const str = input.peek(1);
|
|
31
30
|
if (this._charBitmap) {
|
|
32
|
-
|
|
31
|
+
const ccode = str.charCodeAt(0);
|
|
33
32
|
cont = (this._charBitmap[ccode >> 3] & (1 << (ccode & 7))) != 0;
|
|
34
33
|
}
|
|
35
34
|
else {
|
|
@@ -42,10 +41,9 @@ var AnyOfParser = /** @class */ (function () {
|
|
|
42
41
|
}
|
|
43
42
|
if ((this._maxLen != null && ret.length > this._maxLen) ||
|
|
44
43
|
(this._minLen != null && ret.length < this._minLen)) {
|
|
45
|
-
return core_1.ParseResult.failed(core_1.ParseError.parserRejected(this, parserContext,
|
|
44
|
+
return core_1.ParseResult.failed(core_1.ParseError.parserRejected(this, parserContext, `Expecting AnyOf ${this._characters}`));
|
|
46
45
|
}
|
|
47
|
-
return core_1.ParseResult.successful(ret.join(
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
}());
|
|
46
|
+
return core_1.ParseResult.successful(ret.join(""));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
51
49
|
exports.AnyOfParser = AnyOfParser;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Parser, ParserContext, ParseResult } from "../core";
|
|
2
|
+
export declare class RegexParser implements Parser<string> {
|
|
3
|
+
private _regex;
|
|
4
|
+
_charBitmap: number[] | null;
|
|
5
|
+
constructor(_regex: RegExp);
|
|
6
|
+
parse(parserContext: ParserContext): ParseResult<string>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegexParser = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
class RegexParser {
|
|
6
|
+
constructor(_regex) {
|
|
7
|
+
this._regex = _regex;
|
|
8
|
+
this._charBitmap = null;
|
|
9
|
+
}
|
|
10
|
+
parse(parserContext) {
|
|
11
|
+
if (!parserContext.input.readRegex) {
|
|
12
|
+
throw core_1.ParseError.parserRejected(this, parserContext, "Input doesn't support regex parsing");
|
|
13
|
+
}
|
|
14
|
+
const reResult = parserContext.input.readRegex(this._regex);
|
|
15
|
+
if (!reResult) {
|
|
16
|
+
return core_1.ParseResult.failed(core_1.ParseError.parserRejected(this, parserContext, `Expected ${this._regex.source}`));
|
|
17
|
+
}
|
|
18
|
+
return core_1.ParseResult.successful(reResult);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.RegexParser = RegexParser;
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenParser = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
class TokenParser {
|
|
6
|
+
constructor(_token) {
|
|
7
7
|
this._token = _token;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
parse(parserContext) {
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
const str = parserContext.input.read(this._token.length);
|
|
12
12
|
if (str !== this._token) {
|
|
13
|
-
return core_1.ParseResult.failed(core_1.ParseError.parserRejected(this, parserContext,
|
|
13
|
+
return core_1.ParseResult.failed(core_1.ParseError.parserRejected(this, parserContext, `Expected token ${this._token}`));
|
|
14
14
|
}
|
|
15
15
|
return core_1.ParseResult.successful(str);
|
|
16
16
|
}
|
|
17
17
|
catch (e) {
|
|
18
|
-
|
|
18
|
+
if (e instanceof core_1.ParseError) {
|
|
19
|
+
return core_1.ParseResult.failed(e);
|
|
20
|
+
}
|
|
21
|
+
throw e;
|
|
19
22
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
23
25
|
exports.TokenParser = TokenParser;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Parser, ParserContext } from "../core";
|
|
1
|
+
import { Parser, ParserContext, ParseResult } from "../core";
|
|
2
2
|
export declare class WhitespaceParser implements Parser<void> {
|
|
3
3
|
private _mandatory;
|
|
4
4
|
constructor(_mandatory: boolean);
|
|
5
|
-
parse(parserContext: ParserContext):
|
|
5
|
+
parse(parserContext: ParserContext): ParseResult<void>;
|
|
6
6
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WhitespaceParser = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
class WhitespaceParser {
|
|
6
|
+
constructor(_mandatory) {
|
|
7
7
|
this._mandatory = _mandatory;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
while (!input.eof() &&
|
|
9
|
+
parse(parserContext) {
|
|
10
|
+
const input = parserContext.input;
|
|
11
|
+
let c;
|
|
12
|
+
let found = false;
|
|
13
|
+
while (!input.eof() &&
|
|
14
|
+
((c = input.peek(1)), c == " " || c == "\t" || c == "\n")) {
|
|
14
15
|
input.read(1);
|
|
15
16
|
found = true;
|
|
16
17
|
}
|
|
@@ -20,7 +21,6 @@ var WhitespaceParser = /** @class */ (function () {
|
|
|
20
21
|
else {
|
|
21
22
|
return core_1.ParseResult.voidSuccessful();
|
|
22
23
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
26
|
exports.WhitespaceParser = WhitespaceParser;
|
package/dist/parzing.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|