@@ -54,10 +54,11 @@ static void Main(string[] args)
5454 text = Regex . Replace ( text , @"this\.state = \d+;[\r\n\t ]*this\.match" , "this.match" ) ;
5555 text = Regex . Replace ( text , @"this\.state = \d+;[\r\n\t ]*this\._errHandler\.sync\(this\);" , "this._errHandler.sync(this);" ) ;
5656 text = Regex . Replace ( text , @"this\.state = \d+;[\r\n\t ]*_la" , "_la" ) ;
57+ text = Regex . Replace ( text , @"this\.state = \d+;[\r\n\t ]*localctx" , "localctx" ) ;
58+ text = Regex . Replace ( text , @"this\.state = \d+;[\r\n\t ]*localctx" , "localctx" ) ;
59+
5760
58-
5961
60- text = Regex . Replace ( text , @"sempred\(localctx, ruleIndex, predIndex\) \{[\s\S]+?\};" , "sempred(localctx, ruleIndex, predIndex) { return true; };" ) ;
6162
6263 // expr 一般情况下返回 ExprContext 的数组 或 单个 ExprContext
6364 text = Regex . Replace ( text , @"expr = function\(i\) \{[\s\S]+?\};" , "expr = function(i) {return this.getTypedRuleContexts(ExprContext);};" ) ;
@@ -66,11 +67,51 @@ static void Main(string[] args)
6667 text = Regex . Replace ( text , @"if\(parent===undefined\) \{[\r\n\t ]*parent = null;[\r\n\t ]*\}" , "" ) ;
6768 text = Regex . Replace ( text , @"if\(invokingState===undefined \|\| invokingState===null\) \{[\r\n\t ]*invokingState = -1;[\r\n\t ]*}" , "" ) ;
6869
69-
70-
7170 text = Regex . Replace ( text , @"let _prevctx = localctx;" , "" ) ;
7271 text = Regex . Replace ( text , @"_prevctx = localctx;" , "" ) ;
7372
73+
74+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.state = (\d+);[\r\n\t ]*this\.expr\((\d+)\);"
75+ , "this.F($1,$2,$3,$4,$5,$6);" ) ;
76+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.state = (\d+);[\r\n\t ]*this\.expr\((\d+)\);"
77+ , "this.G($1,$2,$3,$4,$5);" ) ;
78+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.state = (\d+);[\r\n\t ]*this\.expr\((\d+)\);"
79+ , "this.I($1,$2,$3,$4);" ) ;
80+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.state = (\d+);[\r\n\t ]*this\.expr\((\d+)\);"
81+ , "this.J($1,$2,$3);" ) ;
82+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);" , "this.D($1,$2,$3,$4);" ) ;
83+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);" , "this.C($1,$2,$3);" ) ;
84+ text = Regex . Replace ( text , @"this\.match\((\d+)\);[\r\n\t ]*this\.match\((\d+)\);" , "this.B($1,$2);" ) ;
85+ text = Regex . Replace ( text , @"this\.match\((\d+)\);" , "this.A($1);" ) ;
86+ text = Regex . Replace ( text , @"this\.state = (\d+);[\r\n\t ]*this\.expr\((\d+)\);" , "this.E($1,$2);" ) ;
87+ text = Regex . Replace ( text , @"this\._errHandler\.sync\(this\);[\r\n\t ]*_la = this\._input\.LA\(1\);" , "_la = this.Z();" ) ;
88+ text = Regex . Replace ( text , @"_la = this\._input\.LA\(1\);" , "_la = this.Y();" ) ;
89+ text = Regex . Replace ( text , @"this\._errHandler\.sync\(this\);" , "this.X();" ) ;
90+ text = text . Replace ( "this.pushNewRecursionContext(localctx, _startState, 1);" , "this.W(localctx, _startState, 1);" ) ;
91+ text = Regex . Replace ( text , @"this\._errHandler\.reportMatch\(this\);[\r\n\t ]*this\.consume\(\);" , "this.Q();" ) ;
92+
93+
94+
95+ text = Regex . Replace ( text , @"sempred\(localctx, ruleIndex, predIndex\) \{[\s\S]+?\};" , @" sempred(localctx, ruleIndex, predIndex){return true;};
96+ A(a){this.match(a);}
97+ B(a,b){this.match(a);this.match(b);}
98+ C(a,b,c){this.match(a);this.match(b);this.match(c);}
99+ D(a,b,c,d){this.match(a);this.match(b);this.match(c);this.match(d);}
100+ E(a,b){this.state=a;this.expr(b);}
101+ F(a,b,c,d,e,f){this.match(a);this.match(b);this.match(c);this.match(d);this.state=e;this.expr(f);}
102+ G(a,b,c,e,f){this.match(a);this.match(b);this.match(c);this.state=e;this.expr(f);}
103+ I(a,b,e,f){this.match(a);this.match(b);this.state=e;this.expr(f);}
104+ J(a,e,f){this.match(a);this.state=e;this.expr(f);}
105+
106+
107+
108+ Q(){this._errHandler.reportMatch(this);this.consume();}
109+ W(a,b,c){this.pushNewRecursionContext(a, b, c);}
110+ X(){this._errHandler.sync(this);}
111+ Y(){return this._input.LA(1);}
112+ Z(){this._errHandler.sync(this);return this._input.LA(1);}
113+ " ) ;
114+
74115 // 清理多余的空行和注释
75116 text = Regex . Replace ( text , @"[\t ]*//.*([\r\n])" , "$1" ) ;
76117 text = Regex . Replace ( text , @"[\t ]*([\r\n])([\r\n])+" , "$1" ) ;
0 commit comments