@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.
@@ -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 (!ParserCache) {
1986
- ParserCache = new Parser(ParserRules, { debug: false });
1985
+ if (!parser) {
1986
+ if (!ParserCache) {
1987
+ ParserCache = new Parser(ParserRules, { debug: false });
1988
+ }
1989
+ parser = ParserCache;
1987
1990
  }
1988
1991
  try {
1989
- ret = ParserCache.getAST(txt.trim(), 'statement_main');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@halleyassist/rule-parser",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "The grammar for HalleyAssist rules",
5
5
  "main": "src/RuleParser.production.js",
6
6
  "browser": "./dist/rule-parser.browser.js",
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(!ParserCache){
72
- ParserCache = new Parser(ParserRules, {debug: false})
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 = ParserCache.getAST(txt.trim(), 'statement_main');
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(!ParserCache){
72
- ParserCache = new Parser(ParserRules, {debug: false})
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 = ParserCache.getAST(txt.trim(), 'statement_main');
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) {