Commit 0265e6dc authored by Vladimír Štill's avatar Vladimír Štill
Browse files

lib: Update parser to handle init/final as state names

parent a9b22c1e
Pipeline #95038 passed with stage
in 1 minute and 40 seconds
......@@ -10,7 +10,7 @@ production: LEFT_PARENTHESIS statename COMMA statename RIGHT_PARENTHESIS EQUALS
final: FINAL EQUALS LEFT_BRACKET (statename (COMMA statename)* | ) RIGHT_BRACKET;
statename: (STATE | QUOTE anyvalue+ QUOTE);
statename: (INIT | FINAL | STATE | QUOTE anyvalue+ QUOTE);
comment: (HASH anyvalue* | );
......
......@@ -12,31 +12,32 @@ else:
def serializedATN():
with StringIO() as buf:
buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\17")
buf.write("P\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b")
buf.write("R\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b")
buf.write("\t\b\3\2\3\2\7\2\23\n\2\f\2\16\2\26\13\2\3\2\3\2\3\2\3")
buf.write("\3\3\3\3\3\3\3\5\3\37\n\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4")
buf.write("\3\4\3\5\3\5\3\5\3\5\3\5\3\5\7\5/\n\5\f\5\16\5\62\13\5")
buf.write("\3\5\5\5\65\n\5\3\5\3\5\3\6\3\6\3\6\6\6<\n\6\r\6\16\6")
buf.write("=\3\6\3\6\5\6B\n\6\3\7\3\7\7\7F\n\7\f\7\16\7I\13\7\3\7")
buf.write("\5\7L\n\7\3\b\3\b\3\b\2\2\t\2\4\6\b\n\f\16\2\3\4\2\3\f")
buf.write("\17\17\2P\2\20\3\2\2\2\4\36\3\2\2\2\6 \3\2\2\2\b(\3\2")
buf.write("\2\2\nA\3\2\2\2\fK\3\2\2\2\16M\3\2\2\2\20\24\5\4\3\2\21")
buf.write("\23\5\6\4\2\22\21\3\2\2\2\23\26\3\2\2\2\24\22\3\2\2\2")
buf.write("\24\25\3\2\2\2\25\27\3\2\2\2\26\24\3\2\2\2\27\30\5\b\5")
buf.write("\2\30\31\5\f\7\2\31\3\3\2\2\2\32\33\7\3\2\2\33\34\7\4")
buf.write("\2\2\34\37\5\n\6\2\35\37\3\2\2\2\36\32\3\2\2\2\36\35\3")
buf.write("\2\2\2\37\5\3\2\2\2 !\7\5\2\2!\"\5\n\6\2\"#\7\t\2\2#$")
buf.write("\5\n\6\2$%\7\6\2\2%&\7\4\2\2&\'\5\n\6\2\'\7\3\2\2\2()")
buf.write("\7\n\2\2)*\7\4\2\2*\64\7\7\2\2+\60\5\n\6\2,-\7\t\2\2-")
buf.write("/\5\n\6\2.,\3\2\2\2/\62\3\2\2\2\60.\3\2\2\2\60\61\3\2")
buf.write("\2\2\61\65\3\2\2\2\62\60\3\2\2\2\63\65\3\2\2\2\64+\3\2")
buf.write("\2\2\64\63\3\2\2\2\65\66\3\2\2\2\66\67\7\b\2\2\67\t\3")
buf.write("\2\2\28B\7\13\2\29;\7\r\2\2:<\5\16\b\2;:\3\2\2\2<=\3\2")
buf.write("\2\2=;\3\2\2\2=>\3\2\2\2>?\3\2\2\2?@\7\r\2\2@B\3\2\2\2")
buf.write("A8\3\2\2\2A9\3\2\2\2B\13\3\2\2\2CG\7\f\2\2DF\5\16\b\2")
buf.write("ED\3\2\2\2FI\3\2\2\2GE\3\2\2\2GH\3\2\2\2HL\3\2\2\2IG\3")
buf.write("\2\2\2JL\3\2\2\2KC\3\2\2\2KJ\3\2\2\2L\r\3\2\2\2MN\t\2")
buf.write("\2\2N\17\3\2\2\2\n\24\36\60\64=AGK")
buf.write("\3\5\5\5\65\n\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\6\6>\n\6\r")
buf.write("\6\16\6?\3\6\3\6\5\6D\n\6\3\7\3\7\7\7H\n\7\f\7\16\7K\13")
buf.write("\7\3\7\5\7N\n\7\3\b\3\b\3\b\2\2\t\2\4\6\b\n\f\16\2\3\4")
buf.write("\2\3\f\17\17\2T\2\20\3\2\2\2\4\36\3\2\2\2\6 \3\2\2\2\b")
buf.write("(\3\2\2\2\nC\3\2\2\2\fM\3\2\2\2\16O\3\2\2\2\20\24\5\4")
buf.write("\3\2\21\23\5\6\4\2\22\21\3\2\2\2\23\26\3\2\2\2\24\22\3")
buf.write("\2\2\2\24\25\3\2\2\2\25\27\3\2\2\2\26\24\3\2\2\2\27\30")
buf.write("\5\b\5\2\30\31\5\f\7\2\31\3\3\2\2\2\32\33\7\3\2\2\33\34")
buf.write("\7\4\2\2\34\37\5\n\6\2\35\37\3\2\2\2\36\32\3\2\2\2\36")
buf.write("\35\3\2\2\2\37\5\3\2\2\2 !\7\5\2\2!\"\5\n\6\2\"#\7\t\2")
buf.write("\2#$\5\n\6\2$%\7\6\2\2%&\7\4\2\2&\'\5\n\6\2\'\7\3\2\2")
buf.write("\2()\7\n\2\2)*\7\4\2\2*\64\7\7\2\2+\60\5\n\6\2,-\7\t\2")
buf.write("\2-/\5\n\6\2.,\3\2\2\2/\62\3\2\2\2\60.\3\2\2\2\60\61\3")
buf.write("\2\2\2\61\65\3\2\2\2\62\60\3\2\2\2\63\65\3\2\2\2\64+\3")
buf.write("\2\2\2\64\63\3\2\2\2\65\66\3\2\2\2\66\67\7\b\2\2\67\t")
buf.write("\3\2\2\28D\7\3\2\29D\7\n\2\2:D\7\13\2\2;=\7\r\2\2<>\5")
buf.write("\16\b\2=<\3\2\2\2>?\3\2\2\2?=\3\2\2\2?@\3\2\2\2@A\3\2")
buf.write("\2\2AB\7\r\2\2BD\3\2\2\2C8\3\2\2\2C9\3\2\2\2C:\3\2\2\2")
buf.write("C;\3\2\2\2D\13\3\2\2\2EI\7\f\2\2FH\5\16\b\2GF\3\2\2\2")
buf.write("HK\3\2\2\2IG\3\2\2\2IJ\3\2\2\2JN\3\2\2\2KI\3\2\2\2LN\3")
buf.write("\2\2\2ME\3\2\2\2ML\3\2\2\2N\r\3\2\2\2OP\t\2\2\2P\17\3")
buf.write("\2\2\2\n\24\36\60\64?CIM")
return buf.getvalue()
......@@ -381,7 +382,7 @@ class DFAParser ( Parser ):
self.state = 50
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [DFAParser.STATE, DFAParser.QUOTE]:
if token in [DFAParser.INIT, DFAParser.FINAL, DFAParser.STATE, DFAParser.QUOTE]:
self.state = 41
self.statename()
self.state = 46
......@@ -420,6 +421,12 @@ class DFAParser ( Parser ):
super().__init__(parent, invokingState)
self.parser = parser
def INIT(self):
return self.getToken(DFAParser.INIT, 0)
def FINAL(self):
return self.getToken(DFAParser.FINAL, 0)
def STATE(self):
return self.getToken(DFAParser.STATE, 0)
......@@ -463,29 +470,37 @@ class DFAParser ( Parser ):
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 63
self.state = 65
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [DFAParser.STATE]:
if token in [DFAParser.INIT]:
self.state = 54
self.match(DFAParser.INIT)
pass
elif token in [DFAParser.FINAL]:
self.state = 55
self.match(DFAParser.FINAL)
pass
elif token in [DFAParser.STATE]:
self.state = 56
self.match(DFAParser.STATE)
pass
elif token in [DFAParser.QUOTE]:
self.state = 55
self.state = 57
self.match(DFAParser.QUOTE)
self.state = 57
self.state = 59
self._errHandler.sync(self)
_la = self._input.LA(1)
while True:
self.state = 56
self.state = 58
self.anyvalue()
self.state = 59
self.state = 61
self._errHandler.sync(self)
_la = self._input.LA(1)
if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << DFAParser.INIT) | (1 << DFAParser.EQUALS) | (1 << DFAParser.LEFT_PARENTHESIS) | (1 << DFAParser.RIGHT_PARENTHESIS) | (1 << DFAParser.LEFT_BRACKET) | (1 << DFAParser.RIGHT_BRACKET) | (1 << DFAParser.COMMA) | (1 << DFAParser.FINAL) | (1 << DFAParser.STATE) | (1 << DFAParser.HASH) | (1 << DFAParser.ANYCHAR))) != 0)):
break
self.state = 61
self.state = 63
self.match(DFAParser.QUOTE)
pass
else:
......@@ -544,19 +559,19 @@ class DFAParser ( Parser ):
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 73
self.state = 75
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [DFAParser.HASH]:
self.state = 65
self.state = 67
self.match(DFAParser.HASH)
self.state = 69
self.state = 71
self._errHandler.sync(self)
_la = self._input.LA(1)
while (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << DFAParser.INIT) | (1 << DFAParser.EQUALS) | (1 << DFAParser.LEFT_PARENTHESIS) | (1 << DFAParser.RIGHT_PARENTHESIS) | (1 << DFAParser.LEFT_BRACKET) | (1 << DFAParser.RIGHT_BRACKET) | (1 << DFAParser.COMMA) | (1 << DFAParser.FINAL) | (1 << DFAParser.STATE) | (1 << DFAParser.HASH) | (1 << DFAParser.ANYCHAR))) != 0):
self.state = 66
self.state = 68
self.anyvalue()
self.state = 71
self.state = 73
self._errHandler.sync(self)
_la = self._input.LA(1)
......@@ -642,7 +657,7 @@ class DFAParser ( Parser ):
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 75
self.state = 77
_la = self._input.LA(1)
if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << DFAParser.INIT) | (1 << DFAParser.EQUALS) | (1 << DFAParser.LEFT_PARENTHESIS) | (1 << DFAParser.RIGHT_PARENTHESIS) | (1 << DFAParser.LEFT_BRACKET) | (1 << DFAParser.RIGHT_BRACKET) | (1 << DFAParser.COMMA) | (1 << DFAParser.FINAL) | (1 << DFAParser.STATE) | (1 << DFAParser.HASH) | (1 << DFAParser.ANYCHAR))) != 0)):
self._errHandler.recoverInline(self)
......
......@@ -12,7 +12,7 @@ stateset: LEFT_BRACKET (statename (COMMA statename)* | ) RIGHT_BRACKET;
final: FINAL EQUALS stateset;
statename: (STATE | QUOTE anyvalue+ QUOTE);
statename: (STATE | INIT | FINAL | QUOTE anyvalue+ QUOTE);
comment: (HASH anyvalue* | );
......
......@@ -12,33 +12,34 @@ else:
def serializedATN():
with StringIO() as buf:
buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\20")
buf.write("W\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b")
buf.write("Y\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b")
buf.write("\t\b\4\t\t\t\3\2\3\2\7\2\25\n\2\f\2\16\2\30\13\2\3\2\3")
buf.write("\2\3\2\3\3\3\3\3\3\3\3\5\3!\n\3\3\4\3\4\3\4\3\4\3\4\5")
buf.write("\4(\n\4\3\4\3\4\3\4\3\4\3\5\3\5\3\5\3\5\7\5\62\n\5\f\5")
buf.write("\16\5\65\13\5\3\5\5\58\n\5\3\5\3\5\3\6\3\6\3\6\3\6\3\7")
buf.write("\3\7\3\7\6\7C\n\7\r\7\16\7D\3\7\3\7\5\7I\n\7\3\b\3\b\7")
buf.write("\bM\n\b\f\b\16\bP\13\b\3\b\5\bS\n\b\3\t\3\t\3\t\2\2\n")
buf.write("\2\4\6\b\n\f\16\20\2\3\5\2\3\n\f\r\20\20\2W\2\22\3\2\2")
buf.write("\2\4 \3\2\2\2\6\"\3\2\2\2\b-\3\2\2\2\n;\3\2\2\2\fH\3\2")
buf.write("\2\2\16R\3\2\2\2\20T\3\2\2\2\22\26\5\4\3\2\23\25\5\6\4")
buf.write("\2\24\23\3\2\2\2\25\30\3\2\2\2\26\24\3\2\2\2\26\27\3\2")
buf.write("\2\2\27\31\3\2\2\2\30\26\3\2\2\2\31\32\5\n\6\2\32\33\5")
buf.write("\16\b\2\33\3\3\2\2\2\34\35\7\3\2\2\35\36\7\4\2\2\36!\5")
buf.write("\f\7\2\37!\3\2\2\2 \34\3\2\2\2 \37\3\2\2\2!\5\3\2\2\2")
buf.write("\"#\7\5\2\2#$\5\f\7\2$\'\7\t\2\2%(\5\f\7\2&(\7\13\2\2")
buf.write("\'%\3\2\2\2\'&\3\2\2\2()\3\2\2\2)*\7\6\2\2*+\7\4\2\2+")
buf.write(",\5\b\5\2,\7\3\2\2\2-\67\7\7\2\2.\63\5\f\7\2/\60\7\t\2")
buf.write("\2\60\62\5\f\7\2\61/\3\2\2\2\62\65\3\2\2\2\63\61\3\2\2")
buf.write("\2\63\64\3\2\2\2\648\3\2\2\2\65\63\3\2\2\2\668\3\2\2\2")
buf.write("\67.\3\2\2\2\67\66\3\2\2\289\3\2\2\29:\7\b\2\2:\t\3\2")
buf.write("\2\2;<\7\n\2\2<=\7\4\2\2=>\5\b\5\2>\13\3\2\2\2?I\7\f\2")
buf.write("\2@B\7\16\2\2AC\5\20\t\2BA\3\2\2\2CD\3\2\2\2DB\3\2\2\2")
buf.write("DE\3\2\2\2EF\3\2\2\2FG\7\16\2\2GI\3\2\2\2H?\3\2\2\2H@")
buf.write("\3\2\2\2I\r\3\2\2\2JN\7\r\2\2KM\5\20\t\2LK\3\2\2\2MP\3")
buf.write("\2\2\2NL\3\2\2\2NO\3\2\2\2OS\3\2\2\2PN\3\2\2\2QS\3\2\2")
buf.write("\2RJ\3\2\2\2RQ\3\2\2\2S\17\3\2\2\2TU\t\2\2\2U\21\3\2\2")
buf.write("\2\13\26 \'\63\67DHNR")
buf.write("\3\7\3\7\3\7\3\7\6\7E\n\7\r\7\16\7F\3\7\3\7\5\7K\n\7\3")
buf.write("\b\3\b\7\bO\n\b\f\b\16\bR\13\b\3\b\5\bU\n\b\3\t\3\t\3")
buf.write("\t\2\2\n\2\4\6\b\n\f\16\20\2\3\5\2\3\n\f\r\20\20\2[\2")
buf.write("\22\3\2\2\2\4 \3\2\2\2\6\"\3\2\2\2\b-\3\2\2\2\n;\3\2\2")
buf.write("\2\fJ\3\2\2\2\16T\3\2\2\2\20V\3\2\2\2\22\26\5\4\3\2\23")
buf.write("\25\5\6\4\2\24\23\3\2\2\2\25\30\3\2\2\2\26\24\3\2\2\2")
buf.write("\26\27\3\2\2\2\27\31\3\2\2\2\30\26\3\2\2\2\31\32\5\n\6")
buf.write("\2\32\33\5\16\b\2\33\3\3\2\2\2\34\35\7\3\2\2\35\36\7\4")
buf.write("\2\2\36!\5\f\7\2\37!\3\2\2\2 \34\3\2\2\2 \37\3\2\2\2!")
buf.write("\5\3\2\2\2\"#\7\5\2\2#$\5\f\7\2$\'\7\t\2\2%(\5\f\7\2&")
buf.write("(\7\13\2\2\'%\3\2\2\2\'&\3\2\2\2()\3\2\2\2)*\7\6\2\2*")
buf.write("+\7\4\2\2+,\5\b\5\2,\7\3\2\2\2-\67\7\7\2\2.\63\5\f\7\2")
buf.write("/\60\7\t\2\2\60\62\5\f\7\2\61/\3\2\2\2\62\65\3\2\2\2\63")
buf.write("\61\3\2\2\2\63\64\3\2\2\2\648\3\2\2\2\65\63\3\2\2\2\66")
buf.write("8\3\2\2\2\67.\3\2\2\2\67\66\3\2\2\289\3\2\2\29:\7\b\2")
buf.write("\2:\t\3\2\2\2;<\7\n\2\2<=\7\4\2\2=>\5\b\5\2>\13\3\2\2")
buf.write("\2?K\7\f\2\2@K\7\3\2\2AK\7\n\2\2BD\7\16\2\2CE\5\20\t\2")
buf.write("DC\3\2\2\2EF\3\2\2\2FD\3\2\2\2FG\3\2\2\2GH\3\2\2\2HI\7")
buf.write("\16\2\2IK\3\2\2\2J?\3\2\2\2J@\3\2\2\2JA\3\2\2\2JB\3\2")
buf.write("\2\2K\r\3\2\2\2LP\7\r\2\2MO\5\20\t\2NM\3\2\2\2OR\3\2\2")
buf.write("\2PN\3\2\2\2PQ\3\2\2\2QU\3\2\2\2RP\3\2\2\2SU\3\2\2\2T")
buf.write("L\3\2\2\2TS\3\2\2\2U\17\3\2\2\2VW\t\2\2\2W\21\3\2\2\2")
buf.write("\13\26 \'\63\67FJPT")
return buf.getvalue()
......@@ -311,7 +312,7 @@ class NFAParser ( Parser ):
self.state = 37
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [NFAParser.STATE, NFAParser.QUOTE]:
if token in [NFAParser.INIT, NFAParser.FINAL, NFAParser.STATE, NFAParser.QUOTE]:
self.state = 35
self.statename()
pass
......@@ -395,7 +396,7 @@ class NFAParser ( Parser ):
self.state = 53
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [NFAParser.STATE, NFAParser.QUOTE]:
if token in [NFAParser.INIT, NFAParser.FINAL, NFAParser.STATE, NFAParser.QUOTE]:
self.state = 44
self.statename()
self.state = 49
......@@ -495,6 +496,12 @@ class NFAParser ( Parser ):
def STATE(self):
return self.getToken(NFAParser.STATE, 0)
def INIT(self):
return self.getToken(NFAParser.INIT, 0)
def FINAL(self):
return self.getToken(NFAParser.FINAL, 0)
def QUOTE(self, i:int=None):
if i is None:
return self.getTokens(NFAParser.QUOTE)
......@@ -535,29 +542,37 @@ class NFAParser ( Parser ):
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 70
self.state = 72
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [NFAParser.STATE]:
self.state = 61
self.match(NFAParser.STATE)
pass
elif token in [NFAParser.QUOTE]:
elif token in [NFAParser.INIT]:
self.state = 62
self.match(NFAParser.INIT)
pass
elif token in [NFAParser.FINAL]:
self.state = 63
self.match(NFAParser.FINAL)
pass
elif token in [NFAParser.QUOTE]:
self.state = 64
self.match(NFAParser.QUOTE)
self.state = 64
self.state = 66
self._errHandler.sync(self)
_la = self._input.LA(1)
while True:
self.state = 63
self.state = 65
self.anyvalue()
self.state = 66
self.state = 68
self._errHandler.sync(self)
_la = self._input.LA(1)
if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << NFAParser.INIT) | (1 << NFAParser.EQUALS) | (1 << NFAParser.LEFT_PARENTHESIS) | (1 << NFAParser.RIGHT_PARENTHESIS) | (1 << NFAParser.LEFT_BRACKET) | (1 << NFAParser.RIGHT_BRACKET) | (1 << NFAParser.COMMA) | (1 << NFAParser.FINAL) | (1 << NFAParser.STATE) | (1 << NFAParser.HASH) | (1 << NFAParser.ANYCHAR))) != 0)):
break
self.state = 68
self.state = 70
self.match(NFAParser.QUOTE)
pass
else:
......@@ -616,19 +631,19 @@ class NFAParser ( Parser ):
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 80
self.state = 82
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [NFAParser.HASH]:
self.state = 72
self.state = 74
self.match(NFAParser.HASH)
self.state = 76
self.state = 78
self._errHandler.sync(self)
_la = self._input.LA(1)
while (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << NFAParser.INIT) | (1 << NFAParser.EQUALS) | (1 << NFAParser.LEFT_PARENTHESIS) | (1 << NFAParser.RIGHT_PARENTHESIS) | (1 << NFAParser.LEFT_BRACKET) | (1 << NFAParser.RIGHT_BRACKET) | (1 << NFAParser.COMMA) | (1 << NFAParser.FINAL) | (1 << NFAParser.STATE) | (1 << NFAParser.HASH) | (1 << NFAParser.ANYCHAR))) != 0):
self.state = 73
self.state = 75
self.anyvalue()
self.state = 78
self.state = 80
self._errHandler.sync(self)
_la = self._input.LA(1)
......@@ -714,7 +729,7 @@ class NFAParser ( Parser ):
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 82
self.state = 84
_la = self._input.LA(1)
if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << NFAParser.INIT) | (1 << NFAParser.EQUALS) | (1 << NFAParser.LEFT_PARENTHESIS) | (1 << NFAParser.RIGHT_PARENTHESIS) | (1 << NFAParser.LEFT_BRACKET) | (1 << NFAParser.RIGHT_BRACKET) | (1 << NFAParser.COMMA) | (1 << NFAParser.FINAL) | (1 << NFAParser.STATE) | (1 << NFAParser.HASH) | (1 << NFAParser.ANYCHAR))) != 0)):
self._errHandler.recoverInline(self)
......
......@@ -197,7 +197,29 @@ class Parser:
raise ParsingError(e.args)
class DFABuilder(DFAListener):
class StateVisitor:
def visitStatename(self, ctx) -> str:
if ctx.STATE():
return str(ctx.STATE())
elif ctx.FINAL():
return "final"
elif ctx.INIT():
return "init"
elif ctx.QUOTE():
name = ""
i = 0
while ctx.anyvalue(i) is not None:
for attribute in self.anyvalue_attributes:
value = getattr(ctx.anyvalue(i), attribute)()
if value is not None:
name += str(value)
i += 1
return name
assert False, "invalid context in visitStatename"
class DFABuilder(DFAListener, StateVisitor):
# anyvalue possibilities
anyvalue_attributes = anyvalue_attributes(DFAParser)
......@@ -215,21 +237,6 @@ class DFABuilder(DFAListener):
self.init = state
self.states.add(state)
def visitStatename(self, ctx) -> str:
if ctx.STATE():
return str(ctx.STATE())
elif ctx.QUOTE():
name = ""
i = 0
while ctx.anyvalue(i) is not None:
for attribute in self.anyvalue_attributes:
value = getattr(ctx.anyvalue(i), attribute)()
if value is not None:
name += str(value)
i += 1
return name
def exitProduction(self, ctx):
state = State(self.visitStatename(ctx.statename(0)))
character = Character(self.visitStatename(ctx.statename(1)))
......@@ -258,7 +265,7 @@ class DFABuilder(DFAListener):
return None
class NFABuilder(NFAListener):
class NFABuilder(NFAListener, StateVisitor):
anyvalue_attributes = anyvalue_attributes(NFAParser)
def __init__(self):
......@@ -276,21 +283,6 @@ class NFABuilder(NFAListener):
self.init = state
self.states.add(state)
def visitStatename(self, ctx) -> str:
if ctx.STATE():
return str(ctx.STATE())
elif ctx.QUOTE():
name = ""
i = 0
while ctx.anyvalue(i) is not None:
for attribute in self.anyvalue_attributes:
value = getattr(ctx.anyvalue(i), attribute)()
if value is not None:
name += str(value)
i += 1
return name
def exitProduction(self, ctx):
state = State(self.visitStatename(ctx.statename(0)))
self.states.add(state)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment