00001
00002
00003 import sys
00004 from antlr3 import *
00005 from antlr3.compat import set, frozenset
00006
00007 import sys
00008 import traceback
00009
00010 from InterfaceLexer import InterfaceLexer
00011
00012 class Method(object):
00013 def __init__(self, name, return_fields, fields, attributes):
00014 self.name = name
00015 self.return_fields = return_fields
00016 self.fields = fields
00017 self.attributes = attributes
00018
00019 if (self.fields is None):
00020 self.fields = []
00021 if (self.return_fields is None):
00022 self.return_fields = []
00023 if (self.attributes is None):
00024 self.attributes = []
00025
00026 def __repr__(self):
00027 return "%s: ret: %s fields: %s attr: %s"%(self.name, self.return_fields, self.fields, self.attributes)
00028
00029 class Interface(object):
00030 def __init__(self, name):
00031 self.name = name
00032 self.methods = []
00033
00034 def __repr__(self):
00035 return "%s: %s"%(self.name, self.methods)
00036
00037
00038
00039
00040 HIDDEN = BaseRecognizer.HIDDEN
00041
00042
00043 CLOSEPAREN=9
00044 LETTER=17
00045 ATTRIBUTE=5
00046 OPENBRACKET=6
00047 WHITESPACE=4
00048 SEMICOLON=10
00049 ID=18
00050 EOF=-1
00051 CLOSEBRACKET=7
00052 SLASH=12
00053 COMMA=11
00054 MESSAGE=14
00055 INTERFACE=13
00056 DIGIT=16
00057 OPENPAREN=8
00058 COMMENT=19
00059 RETURNS=15
00060
00061
00062 tokenNames = [
00063 "<invalid>", "<EOR>", "<DOWN>", "<UP>",
00064 "WHITESPACE", "ATTRIBUTE", "OPENBRACKET", "CLOSEBRACKET", "OPENPAREN",
00065 "CLOSEPAREN", "SEMICOLON", "COMMA", "SLASH", "INTERFACE", "MESSAGE",
00066 "RETURNS", "DIGIT", "LETTER", "ID", "COMMENT"
00067 ]
00068
00069
00070
00071
00072 class InterfaceParser(Parser):
00073 grammarFileName = "/wg/bvu/jfaust/ros/dev/visualization-2.0/visualization/rve_interface_gen/antlr/InterfaceParser.g"
00074 antlr_version = version_str_to_tuple("3.1.2")
00075 antlr_version_str = "3.1.2"
00076 tokenNames = tokenNames
00077
00078 def __init__(self, input, state=None):
00079 if state is None:
00080 state = RecognizerSharedState()
00081
00082 Parser.__init__(self, input, state)
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 interfaces = []
00097
00098
00099 class method_return(ParserRuleReturnScope):
00100 def __init__(self):
00101 ParserRuleReturnScope.__init__(self)
00102
00103 self.name = None
00104 self.rs = None
00105 self.ps = None
00106 self.attrs = None
00107
00108
00109
00110
00111
00112
00113 def method(self, ):
00114
00115 retval = self.method_return()
00116 retval.start = self.input.LT(1)
00117
00118 attr = None
00119 my_name = None
00120 pvals = None
00121
00122 rvals = None
00123
00124
00125 try:
00126 try:
00127
00128
00129 pass
00130
00131
00132 retval.rs = []
00133 retval.ps = []
00134 retval.attrs = []
00135
00136
00137
00138 while True:
00139 alt1 = 2
00140 LA1_0 = self.input.LA(1)
00141
00142 if (LA1_0 == ATTRIBUTE) :
00143 alt1 = 1
00144
00145
00146 if alt1 == 1:
00147
00148 pass
00149 attr=self.match(self.input, ATTRIBUTE, self.FOLLOW_ATTRIBUTE_in_method78)
00150
00151
00152 retval.attrs.append(attr.text)
00153
00154
00155
00156
00157 else:
00158 break
00159
00160
00161 my_name=self.match(self.input, ID, self.FOLLOW_ID_in_method92)
00162
00163 retval.name = my_name.text
00164
00165 self.match(self.input, OPENPAREN, self.FOLLOW_OPENPAREN_in_method96)
00166 self._state.following.append(self.FOLLOW_parameter_list_in_method104)
00167 pvals = self.parameter_list()
00168
00169 self._state.following.pop()
00170
00171
00172 retval.ps = pvals
00173
00174
00175 self.match(self.input, CLOSEPAREN, self.FOLLOW_CLOSEPAREN_in_method112)
00176
00177 alt2 = 2
00178 LA2_0 = self.input.LA(1)
00179
00180 if (LA2_0 == RETURNS) :
00181 alt2 = 1
00182 if alt2 == 1:
00183
00184 pass
00185 self.match(self.input, RETURNS, self.FOLLOW_RETURNS_in_method115)
00186 self._state.following.append(self.FOLLOW_return_vals_in_method121)
00187 rvals = self.return_vals()
00188
00189 self._state.following.pop()
00190
00191 retval.rs = rvals
00192
00193
00194
00195
00196 self.match(self.input, SEMICOLON, self.FOLLOW_SEMICOLON_in_method127)
00197
00198
00199
00200 retval.stop = self.input.LT(-1)
00201
00202
00203 except RecognitionException, re:
00204 self.reportError(re)
00205 self.recover(self.input, re)
00206 finally:
00207
00208 pass
00209
00210 return retval
00211
00212
00213
00214
00215
00216
00217 def interface(self, ):
00218
00219 name = None
00220 mt = None
00221
00222
00223 try:
00224 try:
00225
00226
00227 pass
00228 self.match(self.input, INTERFACE, self.FOLLOW_INTERFACE_in_interface141)
00229 name=self.match(self.input, ID, self.FOLLOW_ID_in_interface145)
00230
00231 self.interfaces.append(Interface(name.text))
00232
00233 self.match(self.input, OPENBRACKET, self.FOLLOW_OPENBRACKET_in_interface149)
00234
00235 while True:
00236 alt3 = 2
00237 LA3_0 = self.input.LA(1)
00238
00239 if (LA3_0 == ATTRIBUTE or LA3_0 == ID) :
00240 alt3 = 1
00241
00242
00243 if alt3 == 1:
00244
00245 pass
00246 self._state.following.append(self.FOLLOW_method_in_interface162)
00247 mt = self.method()
00248
00249 self._state.following.pop()
00250
00251
00252 self.interfaces[-1].methods.append(Method(mt.name, mt.rs, mt.ps, mt.attrs))
00253
00254
00255
00256
00257 else:
00258 break
00259
00260
00261 self.match(self.input, CLOSEBRACKET, self.FOLLOW_CLOSEBRACKET_in_interface178)
00262
00263
00264
00265
00266 except RecognitionException, re:
00267 self.reportError(re)
00268 self.recover(self.input, re)
00269 finally:
00270
00271 pass
00272
00273 return
00274
00275
00276
00277
00278
00279
00280 def parameter_list(self, ):
00281
00282 params = None
00283
00284 i = None
00285 io = None
00286 tv = None
00287
00288 tvo = None
00289
00290
00291 try:
00292 try:
00293
00294 alt5 = 2
00295 LA5_0 = self.input.LA(1)
00296
00297 if (LA5_0 == CLOSEPAREN) :
00298 alt5 = 1
00299 elif (LA5_0 == ID) :
00300 alt5 = 2
00301 else:
00302 nvae = NoViableAltException("", 5, 0, self.input)
00303
00304 raise nvae
00305
00306 if alt5 == 1:
00307
00308 pass
00309
00310 elif alt5 == 2:
00311
00312 pass
00313 self._state.following.append(self.FOLLOW_type_in_parameter_list204)
00314 tv = self.type()
00315
00316 self._state.following.pop()
00317 i=self.match(self.input, ID, self.FOLLOW_ID_in_parameter_list210)
00318
00319 params = [(((tv is not None) and [self.input.toString(tv.start,tv.stop)] or [None])[0], i.text)]
00320
00321
00322 while True:
00323 alt4 = 2
00324 LA4_0 = self.input.LA(1)
00325
00326 if (LA4_0 == COMMA) :
00327 alt4 = 1
00328
00329
00330 if alt4 == 1:
00331
00332 pass
00333 self.match(self.input, COMMA, self.FOLLOW_COMMA_in_parameter_list215)
00334 self._state.following.append(self.FOLLOW_type_in_parameter_list221)
00335 tvo = self.type()
00336
00337 self._state.following.pop()
00338 io=self.match(self.input, ID, self.FOLLOW_ID_in_parameter_list227)
00339
00340 params.append((((tvo is not None) and [self.input.toString(tvo.start,tvo.stop)] or [None])[0], io.text))
00341
00342
00343
00344 else:
00345 break
00346
00347
00348
00349
00350
00351 except RecognitionException, re:
00352 self.reportError(re)
00353 self.recover(self.input, re)
00354 finally:
00355
00356 pass
00357
00358 return params
00359
00360
00361
00362
00363
00364
00365 def package_type(self, ):
00366
00367 t = None
00368
00369 pkg = None
00370 id = None
00371
00372 try:
00373 try:
00374
00375
00376 pass
00377 pkg=self.match(self.input, ID, self.FOLLOW_ID_in_package_type250)
00378 self.match(self.input, SLASH, self.FOLLOW_SLASH_in_package_type252)
00379 id=self.match(self.input, ID, self.FOLLOW_ID_in_package_type256)
00380
00381 t = '%s/%s'%(pkg, id)
00382
00383
00384
00385
00386
00387 except RecognitionException, re:
00388 self.reportError(re)
00389 self.recover(self.input, re)
00390 finally:
00391
00392 pass
00393
00394 return t
00395
00396
00397
00398 class type_return(ParserRuleReturnScope):
00399 def __init__(self):
00400 ParserRuleReturnScope.__init__(self)
00401
00402 self.type_name = None
00403
00404
00405
00406
00407
00408
00409 def type(self, ):
00410
00411 retval = self.type_return()
00412 retval.start = self.input.LT(1)
00413
00414 n = None
00415 np = None
00416
00417
00418 try:
00419 try:
00420
00421 alt6 = 2
00422 LA6_0 = self.input.LA(1)
00423
00424 if (LA6_0 == ID) :
00425 LA6_1 = self.input.LA(2)
00426
00427 if (LA6_1 == SLASH) :
00428 alt6 = 2
00429 elif (LA6_1 == ID) :
00430 alt6 = 1
00431 else:
00432 nvae = NoViableAltException("", 6, 1, self.input)
00433
00434 raise nvae
00435
00436 else:
00437 nvae = NoViableAltException("", 6, 0, self.input)
00438
00439 raise nvae
00440
00441 if alt6 == 1:
00442
00443 pass
00444 n=self.match(self.input, ID, self.FOLLOW_ID_in_type278)
00445
00446 retval.type_name = n
00447
00448
00449
00450 elif alt6 == 2:
00451
00452 pass
00453 self._state.following.append(self.FOLLOW_package_type_in_type289)
00454 np = self.package_type()
00455
00456 self._state.following.pop()
00457
00458 retval.type_name = np
00459
00460
00461
00462 retval.stop = self.input.LT(-1)
00463
00464
00465 except RecognitionException, re:
00466 self.reportError(re)
00467 self.recover(self.input, re)
00468 finally:
00469
00470 pass
00471
00472 return retval
00473
00474
00475
00476
00477
00478
00479 def return_vals(self, ):
00480
00481 rs = None
00482
00483 pl = None
00484
00485
00486 try:
00487 try:
00488
00489 alt7 = 2
00490 LA7_0 = self.input.LA(1)
00491
00492 if (LA7_0 == SEMICOLON) :
00493 alt7 = 1
00494 elif (LA7_0 == OPENPAREN) :
00495 alt7 = 2
00496 else:
00497 nvae = NoViableAltException("", 7, 0, self.input)
00498
00499 raise nvae
00500
00501 if alt7 == 1:
00502
00503 pass
00504
00505 elif alt7 == 2:
00506
00507 pass
00508 self.match(self.input, OPENPAREN, self.FOLLOW_OPENPAREN_in_return_vals311)
00509 self._state.following.append(self.FOLLOW_parameter_list_in_return_vals317)
00510 pl = self.parameter_list()
00511
00512 self._state.following.pop()
00513
00514 rs = pl
00515
00516 self.match(self.input, CLOSEPAREN, self.FOLLOW_CLOSEPAREN_in_return_vals321)
00517
00518
00519
00520 except RecognitionException, re:
00521 self.reportError(re)
00522 self.recover(self.input, re)
00523 finally:
00524
00525 pass
00526
00527 return rs
00528
00529
00530
00531
00532
00533
00534 def message(self, ):
00535
00536 try:
00537 try:
00538
00539
00540 pass
00541 self.match(self.input, MESSAGE, self.FOLLOW_MESSAGE_in_message334)
00542 self.match(self.input, ID, self.FOLLOW_ID_in_message336)
00543 self.match(self.input, OPENBRACKET, self.FOLLOW_OPENBRACKET_in_message338)
00544
00545 while True:
00546 alt8 = 2
00547 LA8_0 = self.input.LA(1)
00548
00549 if (LA8_0 == ID) :
00550 alt8 = 1
00551
00552
00553 if alt8 == 1:
00554
00555 pass
00556 self._state.following.append(self.FOLLOW_type_in_message341)
00557 self.type()
00558
00559 self._state.following.pop()
00560 self.match(self.input, ID, self.FOLLOW_ID_in_message343)
00561 self.match(self.input, SEMICOLON, self.FOLLOW_SEMICOLON_in_message345)
00562
00563
00564 else:
00565 break
00566
00567
00568 self.match(self.input, CLOSEBRACKET, self.FOLLOW_CLOSEBRACKET_in_message349)
00569
00570
00571
00572
00573 except RecognitionException, re:
00574 self.reportError(re)
00575 self.recover(self.input, re)
00576 finally:
00577
00578 pass
00579
00580 return
00581
00582
00583
00584
00585
00586
00587 def main(self, ):
00588
00589 try:
00590 try:
00591
00592
00593 pass
00594
00595 while True:
00596 alt9 = 3
00597 LA9_0 = self.input.LA(1)
00598
00599 if (LA9_0 == INTERFACE) :
00600 alt9 = 1
00601 elif (LA9_0 == MESSAGE) :
00602 alt9 = 2
00603
00604
00605 if alt9 == 1:
00606
00607 pass
00608 self._state.following.append(self.FOLLOW_interface_in_main363)
00609 self.interface()
00610
00611 self._state.following.pop()
00612
00613
00614 elif alt9 == 2:
00615
00616 pass
00617 self._state.following.append(self.FOLLOW_message_in_main367)
00618 self.message()
00619
00620 self._state.following.pop()
00621
00622
00623 else:
00624 break
00625
00626
00627 self.match(self.input, EOF, self.FOLLOW_EOF_in_main371)
00628
00629
00630
00631
00632 except RecognitionException, re:
00633 self.reportError(re)
00634 self.recover(self.input, re)
00635 finally:
00636
00637 pass
00638
00639 return
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649 FOLLOW_ATTRIBUTE_in_method78 = frozenset([5, 18])
00650 FOLLOW_ID_in_method92 = frozenset([8])
00651 FOLLOW_OPENPAREN_in_method96 = frozenset([9, 18])
00652 FOLLOW_parameter_list_in_method104 = frozenset([9])
00653 FOLLOW_CLOSEPAREN_in_method112 = frozenset([10, 15])
00654 FOLLOW_RETURNS_in_method115 = frozenset([8, 10])
00655 FOLLOW_return_vals_in_method121 = frozenset([10])
00656 FOLLOW_SEMICOLON_in_method127 = frozenset([1])
00657 FOLLOW_INTERFACE_in_interface141 = frozenset([18])
00658 FOLLOW_ID_in_interface145 = frozenset([6])
00659 FOLLOW_OPENBRACKET_in_interface149 = frozenset([5, 7, 18])
00660 FOLLOW_method_in_interface162 = frozenset([5, 7, 18])
00661 FOLLOW_CLOSEBRACKET_in_interface178 = frozenset([1])
00662 FOLLOW_type_in_parameter_list204 = frozenset([18])
00663 FOLLOW_ID_in_parameter_list210 = frozenset([1, 11])
00664 FOLLOW_COMMA_in_parameter_list215 = frozenset([18])
00665 FOLLOW_type_in_parameter_list221 = frozenset([18])
00666 FOLLOW_ID_in_parameter_list227 = frozenset([1, 11])
00667 FOLLOW_ID_in_package_type250 = frozenset([12])
00668 FOLLOW_SLASH_in_package_type252 = frozenset([18])
00669 FOLLOW_ID_in_package_type256 = frozenset([1])
00670 FOLLOW_ID_in_type278 = frozenset([1])
00671 FOLLOW_package_type_in_type289 = frozenset([1])
00672 FOLLOW_OPENPAREN_in_return_vals311 = frozenset([9, 18])
00673 FOLLOW_parameter_list_in_return_vals317 = frozenset([9])
00674 FOLLOW_CLOSEPAREN_in_return_vals321 = frozenset([1])
00675 FOLLOW_MESSAGE_in_message334 = frozenset([18])
00676 FOLLOW_ID_in_message336 = frozenset([6])
00677 FOLLOW_OPENBRACKET_in_message338 = frozenset([7, 18])
00678 FOLLOW_type_in_message341 = frozenset([18])
00679 FOLLOW_ID_in_message343 = frozenset([10])
00680 FOLLOW_SEMICOLON_in_message345 = frozenset([7, 18])
00681 FOLLOW_CLOSEBRACKET_in_message349 = frozenset([1])
00682 FOLLOW_interface_in_main363 = frozenset([13, 14])
00683 FOLLOW_message_in_main367 = frozenset([13, 14])
00684 FOLLOW_EOF_in_main371 = frozenset([1])
00685
00686
00687
00688
00689 def main(argv, otherArg=None):
00690 char_stream = ANTLRFileStream(sys.argv[1])
00691 lexer = InterfaceLexer(char_stream)
00692 tokens = CommonTokenStream(lexer)
00693 parser = InterfaceParser(tokens);
00694
00695 try:
00696 parser.main()
00697 except RecognitionException:
00698 traceback.print_stack()
00699
00700
00701 if __name__ == '__main__':
00702 main(sys.argv)