EmbASP-Python
ClingoParser.py
1 # Generated from ClingoParser.g4 by ANTLR 4.7
2 # encoding: utf-8
3 from __future__ import print_function
4 from antlr4 import *
5 from io import StringIO
6 import sys
7 
8 def serializedATN():
9  with StringIO() as buf:
10  buf.write(u"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3")
11  buf.write(u"\f\62\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\3\2\3\2")
12  buf.write(u"\3\2\3\3\7\3\21\n\3\f\3\16\3\24\13\3\3\3\3\3\3\4\7\4")
13  buf.write(u"\31\n\4\f\4\16\4\34\13\4\3\5\3\5\3\5\3\5\3\5\7\5#\n\5")
14  buf.write(u"\f\5\16\5&\13\5\3\5\3\5\5\5*\n\5\3\6\3\6\3\6\3\6\5\6")
15  buf.write(u"\60\n\6\3\6\2\2\7\2\4\6\b\n\2\2\2\63\2\f\3\2\2\2\4\22")
16  buf.write(u"\3\2\2\2\6\32\3\2\2\2\b\35\3\2\2\2\n/\3\2\2\2\f\r\7\3")
17  buf.write(u"\2\2\r\16\5\4\3\2\16\3\3\2\2\2\17\21\5\b\5\2\20\17\3")
18  buf.write(u"\2\2\2\21\24\3\2\2\2\22\20\3\2\2\2\22\23\3\2\2\2\23\25")
19  buf.write(u"\3\2\2\2\24\22\3\2\2\2\25\26\7\7\2\2\26\5\3\2\2\2\27")
20  buf.write(u"\31\5\2\2\2\30\27\3\2\2\2\31\34\3\2\2\2\32\30\3\2\2\2")
21  buf.write(u"\32\33\3\2\2\2\33\7\3\2\2\2\34\32\3\2\2\2\35)\7\b\2\2")
22  buf.write(u"\36\37\7\n\2\2\37$\5\n\6\2 !\7\5\2\2!#\5\n\6\2\" \3\2")
23  buf.write(u"\2\2#&\3\2\2\2$\"\3\2\2\2$%\3\2\2\2%\'\3\2\2\2&$\3\2")
24  buf.write(u"\2\2\'(\7\13\2\2(*\3\2\2\2)\36\3\2\2\2)*\3\2\2\2*\t\3")
25  buf.write(u"\2\2\2+\60\7\b\2\2,\60\7\6\2\2-\60\5\b\5\2.\60\7\t\2")
26  buf.write(u"\2/+\3\2\2\2/,\3\2\2\2/-\3\2\2\2/.\3\2\2\2\60\13\3\2")
27  buf.write(u"\2\2\7\22\32$)/")
28  return buf.getvalue()
29 
30 
31 class ClingoParser ( Parser ):
32 
33  grammarFileName = "ClingoParser.g4"
34 
35  atn = ATNDeserializer().deserialize(serializedATN())
36 
37  decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
38 
39  sharedContextCache = PredictionContextCache()
40 
41  literalNames = [ u"<INVALID>", u"<INVALID>", u"<INVALID>", u"','", u"<INVALID>",
42  u"<INVALID>", u"<INVALID>", u"<INVALID>", u"'('", u"')'" ]
43 
44  symbolicNames = [ u"<INVALID>", u"START", u"ANY", u"COMMA", u"INTEGER_CONSTANT",
45  u"NEW_LINE", u"IDENTIFIER", u"STRING_CONSTANT", u"TERMS_BEGIN",
46  u"TERMS_END", u"WHITE_SPACE" ]
47 
48  RULE_answer_set = 0
49  RULE_model = 1
50  RULE_output = 2
51  RULE_predicate_atom = 3
52  RULE_term = 4
53 
54  ruleNames = [ u"answer_set", u"model", u"output", u"predicate_atom",
55  u"term" ]
56 
57  EOF = Token.EOF
58  START=1
59  ANY=2
60  COMMA=3
61  INTEGER_CONSTANT=4
62  NEW_LINE=5
63  IDENTIFIER=6
64  STRING_CONSTANT=7
65  TERMS_BEGIN=8
66  TERMS_END=9
67  WHITE_SPACE=10
68 
69  def __init__(self, input, output=sys.stdout):
70  super(ClingoParser, self).__init__(input, output=output)
71  self.checkVersion("4.7")
72  self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
73  self._predicates = None
74 
75 
76 
77  class Answer_setContext(ParserRuleContext):
78 
79  def __init__(self, parser, parent=None, invokingState=-1):
80  super(ClingoParser.Answer_setContext, self).__init__(parent, invokingState)
81  self.parser = parser
82 
83  def START(self):
84  return self.getToken(ClingoParser.START, 0)
85 
86  def model(self):
87  return self.getTypedRuleContext(ClingoParser.ModelContext,0)
88 
89 
90  def getRuleIndex(self):
91  return ClingoParser.RULE_answer_set
92 
93  def accept(self, visitor):
94  if hasattr(visitor, "visitAnswer_set"):
95  return visitor.visitAnswer_set(self)
96  else:
97  return visitor.visitChildren(self)
98 
99 
100 
101 
102  def answer_set(self):
103 
104  localctx = ClingoParser.Answer_setContext(self, self._ctx, self.state)
105  self.enterRule(localctx, 0, self.RULE_answer_set)
106  try:
107  self.enterOuterAlt(localctx, 1)
108  self.state = 10
109  self.match(ClingoParser.START)
110  self.state = 11
111  self.model()
112  except RecognitionException as re:
113  localctx.exception = re
114  self._errHandler.reportError(self, re)
115  self._errHandler.recover(self, re)
116  finally:
117  self.exitRule()
118  return localctx
119 
120  class ModelContext(ParserRuleContext):
121 
122  def __init__(self, parser, parent=None, invokingState=-1):
123  super(ClingoParser.ModelContext, self).__init__(parent, invokingState)
124  self.parser = parser
125 
126  def NEW_LINE(self):
127  return self.getToken(ClingoParser.NEW_LINE, 0)
128 
129  def predicate_atom(self, i=None):
130  if i is None:
131  return self.getTypedRuleContexts(ClingoParser.Predicate_atomContext)
132  else:
133  return self.getTypedRuleContext(ClingoParser.Predicate_atomContext,i)
134 
135 
136  def getRuleIndex(self):
137  return ClingoParser.RULE_model
138 
139  def accept(self, visitor):
140  if hasattr(visitor, "visitModel"):
141  return visitor.visitModel(self)
142  else:
143  return visitor.visitChildren(self)
144 
145 
146 
147 
148  def model(self):
149 
150  localctx = ClingoParser.ModelContext(self, self._ctx, self.state)
151  self.enterRule(localctx, 2, self.RULE_model)
152  self._la = 0 # Token type
153  try:
154  self.enterOuterAlt(localctx, 1)
155  self.state = 16
156  self._errHandler.sync(self)
157  _la = self._input.LA(1)
158  while _la==ClingoParser.IDENTIFIER:
159  self.state = 13
160  self.predicate_atom()
161  self.state = 18
162  self._errHandler.sync(self)
163  _la = self._input.LA(1)
164 
165  self.state = 19
166  self.match(ClingoParser.NEW_LINE)
167  except RecognitionException as re:
168  localctx.exception = re
169  self._errHandler.reportError(self, re)
170  self._errHandler.recover(self, re)
171  finally:
172  self.exitRule()
173  return localctx
174 
175  class OutputContext(ParserRuleContext):
176 
177  def __init__(self, parser, parent=None, invokingState=-1):
178  super(ClingoParser.OutputContext, self).__init__(parent, invokingState)
179  self.parser = parser
180 
181  def answer_set(self, i=None):
182  if i is None:
183  return self.getTypedRuleContexts(ClingoParser.Answer_setContext)
184  else:
185  return self.getTypedRuleContext(ClingoParser.Answer_setContext,i)
186 
187 
188  def getRuleIndex(self):
189  return ClingoParser.RULE_output
190 
191  def accept(self, visitor):
192  if hasattr(visitor, "visitOutput"):
193  return visitor.visitOutput(self)
194  else:
195  return visitor.visitChildren(self)
196 
197 
198 
199 
200  def output(self):
201 
202  localctx = ClingoParser.OutputContext(self, self._ctx, self.state)
203  self.enterRule(localctx, 4, self.RULE_output)
204  self._la = 0 # Token type
205  try:
206  self.enterOuterAlt(localctx, 1)
207  self.state = 24
208  self._errHandler.sync(self)
209  _la = self._input.LA(1)
210  while _la==ClingoParser.START:
211  self.state = 21
212  self.answer_set()
213  self.state = 26
214  self._errHandler.sync(self)
215  _la = self._input.LA(1)
216 
217  except RecognitionException as re:
218  localctx.exception = re
219  self._errHandler.reportError(self, re)
220  self._errHandler.recover(self, re)
221  finally:
222  self.exitRule()
223  return localctx
224 
225  class Predicate_atomContext(ParserRuleContext):
226 
227  def __init__(self, parser, parent=None, invokingState=-1):
228  super(ClingoParser.Predicate_atomContext, self).__init__(parent, invokingState)
229  self.parser = parser
230 
231  def IDENTIFIER(self):
232  return self.getToken(ClingoParser.IDENTIFIER, 0)
233 
234  def TERMS_BEGIN(self):
235  return self.getToken(ClingoParser.TERMS_BEGIN, 0)
236 
237  def term(self, i=None):
238  if i is None:
239  return self.getTypedRuleContexts(ClingoParser.TermContext)
240  else:
241  return self.getTypedRuleContext(ClingoParser.TermContext,i)
242 
243 
244  def TERMS_END(self):
245  return self.getToken(ClingoParser.TERMS_END, 0)
246 
247  def COMMA(self, i=None):
248  if i is None:
249  return self.getTokens(ClingoParser.COMMA)
250  else:
251  return self.getToken(ClingoParser.COMMA, i)
252 
253  def getRuleIndex(self):
254  return ClingoParser.RULE_predicate_atom
255 
256  def accept(self, visitor):
257  if hasattr(visitor, "visitPredicate_atom"):
258  return visitor.visitPredicate_atom(self)
259  else:
260  return visitor.visitChildren(self)
261 
262 
263 
264 
265  def predicate_atom(self):
266 
267  localctx = ClingoParser.Predicate_atomContext(self, self._ctx, self.state)
268  self.enterRule(localctx, 6, self.RULE_predicate_atom)
269  self._la = 0 # Token type
270  try:
271  self.enterOuterAlt(localctx, 1)
272  self.state = 27
273  self.match(ClingoParser.IDENTIFIER)
274  self.state = 39
275  self._errHandler.sync(self)
276  _la = self._input.LA(1)
277  if _la==ClingoParser.TERMS_BEGIN:
278  self.state = 28
279  self.match(ClingoParser.TERMS_BEGIN)
280  self.state = 29
281  self.term()
282  self.state = 34
283  self._errHandler.sync(self)
284  _la = self._input.LA(1)
285  while _la==ClingoParser.COMMA:
286  self.state = 30
287  self.match(ClingoParser.COMMA)
288  self.state = 31
289  self.term()
290  self.state = 36
291  self._errHandler.sync(self)
292  _la = self._input.LA(1)
293 
294  self.state = 37
295  self.match(ClingoParser.TERMS_END)
296 
297 
298  except RecognitionException as re:
299  localctx.exception = re
300  self._errHandler.reportError(self, re)
301  self._errHandler.recover(self, re)
302  finally:
303  self.exitRule()
304  return localctx
305 
306  class TermContext(ParserRuleContext):
307 
308  def __init__(self, parser, parent=None, invokingState=-1):
309  super(ClingoParser.TermContext, self).__init__(parent, invokingState)
310  self.parser = parser
311 
312  def IDENTIFIER(self):
313  return self.getToken(ClingoParser.IDENTIFIER, 0)
314 
315  def INTEGER_CONSTANT(self):
316  return self.getToken(ClingoParser.INTEGER_CONSTANT, 0)
317 
318  def predicate_atom(self):
319  return self.getTypedRuleContext(ClingoParser.Predicate_atomContext,0)
320 
321 
322  def STRING_CONSTANT(self):
323  return self.getToken(ClingoParser.STRING_CONSTANT, 0)
324 
325  def getRuleIndex(self):
326  return ClingoParser.RULE_term
327 
328  def accept(self, visitor):
329  if hasattr(visitor, "visitTerm"):
330  return visitor.visitTerm(self)
331  else:
332  return visitor.visitChildren(self)
333 
334 
335 
336 
337  def term(self):
338 
339  localctx = ClingoParser.TermContext(self, self._ctx, self.state)
340  self.enterRule(localctx, 8, self.RULE_term)
341  try:
342  self.state = 45
343  self._errHandler.sync(self)
344  la_ = self._interp.adaptivePredict(self._input,4,self._ctx)
345  if la_ == 1:
346  self.enterOuterAlt(localctx, 1)
347  self.state = 41
348  self.match(ClingoParser.IDENTIFIER)
349  pass
350 
351  elif la_ == 2:
352  self.enterOuterAlt(localctx, 2)
353  self.state = 42
354  self.match(ClingoParser.INTEGER_CONSTANT)
355  pass
356 
357  elif la_ == 3:
358  self.enterOuterAlt(localctx, 3)
359  self.state = 43
360  self.predicate_atom()
361  pass
362 
363  elif la_ == 4:
364  self.enterOuterAlt(localctx, 4)
365  self.state = 44
366  self.match(ClingoParser.STRING_CONSTANT)
367  pass
368 
369 
370  except RecognitionException as re:
371  localctx.exception = re
372  self._errHandler.reportError(self, re)
373  self._errHandler.recover(self, re)
374  finally:
375  self.exitRule()
376  return localctx
377 
378 
379 
380 
381 
parsers.asp.clingo.ClingoParser.ClingoParser.Answer_setContext.parser
parser
Definition: ClingoParser.py:81
parsers.asp.clingo.ClingoParser.ClingoParser
Definition: ClingoParser.py:31
parsers.asp.clingo.ClingoParser.ClingoParser.OutputContext
Definition: ClingoParser.py:175
parsers.asp.clingo.ClingoParser.ClingoParser.atn
atn
Definition: ClingoParser.py:35
parsers.asp.clingo.ClingoParser.ClingoParser.Answer_setContext
Definition: ClingoParser.py:77
parsers.asp.clingo.ClingoParser.ClingoParser.Predicate_atomContext.term
def term(self, i=None)
Definition: ClingoParser.py:237
parsers.asp.clingo.ClingoParser.ClingoParser.Predicate_atomContext.parser
parser
Definition: ClingoParser.py:229
parsers.asp.clingo.ClingoParser.ClingoParser._interp
_interp
Definition: ClingoParser.py:72
parsers.asp.clingo.ClingoParser.ClingoParser.sharedContextCache
sharedContextCache
Definition: ClingoParser.py:39
parsers.asp.clingo.ClingoParser.ClingoParser.TermContext
Definition: ClingoParser.py:306
parsers.asp.clingo.ClingoParser.ClingoParser.OutputContext.answer_set
def answer_set(self, i=None)
Definition: ClingoParser.py:181
parsers.asp.clingo.ClingoParser.ClingoParser.Predicate_atomContext
Definition: ClingoParser.py:225
parsers.asp.clingo.ClingoParser.ClingoParser.ModelContext.parser
parser
Definition: ClingoParser.py:124
parsers.asp.clingo.ClingoParser.ClingoParser.TermContext.predicate_atom
def predicate_atom(self)
Definition: ClingoParser.py:318
parsers.asp.clingo.ClingoParser.ClingoParser.ModelContext
Definition: ClingoParser.py:120
parsers.asp.clingo.ClingoParser.ClingoParser.TermContext.parser
parser
Definition: ClingoParser.py:310
parsers.asp.clingo.ClingoParser.ClingoParser.ModelContext.predicate_atom
def predicate_atom(self, i=None)
Definition: ClingoParser.py:129
parsers.asp.clingo.ClingoParser.ClingoParser._predicates
_predicates
Definition: ClingoParser.py:73
parsers.asp.clingo.ClingoParser.ClingoParser.OutputContext.parser
parser
Definition: ClingoParser.py:179
parsers.asp.clingo.ClingoParser.ClingoParser.decisionsToDFA
list decisionsToDFA
Definition: ClingoParser.py:37
parsers.asp.clingo.ClingoParser.ClingoParser.Answer_setContext.model
def model(self)
Definition: ClingoParser.py:86