@halleyassist/rule-parser 1.0.21 → 1.0.23
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/dist/rule-parser.browser.js +7 -4
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/RuleParser.js +7 -4
- package/src/RuleParser.production.js +7 -4
|
@@ -1980,13 +1980,16 @@ const normalizeDow = text => {
|
|
|
1980
1980
|
};
|
|
1981
1981
|
const Epsilon = 0.01;
|
|
1982
1982
|
class RuleParser {
|
|
1983
|
-
static toAst(txt) {
|
|
1983
|
+
static toAst(txt, parser = null) {
|
|
1984
1984
|
let ret;
|
|
1985
|
-
if (!
|
|
1986
|
-
|
|
1985
|
+
if (!parser) {
|
|
1986
|
+
if (!ParserCache) {
|
|
1987
|
+
ParserCache = new Parser(ParserRules, { debug: false });
|
|
1988
|
+
}
|
|
1989
|
+
parser = ParserCache;
|
|
1987
1990
|
}
|
|
1988
1991
|
try {
|
|
1989
|
-
ret =
|
|
1992
|
+
ret = parser.getAST(txt.trim(), 'statement_main');
|
|
1990
1993
|
} catch (e) {
|
|
1991
1994
|
if (e instanceof ParsingError) {
|
|
1992
1995
|
throw ErrorAnalyzer.analyzeParseFailure(txt, e);
|
package/index.d.ts
CHANGED
|
@@ -198,7 +198,7 @@ declare class RuleParser {
|
|
|
198
198
|
* @returns The AST node representing the parsed rule
|
|
199
199
|
* @throws {RuleParseError} If the rule string is invalid
|
|
200
200
|
*/
|
|
201
|
-
static toAst(txt: string): ASTNode;
|
|
201
|
+
static toAst(txt: string, parser: any = null): ASTNode;
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
204
|
* Parse a rule string into an Intermediate Language (IL) representation
|
package/package.json
CHANGED
package/src/RuleParser.js
CHANGED
|
@@ -65,15 +65,18 @@ const normalizeDow = (text) => {
|
|
|
65
65
|
const Epsilon = 0.01
|
|
66
66
|
|
|
67
67
|
class RuleParser {
|
|
68
|
-
static toAst(txt){
|
|
68
|
+
static toAst(txt, parser = null){
|
|
69
69
|
let ret
|
|
70
70
|
|
|
71
|
-
if(!
|
|
72
|
-
ParserCache
|
|
71
|
+
if(!parser) {
|
|
72
|
+
if(!ParserCache){
|
|
73
|
+
ParserCache = new Parser(ParserRules, {debug: false})
|
|
74
|
+
}
|
|
75
|
+
parser = ParserCache
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
try {
|
|
76
|
-
ret =
|
|
79
|
+
ret = parser.getAST(txt.trim(), 'statement_main');
|
|
77
80
|
} catch (e) {
|
|
78
81
|
// If ebnf throws ParsingError, convert it to RuleParseError with helpful error code
|
|
79
82
|
if (e instanceof ParsingError) {
|
|
@@ -65,15 +65,18 @@ const normalizeDow = (text) => {
|
|
|
65
65
|
const Epsilon = 0.01
|
|
66
66
|
|
|
67
67
|
class RuleParser {
|
|
68
|
-
static toAst(txt){
|
|
68
|
+
static toAst(txt, parser = null){
|
|
69
69
|
let ret
|
|
70
70
|
|
|
71
|
-
if(!
|
|
72
|
-
ParserCache
|
|
71
|
+
if(!parser) {
|
|
72
|
+
if(!ParserCache){
|
|
73
|
+
ParserCache = new Parser(ParserRules, {debug: false})
|
|
74
|
+
}
|
|
75
|
+
parser = ParserCache
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
try {
|
|
76
|
-
ret =
|
|
79
|
+
ret = parser.getAST(txt.trim(), 'statement_main');
|
|
77
80
|
} catch (e) {
|
|
78
81
|
// If ebnf throws ParsingError, convert it to RuleParseError with helpful error code
|
|
79
82
|
if (e instanceof ParsingError) {
|