How to use end_rule method in Gherkin-python

Best Python code snippet using gherkin-python

parser.py

Source:parser.py Github

copy

Full Screen

...71 token = self.read_token(context)72 state = self.match_token(state, token, context)73 if token.eof():74 break75 self.end_rule(context, 'GherkinDocument')76 if context.errors:77 raise CompositeParserException(context.errors)78 return self.get_result()79 def build(self, context, token):80 self.handle_ast_error(context, token, self.ast_builder.build)81 def add_error(self, context, error):82 context.errors.append(error)83 if len(context.errors) > 10:84 raise CompositeParserException(context.errors)85 def start_rule(self, context, rule_type):86 self.handle_ast_error(context, rule_type, self.ast_builder.start_rule)87 def end_rule(self, context, rule_type):88 self.handle_ast_error(context, rule_type, self.ast_builder.end_rule)89 def get_result(self):90 return self.ast_builder.get_result()91 def read_token(self, context):92 if context.token_queue:93 return context.token_queue.popleft()94 else:95 return context.token_scanner.read()96 def match_EOF(self, context, token):97 return self.handle_external_error(context, False, token, context.token_matcher.match_EOF)98 def match_Empty(self, context, token):99 if token.eof():100 return False101 return self.handle_external_error(context, False, token, context.token_matcher.match_Empty)102 def match_Comment(self, context, token):103 if token.eof():104 return False105 return self.handle_external_error(context, False, token, context.token_matcher.match_Comment)106 def match_TagLine(self, context, token):107 if token.eof():108 return False109 return self.handle_external_error(context, False, token, context.token_matcher.match_TagLine)110 def match_FeatureLine(self, context, token):111 if token.eof():112 return False113 return self.handle_external_error(context, False, token, context.token_matcher.match_FeatureLine)114 def match_BackgroundLine(self, context, token):115 if token.eof():116 return False117 return self.handle_external_error(context, False, token, context.token_matcher.match_BackgroundLine)118 def match_ScenarioLine(self, context, token):119 if token.eof():120 return False121 return self.handle_external_error(context, False, token, context.token_matcher.match_ScenarioLine)122 def match_ScenarioOutlineLine(self, context, token):123 if token.eof():124 return False125 return self.handle_external_error(context, False, token, context.token_matcher.match_ScenarioOutlineLine)126 def match_ExamplesLine(self, context, token):127 if token.eof():128 return False129 return self.handle_external_error(context, False, token, context.token_matcher.match_ExamplesLine)130 def match_StepLine(self, context, token):131 if token.eof():132 return False133 return self.handle_external_error(context, False, token, context.token_matcher.match_StepLine)134 def match_DocStringSeparator(self, context, token):135 if token.eof():136 return False137 return self.handle_external_error(context, False, token, context.token_matcher.match_DocStringSeparator)138 def match_TableRow(self, context, token):139 if token.eof():140 return False141 return self.handle_external_error(context, False, token, context.token_matcher.match_TableRow)142 def match_Language(self, context, token):143 if token.eof():144 return False145 return self.handle_external_error(context, False, token, context.token_matcher.match_Language)146 def match_Other(self, context, token):147 if token.eof():148 return False149 return self.handle_external_error(context, False, token, context.token_matcher.match_Other)150 def match_token(self, state, token, context):151 state_map = {152 0: self.match_token_at_0,153 1: self.match_token_at_1,154 2: self.match_token_at_2,155 3: self.match_token_at_3,156 4: self.match_token_at_4,157 5: self.match_token_at_5,158 6: self.match_token_at_6,159 7: self.match_token_at_7,160 8: self.match_token_at_8,161 9: self.match_token_at_9,162 10: self.match_token_at_10,163 11: self.match_token_at_11,164 12: self.match_token_at_12,165 13: self.match_token_at_13,166 14: self.match_token_at_14,167 15: self.match_token_at_15,168 16: self.match_token_at_16,169 17: self.match_token_at_17,170 18: self.match_token_at_18,171 19: self.match_token_at_19,172 20: self.match_token_at_20,173 21: self.match_token_at_21,174 22: self.match_token_at_22,175 23: self.match_token_at_23,176 24: self.match_token_at_24,177 25: self.match_token_at_25,178 26: self.match_token_at_26,179 28: self.match_token_at_28,180 29: self.match_token_at_29,181 30: self.match_token_at_30,182 31: self.match_token_at_31,183 32: self.match_token_at_32,184 33: self.match_token_at_33,185 }186 if state in state_map:187 return state_map[state](token, context)188 else:189 raise RuntimeError("Unknown state: " + str(state))190 # Start191 def match_token_at_0(self, token, context):192 if self.match_EOF(context, token):193 self.build(context, token)194 return 27195 if self.match_Language(context, token):196 self.start_rule(context, 'Feature')197 self.start_rule(context, 'Feature_Header')198 self.build(context, token)199 return 1200 if self.match_TagLine(context, token):201 self.start_rule(context, 'Feature')202 self.start_rule(context, 'Feature_Header')203 self.start_rule(context, 'Tags')204 self.build(context, token)205 return 2206 if self.match_FeatureLine(context, token):207 self.start_rule(context, 'Feature')208 self.start_rule(context, 'Feature_Header')209 self.build(context, token)210 return 3211 if self.match_Comment(context, token):212 self.build(context, token)213 return 0214 if self.match_Empty(context, token):215 self.build(context, token)216 return 0217 state_comment = "State: 0 - Start"218 token.detach219 expected_tokens = ["#EOF", "#Language", "#TagLine", "#FeatureLine", "#Comment", "#Empty"]220 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)221 if (self.stop_at_first_error):222 raise error223 self.add_error(context, error)224 return 0225 # GherkinDocument:0>Feature:0>Feature_Header:0>#Language:0226 def match_token_at_1(self, token, context):227 if self.match_TagLine(context, token):228 self.start_rule(context, 'Tags')229 self.build(context, token)230 return 2231 if self.match_FeatureLine(context, token):232 self.build(context, token)233 return 3234 if self.match_Comment(context, token):235 self.build(context, token)236 return 1237 if self.match_Empty(context, token):238 self.build(context, token)239 return 1240 state_comment = "State: 1 - GherkinDocument:0>Feature:0>Feature_Header:0>#Language:0"241 token.detach242 expected_tokens = ["#TagLine", "#FeatureLine", "#Comment", "#Empty"]243 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)244 if (self.stop_at_first_error):245 raise error246 self.add_error(context, error)247 return 1248 # GherkinDocument:0>Feature:0>Feature_Header:1>Tags:0>#TagLine:0249 def match_token_at_2(self, token, context):250 if self.match_TagLine(context, token):251 self.build(context, token)252 return 2253 if self.match_FeatureLine(context, token):254 self.end_rule(context, 'Tags')255 self.build(context, token)256 return 3257 if self.match_Comment(context, token):258 self.build(context, token)259 return 2260 if self.match_Empty(context, token):261 self.build(context, token)262 return 2263 state_comment = "State: 2 - GherkinDocument:0>Feature:0>Feature_Header:1>Tags:0>#TagLine:0"264 token.detach265 expected_tokens = ["#TagLine", "#FeatureLine", "#Comment", "#Empty"]266 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)267 if (self.stop_at_first_error):268 raise error269 self.add_error(context, error)270 return 2271 # GherkinDocument:0>Feature:0>Feature_Header:2>#FeatureLine:0272 def match_token_at_3(self, token, context):273 if self.match_EOF(context, token):274 self.end_rule(context, 'Feature_Header')275 self.end_rule(context, 'Feature')276 self.build(context, token)277 return 27278 if self.match_Empty(context, token):279 self.build(context, token)280 return 3281 if self.match_Comment(context, token):282 self.build(context, token)283 return 5284 if self.match_BackgroundLine(context, token):285 self.end_rule(context, 'Feature_Header')286 self.start_rule(context, 'Background')287 self.build(context, token)288 return 6289 if self.match_TagLine(context, token):290 self.end_rule(context, 'Feature_Header')291 self.start_rule(context, 'Scenario_Definition')292 self.start_rule(context, 'Tags')293 self.build(context, token)294 return 11295 if self.match_ScenarioLine(context, token):296 self.end_rule(context, 'Feature_Header')297 self.start_rule(context, 'Scenario_Definition')298 self.start_rule(context, 'Scenario')299 self.build(context, token)300 return 12301 if self.match_ScenarioOutlineLine(context, token):302 self.end_rule(context, 'Feature_Header')303 self.start_rule(context, 'Scenario_Definition')304 self.start_rule(context, 'ScenarioOutline')305 self.build(context, token)306 return 17307 if self.match_Other(context, token):308 self.start_rule(context, 'Description')309 self.build(context, token)310 return 4311 state_comment = "State: 3 - GherkinDocument:0>Feature:0>Feature_Header:2>#FeatureLine:0"312 token.detach313 expected_tokens = ["#EOF", "#Empty", "#Comment", "#BackgroundLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]314 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)315 if (self.stop_at_first_error):316 raise error317 self.add_error(context, error)318 return 3319 # GherkinDocument:0>Feature:0>Feature_Header:3>Feature_Description:0>Description_Helper:1>Description:0>#Other:0320 def match_token_at_4(self, token, context):321 if self.match_EOF(context, token):322 self.end_rule(context, 'Description')323 self.end_rule(context, 'Feature_Header')324 self.end_rule(context, 'Feature')325 self.build(context, token)326 return 27327 if self.match_Comment(context, token):328 self.end_rule(context, 'Description')329 self.build(context, token)330 return 5331 if self.match_BackgroundLine(context, token):332 self.end_rule(context, 'Description')333 self.end_rule(context, 'Feature_Header')334 self.start_rule(context, 'Background')335 self.build(context, token)336 return 6337 if self.match_TagLine(context, token):338 self.end_rule(context, 'Description')339 self.end_rule(context, 'Feature_Header')340 self.start_rule(context, 'Scenario_Definition')341 self.start_rule(context, 'Tags')342 self.build(context, token)343 return 11344 if self.match_ScenarioLine(context, token):345 self.end_rule(context, 'Description')346 self.end_rule(context, 'Feature_Header')347 self.start_rule(context, 'Scenario_Definition')348 self.start_rule(context, 'Scenario')349 self.build(context, token)350 return 12351 if self.match_ScenarioOutlineLine(context, token):352 self.end_rule(context, 'Description')353 self.end_rule(context, 'Feature_Header')354 self.start_rule(context, 'Scenario_Definition')355 self.start_rule(context, 'ScenarioOutline')356 self.build(context, token)357 return 17358 if self.match_Other(context, token):359 self.build(context, token)360 return 4361 state_comment = "State: 4 - GherkinDocument:0>Feature:0>Feature_Header:3>Feature_Description:0>Description_Helper:1>Description:0>#Other:0"362 token.detach363 expected_tokens = ["#EOF", "#Comment", "#BackgroundLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]364 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)365 if (self.stop_at_first_error):366 raise error367 self.add_error(context, error)368 return 4369 # GherkinDocument:0>Feature:0>Feature_Header:3>Feature_Description:0>Description_Helper:2>#Comment:0370 def match_token_at_5(self, token, context):371 if self.match_EOF(context, token):372 self.end_rule(context, 'Feature_Header')373 self.end_rule(context, 'Feature')374 self.build(context, token)375 return 27376 if self.match_Comment(context, token):377 self.build(context, token)378 return 5379 if self.match_BackgroundLine(context, token):380 self.end_rule(context, 'Feature_Header')381 self.start_rule(context, 'Background')382 self.build(context, token)383 return 6384 if self.match_TagLine(context, token):385 self.end_rule(context, 'Feature_Header')386 self.start_rule(context, 'Scenario_Definition')387 self.start_rule(context, 'Tags')388 self.build(context, token)389 return 11390 if self.match_ScenarioLine(context, token):391 self.end_rule(context, 'Feature_Header')392 self.start_rule(context, 'Scenario_Definition')393 self.start_rule(context, 'Scenario')394 self.build(context, token)395 return 12396 if self.match_ScenarioOutlineLine(context, token):397 self.end_rule(context, 'Feature_Header')398 self.start_rule(context, 'Scenario_Definition')399 self.start_rule(context, 'ScenarioOutline')400 self.build(context, token)401 return 17402 if self.match_Empty(context, token):403 self.build(context, token)404 return 5405 state_comment = "State: 5 - GherkinDocument:0>Feature:0>Feature_Header:3>Feature_Description:0>Description_Helper:2>#Comment:0"406 token.detach407 expected_tokens = ["#EOF", "#Comment", "#BackgroundLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Empty"]408 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)409 if (self.stop_at_first_error):410 raise error411 self.add_error(context, error)412 return 5413 # GherkinDocument:0>Feature:1>Background:0>#BackgroundLine:0414 def match_token_at_6(self, token, context):415 if self.match_EOF(context, token):416 self.end_rule(context, 'Background')417 self.end_rule(context, 'Feature')418 self.build(context, token)419 return 27420 if self.match_Empty(context, token):421 self.build(context, token)422 return 6423 if self.match_Comment(context, token):424 self.build(context, token)425 return 8426 if self.match_StepLine(context, token):427 self.start_rule(context, 'Step')428 self.build(context, token)429 return 9430 if self.match_TagLine(context, token):431 self.end_rule(context, 'Background')432 self.start_rule(context, 'Scenario_Definition')433 self.start_rule(context, 'Tags')434 self.build(context, token)435 return 11436 if self.match_ScenarioLine(context, token):437 self.end_rule(context, 'Background')438 self.start_rule(context, 'Scenario_Definition')439 self.start_rule(context, 'Scenario')440 self.build(context, token)441 return 12442 if self.match_ScenarioOutlineLine(context, token):443 self.end_rule(context, 'Background')444 self.start_rule(context, 'Scenario_Definition')445 self.start_rule(context, 'ScenarioOutline')446 self.build(context, token)447 return 17448 if self.match_Other(context, token):449 self.start_rule(context, 'Description')450 self.build(context, token)451 return 7452 state_comment = "State: 6 - GherkinDocument:0>Feature:1>Background:0>#BackgroundLine:0"453 token.detach454 expected_tokens = ["#EOF", "#Empty", "#Comment", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]455 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)456 if (self.stop_at_first_error):457 raise error458 self.add_error(context, error)459 return 6460 # GherkinDocument:0>Feature:1>Background:1>Background_Description:0>Description_Helper:1>Description:0>#Other:0461 def match_token_at_7(self, token, context):462 if self.match_EOF(context, token):463 self.end_rule(context, 'Description')464 self.end_rule(context, 'Background')465 self.end_rule(context, 'Feature')466 self.build(context, token)467 return 27468 if self.match_Comment(context, token):469 self.end_rule(context, 'Description')470 self.build(context, token)471 return 8472 if self.match_StepLine(context, token):473 self.end_rule(context, 'Description')474 self.start_rule(context, 'Step')475 self.build(context, token)476 return 9477 if self.match_TagLine(context, token):478 self.end_rule(context, 'Description')479 self.end_rule(context, 'Background')480 self.start_rule(context, 'Scenario_Definition')481 self.start_rule(context, 'Tags')482 self.build(context, token)483 return 11484 if self.match_ScenarioLine(context, token):485 self.end_rule(context, 'Description')486 self.end_rule(context, 'Background')487 self.start_rule(context, 'Scenario_Definition')488 self.start_rule(context, 'Scenario')489 self.build(context, token)490 return 12491 if self.match_ScenarioOutlineLine(context, token):492 self.end_rule(context, 'Description')493 self.end_rule(context, 'Background')494 self.start_rule(context, 'Scenario_Definition')495 self.start_rule(context, 'ScenarioOutline')496 self.build(context, token)497 return 17498 if self.match_Other(context, token):499 self.build(context, token)500 return 7501 state_comment = "State: 7 - GherkinDocument:0>Feature:1>Background:1>Background_Description:0>Description_Helper:1>Description:0>#Other:0"502 token.detach503 expected_tokens = ["#EOF", "#Comment", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]504 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)505 if (self.stop_at_first_error):506 raise error507 self.add_error(context, error)508 return 7509 # GherkinDocument:0>Feature:1>Background:1>Background_Description:0>Description_Helper:2>#Comment:0510 def match_token_at_8(self, token, context):511 if self.match_EOF(context, token):512 self.end_rule(context, 'Background')513 self.end_rule(context, 'Feature')514 self.build(context, token)515 return 27516 if self.match_Comment(context, token):517 self.build(context, token)518 return 8519 if self.match_StepLine(context, token):520 self.start_rule(context, 'Step')521 self.build(context, token)522 return 9523 if self.match_TagLine(context, token):524 self.end_rule(context, 'Background')525 self.start_rule(context, 'Scenario_Definition')526 self.start_rule(context, 'Tags')527 self.build(context, token)528 return 11529 if self.match_ScenarioLine(context, token):530 self.end_rule(context, 'Background')531 self.start_rule(context, 'Scenario_Definition')532 self.start_rule(context, 'Scenario')533 self.build(context, token)534 return 12535 if self.match_ScenarioOutlineLine(context, token):536 self.end_rule(context, 'Background')537 self.start_rule(context, 'Scenario_Definition')538 self.start_rule(context, 'ScenarioOutline')539 self.build(context, token)540 return 17541 if self.match_Empty(context, token):542 self.build(context, token)543 return 8544 state_comment = "State: 8 - GherkinDocument:0>Feature:1>Background:1>Background_Description:0>Description_Helper:2>#Comment:0"545 token.detach546 expected_tokens = ["#EOF", "#Comment", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Empty"]547 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)548 if (self.stop_at_first_error):549 raise error550 self.add_error(context, error)551 return 8552 # GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:0>#StepLine:0553 def match_token_at_9(self, token, context):554 if self.match_EOF(context, token):555 self.end_rule(context, 'Step')556 self.end_rule(context, 'Background')557 self.end_rule(context, 'Feature')558 self.build(context, token)559 return 27560 if self.match_TableRow(context, token):561 self.start_rule(context, 'DataTable')562 self.build(context, token)563 return 10564 if self.match_DocStringSeparator(context, token):565 self.start_rule(context, 'DocString')566 self.build(context, token)567 return 32568 if self.match_StepLine(context, token):569 self.end_rule(context, 'Step')570 self.start_rule(context, 'Step')571 self.build(context, token)572 return 9573 if self.match_TagLine(context, token):574 self.end_rule(context, 'Step')575 self.end_rule(context, 'Background')576 self.start_rule(context, 'Scenario_Definition')577 self.start_rule(context, 'Tags')578 self.build(context, token)579 return 11580 if self.match_ScenarioLine(context, token):581 self.end_rule(context, 'Step')582 self.end_rule(context, 'Background')583 self.start_rule(context, 'Scenario_Definition')584 self.start_rule(context, 'Scenario')585 self.build(context, token)586 return 12587 if self.match_ScenarioOutlineLine(context, token):588 self.end_rule(context, 'Step')589 self.end_rule(context, 'Background')590 self.start_rule(context, 'Scenario_Definition')591 self.start_rule(context, 'ScenarioOutline')592 self.build(context, token)593 return 17594 if self.match_Comment(context, token):595 self.build(context, token)596 return 9597 if self.match_Empty(context, token):598 self.build(context, token)599 return 9600 state_comment = "State: 9 - GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:0>#StepLine:0"601 token.detach602 expected_tokens = ["#EOF", "#TableRow", "#DocStringSeparator", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]603 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)604 if (self.stop_at_first_error):605 raise error606 self.add_error(context, error)607 return 9608 # GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:0>DataTable:0>#TableRow:0609 def match_token_at_10(self, token, context):610 if self.match_EOF(context, token):611 self.end_rule(context, 'DataTable')612 self.end_rule(context, 'Step')613 self.end_rule(context, 'Background')614 self.end_rule(context, 'Feature')615 self.build(context, token)616 return 27617 if self.match_TableRow(context, token):618 self.build(context, token)619 return 10620 if self.match_StepLine(context, token):621 self.end_rule(context, 'DataTable')622 self.end_rule(context, 'Step')623 self.start_rule(context, 'Step')624 self.build(context, token)625 return 9626 if self.match_TagLine(context, token):627 self.end_rule(context, 'DataTable')628 self.end_rule(context, 'Step')629 self.end_rule(context, 'Background')630 self.start_rule(context, 'Scenario_Definition')631 self.start_rule(context, 'Tags')632 self.build(context, token)633 return 11634 if self.match_ScenarioLine(context, token):635 self.end_rule(context, 'DataTable')636 self.end_rule(context, 'Step')637 self.end_rule(context, 'Background')638 self.start_rule(context, 'Scenario_Definition')639 self.start_rule(context, 'Scenario')640 self.build(context, token)641 return 12642 if self.match_ScenarioOutlineLine(context, token):643 self.end_rule(context, 'DataTable')644 self.end_rule(context, 'Step')645 self.end_rule(context, 'Background')646 self.start_rule(context, 'Scenario_Definition')647 self.start_rule(context, 'ScenarioOutline')648 self.build(context, token)649 return 17650 if self.match_Comment(context, token):651 self.build(context, token)652 return 10653 if self.match_Empty(context, token):654 self.build(context, token)655 return 10656 state_comment = "State: 10 - GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:0>DataTable:0>#TableRow:0"657 token.detach658 expected_tokens = ["#EOF", "#TableRow", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]659 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)660 if (self.stop_at_first_error):661 raise error662 self.add_error(context, error)663 return 10664 # GherkinDocument:0>Feature:2>Scenario_Definition:0>Tags:0>#TagLine:0665 def match_token_at_11(self, token, context):666 if self.match_TagLine(context, token):667 self.build(context, token)668 return 11669 if self.match_ScenarioLine(context, token):670 self.end_rule(context, 'Tags')671 self.start_rule(context, 'Scenario')672 self.build(context, token)673 return 12674 if self.match_ScenarioOutlineLine(context, token):675 self.end_rule(context, 'Tags')676 self.start_rule(context, 'ScenarioOutline')677 self.build(context, token)678 return 17679 if self.match_Comment(context, token):680 self.build(context, token)681 return 11682 if self.match_Empty(context, token):683 self.build(context, token)684 return 11685 state_comment = "State: 11 - GherkinDocument:0>Feature:2>Scenario_Definition:0>Tags:0>#TagLine:0"686 token.detach687 expected_tokens = ["#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]688 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)689 if (self.stop_at_first_error):690 raise error691 self.add_error(context, error)692 return 11693 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:0>#ScenarioLine:0694 def match_token_at_12(self, token, context):695 if self.match_EOF(context, token):696 self.end_rule(context, 'Scenario')697 self.end_rule(context, 'Scenario_Definition')698 self.end_rule(context, 'Feature')699 self.build(context, token)700 return 27701 if self.match_Empty(context, token):702 self.build(context, token)703 return 12704 if self.match_Comment(context, token):705 self.build(context, token)706 return 14707 if self.match_StepLine(context, token):708 self.start_rule(context, 'Step')709 self.build(context, token)710 return 15711 if self.match_TagLine(context, token):712 self.end_rule(context, 'Scenario')713 self.end_rule(context, 'Scenario_Definition')714 self.start_rule(context, 'Scenario_Definition')715 self.start_rule(context, 'Tags')716 self.build(context, token)717 return 11718 if self.match_ScenarioLine(context, token):719 self.end_rule(context, 'Scenario')720 self.end_rule(context, 'Scenario_Definition')721 self.start_rule(context, 'Scenario_Definition')722 self.start_rule(context, 'Scenario')723 self.build(context, token)724 return 12725 if self.match_ScenarioOutlineLine(context, token):726 self.end_rule(context, 'Scenario')727 self.end_rule(context, 'Scenario_Definition')728 self.start_rule(context, 'Scenario_Definition')729 self.start_rule(context, 'ScenarioOutline')730 self.build(context, token)731 return 17732 if self.match_Other(context, token):733 self.start_rule(context, 'Description')734 self.build(context, token)735 return 13736 state_comment = "State: 12 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:0>#ScenarioLine:0"737 token.detach738 expected_tokens = ["#EOF", "#Empty", "#Comment", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]739 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)740 if (self.stop_at_first_error):741 raise error742 self.add_error(context, error)743 return 12744 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:1>Scenario_Description:0>Description_Helper:1>Description:0>#Other:0745 def match_token_at_13(self, token, context):746 if self.match_EOF(context, token):747 self.end_rule(context, 'Description')748 self.end_rule(context, 'Scenario')749 self.end_rule(context, 'Scenario_Definition')750 self.end_rule(context, 'Feature')751 self.build(context, token)752 return 27753 if self.match_Comment(context, token):754 self.end_rule(context, 'Description')755 self.build(context, token)756 return 14757 if self.match_StepLine(context, token):758 self.end_rule(context, 'Description')759 self.start_rule(context, 'Step')760 self.build(context, token)761 return 15762 if self.match_TagLine(context, token):763 self.end_rule(context, 'Description')764 self.end_rule(context, 'Scenario')765 self.end_rule(context, 'Scenario_Definition')766 self.start_rule(context, 'Scenario_Definition')767 self.start_rule(context, 'Tags')768 self.build(context, token)769 return 11770 if self.match_ScenarioLine(context, token):771 self.end_rule(context, 'Description')772 self.end_rule(context, 'Scenario')773 self.end_rule(context, 'Scenario_Definition')774 self.start_rule(context, 'Scenario_Definition')775 self.start_rule(context, 'Scenario')776 self.build(context, token)777 return 12778 if self.match_ScenarioOutlineLine(context, token):779 self.end_rule(context, 'Description')780 self.end_rule(context, 'Scenario')781 self.end_rule(context, 'Scenario_Definition')782 self.start_rule(context, 'Scenario_Definition')783 self.start_rule(context, 'ScenarioOutline')784 self.build(context, token)785 return 17786 if self.match_Other(context, token):787 self.build(context, token)788 return 13789 state_comment = "State: 13 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:1>Scenario_Description:0>Description_Helper:1>Description:0>#Other:0"790 token.detach791 expected_tokens = ["#EOF", "#Comment", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]792 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)793 if (self.stop_at_first_error):794 raise error795 self.add_error(context, error)796 return 13797 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:1>Scenario_Description:0>Description_Helper:2>#Comment:0798 def match_token_at_14(self, token, context):799 if self.match_EOF(context, token):800 self.end_rule(context, 'Scenario')801 self.end_rule(context, 'Scenario_Definition')802 self.end_rule(context, 'Feature')803 self.build(context, token)804 return 27805 if self.match_Comment(context, token):806 self.build(context, token)807 return 14808 if self.match_StepLine(context, token):809 self.start_rule(context, 'Step')810 self.build(context, token)811 return 15812 if self.match_TagLine(context, token):813 self.end_rule(context, 'Scenario')814 self.end_rule(context, 'Scenario_Definition')815 self.start_rule(context, 'Scenario_Definition')816 self.start_rule(context, 'Tags')817 self.build(context, token)818 return 11819 if self.match_ScenarioLine(context, token):820 self.end_rule(context, 'Scenario')821 self.end_rule(context, 'Scenario_Definition')822 self.start_rule(context, 'Scenario_Definition')823 self.start_rule(context, 'Scenario')824 self.build(context, token)825 return 12826 if self.match_ScenarioOutlineLine(context, token):827 self.end_rule(context, 'Scenario')828 self.end_rule(context, 'Scenario_Definition')829 self.start_rule(context, 'Scenario_Definition')830 self.start_rule(context, 'ScenarioOutline')831 self.build(context, token)832 return 17833 if self.match_Empty(context, token):834 self.build(context, token)835 return 14836 state_comment = "State: 14 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:1>Scenario_Description:0>Description_Helper:2>#Comment:0"837 token.detach838 expected_tokens = ["#EOF", "#Comment", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Empty"]839 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)840 if (self.stop_at_first_error):841 raise error842 self.add_error(context, error)843 return 14844 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:0>#StepLine:0845 def match_token_at_15(self, token, context):846 if self.match_EOF(context, token):847 self.end_rule(context, 'Step')848 self.end_rule(context, 'Scenario')849 self.end_rule(context, 'Scenario_Definition')850 self.end_rule(context, 'Feature')851 self.build(context, token)852 return 27853 if self.match_TableRow(context, token):854 self.start_rule(context, 'DataTable')855 self.build(context, token)856 return 16857 if self.match_DocStringSeparator(context, token):858 self.start_rule(context, 'DocString')859 self.build(context, token)860 return 30861 if self.match_StepLine(context, token):862 self.end_rule(context, 'Step')863 self.start_rule(context, 'Step')864 self.build(context, token)865 return 15866 if self.match_TagLine(context, token):867 self.end_rule(context, 'Step')868 self.end_rule(context, 'Scenario')869 self.end_rule(context, 'Scenario_Definition')870 self.start_rule(context, 'Scenario_Definition')871 self.start_rule(context, 'Tags')872 self.build(context, token)873 return 11874 if self.match_ScenarioLine(context, token):875 self.end_rule(context, 'Step')876 self.end_rule(context, 'Scenario')877 self.end_rule(context, 'Scenario_Definition')878 self.start_rule(context, 'Scenario_Definition')879 self.start_rule(context, 'Scenario')880 self.build(context, token)881 return 12882 if self.match_ScenarioOutlineLine(context, token):883 self.end_rule(context, 'Step')884 self.end_rule(context, 'Scenario')885 self.end_rule(context, 'Scenario_Definition')886 self.start_rule(context, 'Scenario_Definition')887 self.start_rule(context, 'ScenarioOutline')888 self.build(context, token)889 return 17890 if self.match_Comment(context, token):891 self.build(context, token)892 return 15893 if self.match_Empty(context, token):894 self.build(context, token)895 return 15896 state_comment = "State: 15 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:0>#StepLine:0"897 token.detach898 expected_tokens = ["#EOF", "#TableRow", "#DocStringSeparator", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]899 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)900 if (self.stop_at_first_error):901 raise error902 self.add_error(context, error)903 return 15904 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:0>DataTable:0>#TableRow:0905 def match_token_at_16(self, token, context):906 if self.match_EOF(context, token):907 self.end_rule(context, 'DataTable')908 self.end_rule(context, 'Step')909 self.end_rule(context, 'Scenario')910 self.end_rule(context, 'Scenario_Definition')911 self.end_rule(context, 'Feature')912 self.build(context, token)913 return 27914 if self.match_TableRow(context, token):915 self.build(context, token)916 return 16917 if self.match_StepLine(context, token):918 self.end_rule(context, 'DataTable')919 self.end_rule(context, 'Step')920 self.start_rule(context, 'Step')921 self.build(context, token)922 return 15923 if self.match_TagLine(context, token):924 self.end_rule(context, 'DataTable')925 self.end_rule(context, 'Step')926 self.end_rule(context, 'Scenario')927 self.end_rule(context, 'Scenario_Definition')928 self.start_rule(context, 'Scenario_Definition')929 self.start_rule(context, 'Tags')930 self.build(context, token)931 return 11932 if self.match_ScenarioLine(context, token):933 self.end_rule(context, 'DataTable')934 self.end_rule(context, 'Step')935 self.end_rule(context, 'Scenario')936 self.end_rule(context, 'Scenario_Definition')937 self.start_rule(context, 'Scenario_Definition')938 self.start_rule(context, 'Scenario')939 self.build(context, token)940 return 12941 if self.match_ScenarioOutlineLine(context, token):942 self.end_rule(context, 'DataTable')943 self.end_rule(context, 'Step')944 self.end_rule(context, 'Scenario')945 self.end_rule(context, 'Scenario_Definition')946 self.start_rule(context, 'Scenario_Definition')947 self.start_rule(context, 'ScenarioOutline')948 self.build(context, token)949 return 17950 if self.match_Comment(context, token):951 self.build(context, token)952 return 16953 if self.match_Empty(context, token):954 self.build(context, token)955 return 16956 state_comment = "State: 16 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:0>DataTable:0>#TableRow:0"957 token.detach958 expected_tokens = ["#EOF", "#TableRow", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]959 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)960 if (self.stop_at_first_error):961 raise error962 self.add_error(context, error)963 return 16964 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:0>#ScenarioOutlineLine:0965 def match_token_at_17(self, token, context):966 if self.match_EOF(context, token):967 self.end_rule(context, 'ScenarioOutline')968 self.end_rule(context, 'Scenario_Definition')969 self.end_rule(context, 'Feature')970 self.build(context, token)971 return 27972 if self.match_Empty(context, token):973 self.build(context, token)974 return 17975 if self.match_Comment(context, token):976 self.build(context, token)977 return 19978 if self.match_StepLine(context, token):979 self.start_rule(context, 'Step')980 self.build(context, token)981 return 20982 if self.match_TagLine(context, token):983 if self.lookahead_0(context, token):984 self.start_rule(context, 'Examples_Definition')985 self.start_rule(context, 'Tags')986 self.build(context, token)987 return 22988 if self.match_TagLine(context, token):989 self.end_rule(context, 'ScenarioOutline')990 self.end_rule(context, 'Scenario_Definition')991 self.start_rule(context, 'Scenario_Definition')992 self.start_rule(context, 'Tags')993 self.build(context, token)994 return 11995 if self.match_ExamplesLine(context, token):996 self.start_rule(context, 'Examples_Definition')997 self.start_rule(context, 'Examples')998 self.build(context, token)999 return 231000 if self.match_ScenarioLine(context, token):1001 self.end_rule(context, 'ScenarioOutline')1002 self.end_rule(context, 'Scenario_Definition')1003 self.start_rule(context, 'Scenario_Definition')1004 self.start_rule(context, 'Scenario')1005 self.build(context, token)1006 return 121007 if self.match_ScenarioOutlineLine(context, token):1008 self.end_rule(context, 'ScenarioOutline')1009 self.end_rule(context, 'Scenario_Definition')1010 self.start_rule(context, 'Scenario_Definition')1011 self.start_rule(context, 'ScenarioOutline')1012 self.build(context, token)1013 return 171014 if self.match_Other(context, token):1015 self.start_rule(context, 'Description')1016 self.build(context, token)1017 return 181018 state_comment = "State: 17 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:0>#ScenarioOutlineLine:0"1019 token.detach1020 expected_tokens = ["#EOF", "#Empty", "#Comment", "#StepLine", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]1021 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1022 if (self.stop_at_first_error):1023 raise error1024 self.add_error(context, error)1025 return 171026 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:1>ScenarioOutline_Description:0>Description_Helper:1>Description:0>#Other:01027 def match_token_at_18(self, token, context):1028 if self.match_EOF(context, token):1029 self.end_rule(context, 'Description')1030 self.end_rule(context, 'ScenarioOutline')1031 self.end_rule(context, 'Scenario_Definition')1032 self.end_rule(context, 'Feature')1033 self.build(context, token)1034 return 271035 if self.match_Comment(context, token):1036 self.end_rule(context, 'Description')1037 self.build(context, token)1038 return 191039 if self.match_StepLine(context, token):1040 self.end_rule(context, 'Description')1041 self.start_rule(context, 'Step')1042 self.build(context, token)1043 return 201044 if self.match_TagLine(context, token):1045 if self.lookahead_0(context, token):1046 self.end_rule(context, 'Description')1047 self.start_rule(context, 'Examples_Definition')1048 self.start_rule(context, 'Tags')1049 self.build(context, token)1050 return 221051 if self.match_TagLine(context, token):1052 self.end_rule(context, 'Description')1053 self.end_rule(context, 'ScenarioOutline')1054 self.end_rule(context, 'Scenario_Definition')1055 self.start_rule(context, 'Scenario_Definition')1056 self.start_rule(context, 'Tags')1057 self.build(context, token)1058 return 111059 if self.match_ExamplesLine(context, token):1060 self.end_rule(context, 'Description')1061 self.start_rule(context, 'Examples_Definition')1062 self.start_rule(context, 'Examples')1063 self.build(context, token)1064 return 231065 if self.match_ScenarioLine(context, token):1066 self.end_rule(context, 'Description')1067 self.end_rule(context, 'ScenarioOutline')1068 self.end_rule(context, 'Scenario_Definition')1069 self.start_rule(context, 'Scenario_Definition')1070 self.start_rule(context, 'Scenario')1071 self.build(context, token)1072 return 121073 if self.match_ScenarioOutlineLine(context, token):1074 self.end_rule(context, 'Description')1075 self.end_rule(context, 'ScenarioOutline')1076 self.end_rule(context, 'Scenario_Definition')1077 self.start_rule(context, 'Scenario_Definition')1078 self.start_rule(context, 'ScenarioOutline')1079 self.build(context, token)1080 return 171081 if self.match_Other(context, token):1082 self.build(context, token)1083 return 181084 state_comment = "State: 18 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:1>ScenarioOutline_Description:0>Description_Helper:1>Description:0>#Other:0"1085 token.detach1086 expected_tokens = ["#EOF", "#Comment", "#StepLine", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]1087 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1088 if (self.stop_at_first_error):1089 raise error1090 self.add_error(context, error)1091 return 181092 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:1>ScenarioOutline_Description:0>Description_Helper:2>#Comment:01093 def match_token_at_19(self, token, context):1094 if self.match_EOF(context, token):1095 self.end_rule(context, 'ScenarioOutline')1096 self.end_rule(context, 'Scenario_Definition')1097 self.end_rule(context, 'Feature')1098 self.build(context, token)1099 return 271100 if self.match_Comment(context, token):1101 self.build(context, token)1102 return 191103 if self.match_StepLine(context, token):1104 self.start_rule(context, 'Step')1105 self.build(context, token)1106 return 201107 if self.match_TagLine(context, token):1108 if self.lookahead_0(context, token):1109 self.start_rule(context, 'Examples_Definition')1110 self.start_rule(context, 'Tags')1111 self.build(context, token)1112 return 221113 if self.match_TagLine(context, token):1114 self.end_rule(context, 'ScenarioOutline')1115 self.end_rule(context, 'Scenario_Definition')1116 self.start_rule(context, 'Scenario_Definition')1117 self.start_rule(context, 'Tags')1118 self.build(context, token)1119 return 111120 if self.match_ExamplesLine(context, token):1121 self.start_rule(context, 'Examples_Definition')1122 self.start_rule(context, 'Examples')1123 self.build(context, token)1124 return 231125 if self.match_ScenarioLine(context, token):1126 self.end_rule(context, 'ScenarioOutline')1127 self.end_rule(context, 'Scenario_Definition')1128 self.start_rule(context, 'Scenario_Definition')1129 self.start_rule(context, 'Scenario')1130 self.build(context, token)1131 return 121132 if self.match_ScenarioOutlineLine(context, token):1133 self.end_rule(context, 'ScenarioOutline')1134 self.end_rule(context, 'Scenario_Definition')1135 self.start_rule(context, 'Scenario_Definition')1136 self.start_rule(context, 'ScenarioOutline')1137 self.build(context, token)1138 return 171139 if self.match_Empty(context, token):1140 self.build(context, token)1141 return 191142 state_comment = "State: 19 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:1>ScenarioOutline_Description:0>Description_Helper:2>#Comment:0"1143 token.detach1144 expected_tokens = ["#EOF", "#Comment", "#StepLine", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Empty"]1145 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1146 if (self.stop_at_first_error):1147 raise error1148 self.add_error(context, error)1149 return 191150 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:0>#StepLine:01151 def match_token_at_20(self, token, context):1152 if self.match_EOF(context, token):1153 self.end_rule(context, 'Step')1154 self.end_rule(context, 'ScenarioOutline')1155 self.end_rule(context, 'Scenario_Definition')1156 self.end_rule(context, 'Feature')1157 self.build(context, token)1158 return 271159 if self.match_TableRow(context, token):1160 self.start_rule(context, 'DataTable')1161 self.build(context, token)1162 return 211163 if self.match_DocStringSeparator(context, token):1164 self.start_rule(context, 'DocString')1165 self.build(context, token)1166 return 281167 if self.match_StepLine(context, token):1168 self.end_rule(context, 'Step')1169 self.start_rule(context, 'Step')1170 self.build(context, token)1171 return 201172 if self.match_TagLine(context, token):1173 if self.lookahead_0(context, token):1174 self.end_rule(context, 'Step')1175 self.start_rule(context, 'Examples_Definition')1176 self.start_rule(context, 'Tags')1177 self.build(context, token)1178 return 221179 if self.match_TagLine(context, token):1180 self.end_rule(context, 'Step')1181 self.end_rule(context, 'ScenarioOutline')1182 self.end_rule(context, 'Scenario_Definition')1183 self.start_rule(context, 'Scenario_Definition')1184 self.start_rule(context, 'Tags')1185 self.build(context, token)1186 return 111187 if self.match_ExamplesLine(context, token):1188 self.end_rule(context, 'Step')1189 self.start_rule(context, 'Examples_Definition')1190 self.start_rule(context, 'Examples')1191 self.build(context, token)1192 return 231193 if self.match_ScenarioLine(context, token):1194 self.end_rule(context, 'Step')1195 self.end_rule(context, 'ScenarioOutline')1196 self.end_rule(context, 'Scenario_Definition')1197 self.start_rule(context, 'Scenario_Definition')1198 self.start_rule(context, 'Scenario')1199 self.build(context, token)1200 return 121201 if self.match_ScenarioOutlineLine(context, token):1202 self.end_rule(context, 'Step')1203 self.end_rule(context, 'ScenarioOutline')1204 self.end_rule(context, 'Scenario_Definition')1205 self.start_rule(context, 'Scenario_Definition')1206 self.start_rule(context, 'ScenarioOutline')1207 self.build(context, token)1208 return 171209 if self.match_Comment(context, token):1210 self.build(context, token)1211 return 201212 if self.match_Empty(context, token):1213 self.build(context, token)1214 return 201215 state_comment = "State: 20 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:0>#StepLine:0"1216 token.detach1217 expected_tokens = ["#EOF", "#TableRow", "#DocStringSeparator", "#StepLine", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]1218 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1219 if (self.stop_at_first_error):1220 raise error1221 self.add_error(context, error)1222 return 201223 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:1>Step_Arg:0>__alt1:0>DataTable:0>#TableRow:01224 def match_token_at_21(self, token, context):1225 if self.match_EOF(context, token):1226 self.end_rule(context, 'DataTable')1227 self.end_rule(context, 'Step')1228 self.end_rule(context, 'ScenarioOutline')1229 self.end_rule(context, 'Scenario_Definition')1230 self.end_rule(context, 'Feature')1231 self.build(context, token)1232 return 271233 if self.match_TableRow(context, token):1234 self.build(context, token)1235 return 211236 if self.match_StepLine(context, token):1237 self.end_rule(context, 'DataTable')1238 self.end_rule(context, 'Step')1239 self.start_rule(context, 'Step')1240 self.build(context, token)1241 return 201242 if self.match_TagLine(context, token):1243 if self.lookahead_0(context, token):1244 self.end_rule(context, 'DataTable')1245 self.end_rule(context, 'Step')1246 self.start_rule(context, 'Examples_Definition')1247 self.start_rule(context, 'Tags')1248 self.build(context, token)1249 return 221250 if self.match_TagLine(context, token):1251 self.end_rule(context, 'DataTable')1252 self.end_rule(context, 'Step')1253 self.end_rule(context, 'ScenarioOutline')1254 self.end_rule(context, 'Scenario_Definition')1255 self.start_rule(context, 'Scenario_Definition')1256 self.start_rule(context, 'Tags')1257 self.build(context, token)1258 return 111259 if self.match_ExamplesLine(context, token):1260 self.end_rule(context, 'DataTable')1261 self.end_rule(context, 'Step')1262 self.start_rule(context, 'Examples_Definition')1263 self.start_rule(context, 'Examples')1264 self.build(context, token)1265 return 231266 if self.match_ScenarioLine(context, token):1267 self.end_rule(context, 'DataTable')1268 self.end_rule(context, 'Step')1269 self.end_rule(context, 'ScenarioOutline')1270 self.end_rule(context, 'Scenario_Definition')1271 self.start_rule(context, 'Scenario_Definition')1272 self.start_rule(context, 'Scenario')1273 self.build(context, token)1274 return 121275 if self.match_ScenarioOutlineLine(context, token):1276 self.end_rule(context, 'DataTable')1277 self.end_rule(context, 'Step')1278 self.end_rule(context, 'ScenarioOutline')1279 self.end_rule(context, 'Scenario_Definition')1280 self.start_rule(context, 'Scenario_Definition')1281 self.start_rule(context, 'ScenarioOutline')1282 self.build(context, token)1283 return 171284 if self.match_Comment(context, token):1285 self.build(context, token)1286 return 211287 if self.match_Empty(context, token):1288 self.build(context, token)1289 return 211290 state_comment = "State: 21 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:1>Step_Arg:0>__alt1:0>DataTable:0>#TableRow:0"1291 token.detach1292 expected_tokens = ["#EOF", "#TableRow", "#StepLine", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]1293 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1294 if (self.stop_at_first_error):1295 raise error1296 self.add_error(context, error)1297 return 211298 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:0>Tags:0>#TagLine:01299 def match_token_at_22(self, token, context):1300 if self.match_TagLine(context, token):1301 self.build(context, token)1302 return 221303 if self.match_ExamplesLine(context, token):1304 self.end_rule(context, 'Tags')1305 self.start_rule(context, 'Examples')1306 self.build(context, token)1307 return 231308 if self.match_Comment(context, token):1309 self.build(context, token)1310 return 221311 if self.match_Empty(context, token):1312 self.build(context, token)1313 return 221314 state_comment = "State: 22 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:0>Tags:0>#TagLine:0"1315 token.detach1316 expected_tokens = ["#TagLine", "#ExamplesLine", "#Comment", "#Empty"]1317 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1318 if (self.stop_at_first_error):1319 raise error1320 self.add_error(context, error)1321 return 221322 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:0>#ExamplesLine:01323 def match_token_at_23(self, token, context):1324 if self.match_EOF(context, token):1325 self.end_rule(context, 'Examples')1326 self.end_rule(context, 'Examples_Definition')1327 self.end_rule(context, 'ScenarioOutline')1328 self.end_rule(context, 'Scenario_Definition')1329 self.end_rule(context, 'Feature')1330 self.build(context, token)1331 return 271332 if self.match_Empty(context, token):1333 self.build(context, token)1334 return 231335 if self.match_Comment(context, token):1336 self.build(context, token)1337 return 251338 if self.match_TableRow(context, token):1339 self.start_rule(context, 'Examples_Table')1340 self.build(context, token)1341 return 261342 if self.match_TagLine(context, token):1343 if self.lookahead_0(context, token):1344 self.end_rule(context, 'Examples')1345 self.end_rule(context, 'Examples_Definition')1346 self.start_rule(context, 'Examples_Definition')1347 self.start_rule(context, 'Tags')1348 self.build(context, token)1349 return 221350 if self.match_TagLine(context, token):1351 self.end_rule(context, 'Examples')1352 self.end_rule(context, 'Examples_Definition')1353 self.end_rule(context, 'ScenarioOutline')1354 self.end_rule(context, 'Scenario_Definition')1355 self.start_rule(context, 'Scenario_Definition')1356 self.start_rule(context, 'Tags')1357 self.build(context, token)1358 return 111359 if self.match_ExamplesLine(context, token):1360 self.end_rule(context, 'Examples')1361 self.end_rule(context, 'Examples_Definition')1362 self.start_rule(context, 'Examples_Definition')1363 self.start_rule(context, 'Examples')1364 self.build(context, token)1365 return 231366 if self.match_ScenarioLine(context, token):1367 self.end_rule(context, 'Examples')1368 self.end_rule(context, 'Examples_Definition')1369 self.end_rule(context, 'ScenarioOutline')1370 self.end_rule(context, 'Scenario_Definition')1371 self.start_rule(context, 'Scenario_Definition')1372 self.start_rule(context, 'Scenario')1373 self.build(context, token)1374 return 121375 if self.match_ScenarioOutlineLine(context, token):1376 self.end_rule(context, 'Examples')1377 self.end_rule(context, 'Examples_Definition')1378 self.end_rule(context, 'ScenarioOutline')1379 self.end_rule(context, 'Scenario_Definition')1380 self.start_rule(context, 'Scenario_Definition')1381 self.start_rule(context, 'ScenarioOutline')1382 self.build(context, token)1383 return 171384 if self.match_Other(context, token):1385 self.start_rule(context, 'Description')1386 self.build(context, token)1387 return 241388 state_comment = "State: 23 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:0>#ExamplesLine:0"1389 token.detach1390 expected_tokens = ["#EOF", "#Empty", "#Comment", "#TableRow", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]1391 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1392 if (self.stop_at_first_error):1393 raise error1394 self.add_error(context, error)1395 return 231396 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:1>Examples_Description:0>Description_Helper:1>Description:0>#Other:01397 def match_token_at_24(self, token, context):1398 if self.match_EOF(context, token):1399 self.end_rule(context, 'Description')1400 self.end_rule(context, 'Examples')1401 self.end_rule(context, 'Examples_Definition')1402 self.end_rule(context, 'ScenarioOutline')1403 self.end_rule(context, 'Scenario_Definition')1404 self.end_rule(context, 'Feature')1405 self.build(context, token)1406 return 271407 if self.match_Comment(context, token):1408 self.end_rule(context, 'Description')1409 self.build(context, token)1410 return 251411 if self.match_TableRow(context, token):1412 self.end_rule(context, 'Description')1413 self.start_rule(context, 'Examples_Table')1414 self.build(context, token)1415 return 261416 if self.match_TagLine(context, token):1417 if self.lookahead_0(context, token):1418 self.end_rule(context, 'Description')1419 self.end_rule(context, 'Examples')1420 self.end_rule(context, 'Examples_Definition')1421 self.start_rule(context, 'Examples_Definition')1422 self.start_rule(context, 'Tags')1423 self.build(context, token)1424 return 221425 if self.match_TagLine(context, token):1426 self.end_rule(context, 'Description')1427 self.end_rule(context, 'Examples')1428 self.end_rule(context, 'Examples_Definition')1429 self.end_rule(context, 'ScenarioOutline')1430 self.end_rule(context, 'Scenario_Definition')1431 self.start_rule(context, 'Scenario_Definition')1432 self.start_rule(context, 'Tags')1433 self.build(context, token)1434 return 111435 if self.match_ExamplesLine(context, token):1436 self.end_rule(context, 'Description')1437 self.end_rule(context, 'Examples')1438 self.end_rule(context, 'Examples_Definition')1439 self.start_rule(context, 'Examples_Definition')1440 self.start_rule(context, 'Examples')1441 self.build(context, token)1442 return 231443 if self.match_ScenarioLine(context, token):1444 self.end_rule(context, 'Description')1445 self.end_rule(context, 'Examples')1446 self.end_rule(context, 'Examples_Definition')1447 self.end_rule(context, 'ScenarioOutline')1448 self.end_rule(context, 'Scenario_Definition')1449 self.start_rule(context, 'Scenario_Definition')1450 self.start_rule(context, 'Scenario')1451 self.build(context, token)1452 return 121453 if self.match_ScenarioOutlineLine(context, token):1454 self.end_rule(context, 'Description')1455 self.end_rule(context, 'Examples')1456 self.end_rule(context, 'Examples_Definition')1457 self.end_rule(context, 'ScenarioOutline')1458 self.end_rule(context, 'Scenario_Definition')1459 self.start_rule(context, 'Scenario_Definition')1460 self.start_rule(context, 'ScenarioOutline')1461 self.build(context, token)1462 return 171463 if self.match_Other(context, token):1464 self.build(context, token)1465 return 241466 state_comment = "State: 24 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:1>Examples_Description:0>Description_Helper:1>Description:0>#Other:0"1467 token.detach1468 expected_tokens = ["#EOF", "#Comment", "#TableRow", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Other"]1469 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1470 if (self.stop_at_first_error):1471 raise error1472 self.add_error(context, error)1473 return 241474 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:1>Examples_Description:0>Description_Helper:2>#Comment:01475 def match_token_at_25(self, token, context):1476 if self.match_EOF(context, token):1477 self.end_rule(context, 'Examples')1478 self.end_rule(context, 'Examples_Definition')1479 self.end_rule(context, 'ScenarioOutline')1480 self.end_rule(context, 'Scenario_Definition')1481 self.end_rule(context, 'Feature')1482 self.build(context, token)1483 return 271484 if self.match_Comment(context, token):1485 self.build(context, token)1486 return 251487 if self.match_TableRow(context, token):1488 self.start_rule(context, 'Examples_Table')1489 self.build(context, token)1490 return 261491 if self.match_TagLine(context, token):1492 if self.lookahead_0(context, token):1493 self.end_rule(context, 'Examples')1494 self.end_rule(context, 'Examples_Definition')1495 self.start_rule(context, 'Examples_Definition')1496 self.start_rule(context, 'Tags')1497 self.build(context, token)1498 return 221499 if self.match_TagLine(context, token):1500 self.end_rule(context, 'Examples')1501 self.end_rule(context, 'Examples_Definition')1502 self.end_rule(context, 'ScenarioOutline')1503 self.end_rule(context, 'Scenario_Definition')1504 self.start_rule(context, 'Scenario_Definition')1505 self.start_rule(context, 'Tags')1506 self.build(context, token)1507 return 111508 if self.match_ExamplesLine(context, token):1509 self.end_rule(context, 'Examples')1510 self.end_rule(context, 'Examples_Definition')1511 self.start_rule(context, 'Examples_Definition')1512 self.start_rule(context, 'Examples')1513 self.build(context, token)1514 return 231515 if self.match_ScenarioLine(context, token):1516 self.end_rule(context, 'Examples')1517 self.end_rule(context, 'Examples_Definition')1518 self.end_rule(context, 'ScenarioOutline')1519 self.end_rule(context, 'Scenario_Definition')1520 self.start_rule(context, 'Scenario_Definition')1521 self.start_rule(context, 'Scenario')1522 self.build(context, token)1523 return 121524 if self.match_ScenarioOutlineLine(context, token):1525 self.end_rule(context, 'Examples')1526 self.end_rule(context, 'Examples_Definition')1527 self.end_rule(context, 'ScenarioOutline')1528 self.end_rule(context, 'Scenario_Definition')1529 self.start_rule(context, 'Scenario_Definition')1530 self.start_rule(context, 'ScenarioOutline')1531 self.build(context, token)1532 return 171533 if self.match_Empty(context, token):1534 self.build(context, token)1535 return 251536 state_comment = "State: 25 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:1>Examples_Description:0>Description_Helper:2>#Comment:0"1537 token.detach1538 expected_tokens = ["#EOF", "#Comment", "#TableRow", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Empty"]1539 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1540 if (self.stop_at_first_error):1541 raise error1542 self.add_error(context, error)1543 return 251544 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:2>Examples_Table:0>#TableRow:01545 def match_token_at_26(self, token, context):1546 if self.match_EOF(context, token):1547 self.end_rule(context, 'Examples_Table')1548 self.end_rule(context, 'Examples')1549 self.end_rule(context, 'Examples_Definition')1550 self.end_rule(context, 'ScenarioOutline')1551 self.end_rule(context, 'Scenario_Definition')1552 self.end_rule(context, 'Feature')1553 self.build(context, token)1554 return 271555 if self.match_TableRow(context, token):1556 self.build(context, token)1557 return 261558 if self.match_TagLine(context, token):1559 if self.lookahead_0(context, token):1560 self.end_rule(context, 'Examples_Table')1561 self.end_rule(context, 'Examples')1562 self.end_rule(context, 'Examples_Definition')1563 self.start_rule(context, 'Examples_Definition')1564 self.start_rule(context, 'Tags')1565 self.build(context, token)1566 return 221567 if self.match_TagLine(context, token):1568 self.end_rule(context, 'Examples_Table')1569 self.end_rule(context, 'Examples')1570 self.end_rule(context, 'Examples_Definition')1571 self.end_rule(context, 'ScenarioOutline')1572 self.end_rule(context, 'Scenario_Definition')1573 self.start_rule(context, 'Scenario_Definition')1574 self.start_rule(context, 'Tags')1575 self.build(context, token)1576 return 111577 if self.match_ExamplesLine(context, token):1578 self.end_rule(context, 'Examples_Table')1579 self.end_rule(context, 'Examples')1580 self.end_rule(context, 'Examples_Definition')1581 self.start_rule(context, 'Examples_Definition')1582 self.start_rule(context, 'Examples')1583 self.build(context, token)1584 return 231585 if self.match_ScenarioLine(context, token):1586 self.end_rule(context, 'Examples_Table')1587 self.end_rule(context, 'Examples')1588 self.end_rule(context, 'Examples_Definition')1589 self.end_rule(context, 'ScenarioOutline')1590 self.end_rule(context, 'Scenario_Definition')1591 self.start_rule(context, 'Scenario_Definition')1592 self.start_rule(context, 'Scenario')1593 self.build(context, token)1594 return 121595 if self.match_ScenarioOutlineLine(context, token):1596 self.end_rule(context, 'Examples_Table')1597 self.end_rule(context, 'Examples')1598 self.end_rule(context, 'Examples_Definition')1599 self.end_rule(context, 'ScenarioOutline')1600 self.end_rule(context, 'Scenario_Definition')1601 self.start_rule(context, 'Scenario_Definition')1602 self.start_rule(context, 'ScenarioOutline')1603 self.build(context, token)1604 return 171605 if self.match_Comment(context, token):1606 self.build(context, token)1607 return 261608 if self.match_Empty(context, token):1609 self.build(context, token)1610 return 261611 state_comment = "State: 26 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:3>Examples_Definition:1>Examples:2>Examples_Table:0>#TableRow:0"1612 token.detach1613 expected_tokens = ["#EOF", "#TableRow", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]1614 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1615 if (self.stop_at_first_error):1616 raise error1617 self.add_error(context, error)1618 return 261619 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:0>#DocStringSeparator:01620 def match_token_at_28(self, token, context):1621 if self.match_DocStringSeparator(context, token):1622 self.build(context, token)1623 return 291624 if self.match_Other(context, token):1625 self.build(context, token)1626 return 281627 state_comment = "State: 28 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:0>#DocStringSeparator:0"1628 token.detach1629 expected_tokens = ["#DocStringSeparator", "#Other"]1630 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1631 if (self.stop_at_first_error):1632 raise error1633 self.add_error(context, error)1634 return 281635 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:2>#DocStringSeparator:01636 def match_token_at_29(self, token, context):1637 if self.match_EOF(context, token):1638 self.end_rule(context, 'DocString')1639 self.end_rule(context, 'Step')1640 self.end_rule(context, 'ScenarioOutline')1641 self.end_rule(context, 'Scenario_Definition')1642 self.end_rule(context, 'Feature')1643 self.build(context, token)1644 return 271645 if self.match_StepLine(context, token):1646 self.end_rule(context, 'DocString')1647 self.end_rule(context, 'Step')1648 self.start_rule(context, 'Step')1649 self.build(context, token)1650 return 201651 if self.match_TagLine(context, token):1652 if self.lookahead_0(context, token):1653 self.end_rule(context, 'DocString')1654 self.end_rule(context, 'Step')1655 self.start_rule(context, 'Examples_Definition')1656 self.start_rule(context, 'Tags')1657 self.build(context, token)1658 return 221659 if self.match_TagLine(context, token):1660 self.end_rule(context, 'DocString')1661 self.end_rule(context, 'Step')1662 self.end_rule(context, 'ScenarioOutline')1663 self.end_rule(context, 'Scenario_Definition')1664 self.start_rule(context, 'Scenario_Definition')1665 self.start_rule(context, 'Tags')1666 self.build(context, token)1667 return 111668 if self.match_ExamplesLine(context, token):1669 self.end_rule(context, 'DocString')1670 self.end_rule(context, 'Step')1671 self.start_rule(context, 'Examples_Definition')1672 self.start_rule(context, 'Examples')1673 self.build(context, token)1674 return 231675 if self.match_ScenarioLine(context, token):1676 self.end_rule(context, 'DocString')1677 self.end_rule(context, 'Step')1678 self.end_rule(context, 'ScenarioOutline')1679 self.end_rule(context, 'Scenario_Definition')1680 self.start_rule(context, 'Scenario_Definition')1681 self.start_rule(context, 'Scenario')1682 self.build(context, token)1683 return 121684 if self.match_ScenarioOutlineLine(context, token):1685 self.end_rule(context, 'DocString')1686 self.end_rule(context, 'Step')1687 self.end_rule(context, 'ScenarioOutline')1688 self.end_rule(context, 'Scenario_Definition')1689 self.start_rule(context, 'Scenario_Definition')1690 self.start_rule(context, 'ScenarioOutline')1691 self.build(context, token)1692 return 171693 if self.match_Comment(context, token):1694 self.build(context, token)1695 return 291696 if self.match_Empty(context, token):1697 self.build(context, token)1698 return 291699 state_comment = "State: 29 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:1>ScenarioOutline:2>ScenarioOutline_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:2>#DocStringSeparator:0"1700 token.detach1701 expected_tokens = ["#EOF", "#StepLine", "#TagLine", "#ExamplesLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]1702 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1703 if (self.stop_at_first_error):1704 raise error1705 self.add_error(context, error)1706 return 291707 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:0>#DocStringSeparator:01708 def match_token_at_30(self, token, context):1709 if self.match_DocStringSeparator(context, token):1710 self.build(context, token)1711 return 311712 if self.match_Other(context, token):1713 self.build(context, token)1714 return 301715 state_comment = "State: 30 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:0>#DocStringSeparator:0"1716 token.detach1717 expected_tokens = ["#DocStringSeparator", "#Other"]1718 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1719 if (self.stop_at_first_error):1720 raise error1721 self.add_error(context, error)1722 return 301723 # GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:2>#DocStringSeparator:01724 def match_token_at_31(self, token, context):1725 if self.match_EOF(context, token):1726 self.end_rule(context, 'DocString')1727 self.end_rule(context, 'Step')1728 self.end_rule(context, 'Scenario')1729 self.end_rule(context, 'Scenario_Definition')1730 self.end_rule(context, 'Feature')1731 self.build(context, token)1732 return 271733 if self.match_StepLine(context, token):1734 self.end_rule(context, 'DocString')1735 self.end_rule(context, 'Step')1736 self.start_rule(context, 'Step')1737 self.build(context, token)1738 return 151739 if self.match_TagLine(context, token):1740 self.end_rule(context, 'DocString')1741 self.end_rule(context, 'Step')1742 self.end_rule(context, 'Scenario')1743 self.end_rule(context, 'Scenario_Definition')1744 self.start_rule(context, 'Scenario_Definition')1745 self.start_rule(context, 'Tags')1746 self.build(context, token)1747 return 111748 if self.match_ScenarioLine(context, token):1749 self.end_rule(context, 'DocString')1750 self.end_rule(context, 'Step')1751 self.end_rule(context, 'Scenario')1752 self.end_rule(context, 'Scenario_Definition')1753 self.start_rule(context, 'Scenario_Definition')1754 self.start_rule(context, 'Scenario')1755 self.build(context, token)1756 return 121757 if self.match_ScenarioOutlineLine(context, token):1758 self.end_rule(context, 'DocString')1759 self.end_rule(context, 'Step')1760 self.end_rule(context, 'Scenario')1761 self.end_rule(context, 'Scenario_Definition')1762 self.start_rule(context, 'Scenario_Definition')1763 self.start_rule(context, 'ScenarioOutline')1764 self.build(context, token)1765 return 171766 if self.match_Comment(context, token):1767 self.build(context, token)1768 return 311769 if self.match_Empty(context, token):1770 self.build(context, token)1771 return 311772 state_comment = "State: 31 - GherkinDocument:0>Feature:2>Scenario_Definition:1>__alt0:0>Scenario:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:2>#DocStringSeparator:0"1773 token.detach1774 expected_tokens = ["#EOF", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]1775 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1776 if (self.stop_at_first_error):1777 raise error1778 self.add_error(context, error)1779 return 311780 # GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:0>#DocStringSeparator:01781 def match_token_at_32(self, token, context):1782 if self.match_DocStringSeparator(context, token):1783 self.build(context, token)1784 return 331785 if self.match_Other(context, token):1786 self.build(context, token)1787 return 321788 state_comment = "State: 32 - GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:0>#DocStringSeparator:0"1789 token.detach1790 expected_tokens = ["#DocStringSeparator", "#Other"]1791 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)1792 if (self.stop_at_first_error):1793 raise error1794 self.add_error(context, error)1795 return 321796 # GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:2>#DocStringSeparator:01797 def match_token_at_33(self, token, context):1798 if self.match_EOF(context, token):1799 self.end_rule(context, 'DocString')1800 self.end_rule(context, 'Step')1801 self.end_rule(context, 'Background')1802 self.end_rule(context, 'Feature')1803 self.build(context, token)1804 return 271805 if self.match_StepLine(context, token):1806 self.end_rule(context, 'DocString')1807 self.end_rule(context, 'Step')1808 self.start_rule(context, 'Step')1809 self.build(context, token)1810 return 91811 if self.match_TagLine(context, token):1812 self.end_rule(context, 'DocString')1813 self.end_rule(context, 'Step')1814 self.end_rule(context, 'Background')1815 self.start_rule(context, 'Scenario_Definition')1816 self.start_rule(context, 'Tags')1817 self.build(context, token)1818 return 111819 if self.match_ScenarioLine(context, token):1820 self.end_rule(context, 'DocString')1821 self.end_rule(context, 'Step')1822 self.end_rule(context, 'Background')1823 self.start_rule(context, 'Scenario_Definition')1824 self.start_rule(context, 'Scenario')1825 self.build(context, token)1826 return 121827 if self.match_ScenarioOutlineLine(context, token):1828 self.end_rule(context, 'DocString')1829 self.end_rule(context, 'Step')1830 self.end_rule(context, 'Background')1831 self.start_rule(context, 'Scenario_Definition')1832 self.start_rule(context, 'ScenarioOutline')1833 self.build(context, token)1834 return 171835 if self.match_Comment(context, token):1836 self.build(context, token)1837 return 331838 if self.match_Empty(context, token):1839 self.build(context, token)1840 return 331841 state_comment = "State: 33 - GherkinDocument:0>Feature:1>Background:2>Scenario_Step:0>Step:1>Step_Arg:0>__alt1:1>DocString:2>#DocStringSeparator:0"1842 token.detach1843 expected_tokens = ["#EOF", "#StepLine", "#TagLine", "#ScenarioLine", "#ScenarioOutlineLine", "#Comment", "#Empty"]1844 error = UnexpectedEOFException(token, expected_tokens, state_comment) if token.eof() else UnexpectedTokenException(token, expected_tokens, state_comment)...

Full Screen

Full Screen

FullOnewayMeshTest.py

Source:FullOnewayMeshTest.py Github

copy

Full Screen

1#!/usr/bin/env python2"""3:Author Patrik Valkovic4:Created 22.08.2017 21:145:Licence GNUv36Part of grammpy-transforms7"""8from inspect import isclass9from unittest import main, TestCase10from grammpy import *11from grammpy_transforms import ContextFree12class S(Nonterminal): pass13class A(Nonterminal): pass14class B(Nonterminal): pass15class C(Nonterminal): pass16class Rules(Rule):17 rules = [18 ([S], [0, B, 0]),19 ([S], [A]),20 ([A], [0, A]),21 ([A], [B]),22 ([B], [1, B]),23 ([B], [A, B]),24 ([B], [C]),25 ([B], [EPS]),26 ([C], [1, A]),27 ([C], [1])]28"""29 ---------------------------------30 | S | A | B | C |31----------------------------------32S| [] | [2] | [2,4] |[2,4,7]|33----------------------------------34A| | [] | [4] | [4,7] |35----------------------------------36B| | | [] | [7] |37----------------------------------38C| | | | [] |39----------------------------------40S->0B0 S->A A->0A A->B B->1B B->AB B->C B->EPS C->1A C->141 ---- ---- ---- 42 43S->A->0A44S->A->B->1B45S->A->B->AB46S->A->B->eps47S->A->B->C->1A48S->A->B->C->149A->B->1B50A->B->AB51A->B->eps52A->B->C->1A53A->B->C->1 54B->C->1A55B->C->1 56"""57class SimpleTest(TestCase):58 def test_simpleTest(self):59 g = Grammar(terminals=[0, 1],60 nonterminals=[S, A, B, C],61 rules=[Rules],62 start_symbol=S)63 com = ContextFree.remove_unit_rules(g)64 # Removed65 class RuleStoA(Rule): rule=([S], [A])66 self.assertFalse(com.have_rule(RuleStoA))67 class RuleAtoB(Rule): rule=([A], [B])68 self.assertFalse(com.have_rule(RuleAtoB))69 class RuleBtoC(Rule): rule=([B], [C])70 self.assertFalse(com.have_rule(RuleBtoC))71 # Old rules72 class RuleNewSto0B0(Rule): rule = ([S], [0, B, 0])73 self.assertTrue(com.have_rule(RuleNewSto0B0))74 class RuleNewAto0A(Rule): rule = ([A], [0, A])75 self.assertTrue(com.have_rule(RuleNewAto0A))76 class RuleNewBto1B(Rule): rule = ([B], [1, B])77 self.assertTrue(com.have_rule(RuleNewBto1B))78 class RuleNewBtoAB(Rule): rule = ([B], [A, B])79 self.assertTrue(com.have_rule(RuleNewBtoAB))80 class RuleNewBtoEPS(Rule): rule = ([B], [EPS])81 self.assertTrue(com.have_rule(RuleNewBtoEPS))82 class RuleNewCto1A(Rule): rule = ([C], [1, A])83 self.assertTrue(com.have_rule(RuleNewCto1A))84 class RuleNewCto1(Rule): rule = ([C], [1])85 self.assertTrue(com.have_rule(RuleNewCto1))86 # New rules87 class RuleNewSto0A(Rule): rule = ([S], [0, A])88 self.assertTrue(com.have_rule(RuleNewSto0A))89 fromSto0A = com.get_rule(RuleNewSto0A)90 self.assertTrue(isclass(fromSto0A))91 self.assertTrue(issubclass(fromSto0A, ContextFree.ReducedUnitRule))92 self.assertEqual(len(fromSto0A.by_rules), 1)93 self.assertEqual(fromSto0A.by_rules[0].rule, ([S], [A]))94 self.assertEqual(fromSto0A.end_rule.rule, ([A], [0, A]))95 class RuleNewSto1B(Rule): rule = ([S], [1, B])96 self.assertTrue(com.have_rule(RuleNewSto1B))97 fromSto1B = com.get_rule(RuleNewSto1B)98 self.assertTrue(isclass(fromSto1B))99 self.assertTrue(issubclass(fromSto1B, ContextFree.ReducedUnitRule))100 self.assertEqual(len(fromSto1B.by_rules), 2)101 self.assertEqual(fromSto1B.by_rules[0].rule, ([S], [A]))102 self.assertEqual(fromSto1B.by_rules[1].rule, ([A], [B]))103 self.assertEqual(fromSto1B.end_rule.rule, ([B], [1, B]))104 class RuleNewStoAB(Rule): rule = ([S], [A, B])105 self.assertTrue(com.have_rule(RuleNewStoAB))106 fromStoAB = com.get_rule(RuleNewStoAB)107 self.assertTrue(isclass(fromStoAB))108 self.assertTrue(issubclass(fromStoAB, ContextFree.ReducedUnitRule))109 self.assertEqual(len(fromStoAB.by_rules), 2)110 self.assertEqual(fromStoAB.by_rules[0].rule, ([S], [A]))111 self.assertEqual(fromStoAB.by_rules[1].rule, ([A], [B]))112 self.assertEqual(fromStoAB.end_rule.rule, ([B], [A, B]))113 class RuleNewStoEPS(Rule): rule = ([S], [EPS])114 self.assertTrue(com.have_rule(RuleNewStoEPS))115 fromStoEPS = com.get_rule(RuleNewStoEPS)116 self.assertTrue(isclass(fromStoEPS))117 self.assertTrue(issubclass(fromStoEPS, ContextFree.ReducedUnitRule))118 self.assertEqual(len(fromStoEPS.by_rules), 2)119 self.assertEqual(fromStoEPS.by_rules[0].rule, ([S], [A]))120 self.assertEqual(fromStoEPS.by_rules[1].rule, ([A], [B]))121 self.assertEqual(fromStoEPS.end_rule.rule, ([B], [EPS]))122 class RuleNewSto1A(Rule): rule = ([S], [1, A])123 self.assertTrue(com.have_rule(RuleNewSto1A))124 fromSto1A = com.get_rule(RuleNewSto1A)125 self.assertTrue(isclass(fromSto1A))126 self.assertTrue(issubclass(fromSto1A, ContextFree.ReducedUnitRule))127 self.assertEqual(len(fromSto1A.by_rules), 3)128 self.assertEqual(fromSto1A.by_rules[0].rule, ([S], [A]))129 self.assertEqual(fromSto1A.by_rules[1].rule, ([A], [B]))130 self.assertEqual(fromSto1A.by_rules[2].rule, ([B], [C]))131 self.assertEqual(fromSto1A.end_rule.rule, ([C], [1, A]))132 class RuleNewSto1(Rule): rule = ([S], [1])133 self.assertTrue(com.have_rule(RuleNewSto1))134 fromSto1 = com.get_rule(RuleNewSto1)135 self.assertTrue(isclass(fromSto1))136 self.assertTrue(issubclass(fromSto1, ContextFree.ReducedUnitRule))137 self.assertEqual(len(fromSto1.by_rules), 3)138 self.assertEqual(fromSto1.by_rules[0].rule, ([S], [A]))139 self.assertEqual(fromSto1.by_rules[1].rule, ([A], [B]))140 self.assertEqual(fromSto1.by_rules[2].rule, ([B], [C]))141 self.assertEqual(fromSto1.end_rule.rule, ([C], [1]))142 class RuleNewAto1B(Rule): rule = ([A], [1, B])143 self.assertTrue(com.have_rule(RuleNewAto1B))144 fromAto1B = com.get_rule(RuleNewAto1B)145 self.assertTrue(isclass(fromAto1B))146 self.assertTrue(issubclass(fromAto1B, ContextFree.ReducedUnitRule))147 self.assertEqual(len(fromAto1B.by_rules), 1)148 self.assertEqual(fromAto1B.by_rules[0].rule, ([A], [B]))149 self.assertEqual(fromAto1B.end_rule.rule, ([B], [1, B]))150 class RuleNewAtoAB(Rule): rule = ([A], [A, B])151 self.assertTrue(com.have_rule(RuleNewAtoAB))152 fromAtoAB = com.get_rule(RuleNewAtoAB)153 self.assertTrue(isclass(fromAtoAB))154 self.assertTrue(issubclass(fromAtoAB, ContextFree.ReducedUnitRule))155 self.assertEqual(len(fromAtoAB.by_rules), 1)156 self.assertEqual(fromAtoAB.by_rules[0].rule, ([A], [B]))157 self.assertEqual(fromAtoAB.end_rule.rule, ([B], [A, B]))158 class RuleNewAtoEPS(Rule): rule = ([A], [EPS])159 self.assertTrue(com.have_rule(RuleNewAtoEPS))160 fromAtoEPS = com.get_rule(RuleNewAtoEPS)161 self.assertTrue(isclass(fromAtoEPS))162 self.assertTrue(issubclass(fromAtoEPS, ContextFree.ReducedUnitRule))163 self.assertEqual(len(fromAtoEPS.by_rules), 1)164 self.assertEqual(fromAtoEPS.by_rules[0].rule, ([A], [B]))165 self.assertEqual(fromAtoEPS.end_rule.rule, ([B], [EPS]))166 class RuleNewAto1A(Rule): rule = ([A], [1, A])167 self.assertTrue(com.have_rule(RuleNewAto1A))168 fromAto1A = com.get_rule(RuleNewAto1A)169 self.assertTrue(isclass(fromAto1A))170 self.assertTrue(issubclass(fromAto1A, ContextFree.ReducedUnitRule))171 self.assertEqual(len(fromAto1A.by_rules), 2)172 self.assertEqual(fromAto1A.by_rules[0].rule, ([A], [B]))173 self.assertEqual(fromAto1A.by_rules[1].rule, ([B], [C]))174 self.assertEqual(fromAto1A.end_rule.rule, ([C], [1, A]))175 class RuleNewAto1(Rule): rule = ([A], [1])176 self.assertTrue(com.have_rule(RuleNewAto1))177 fromAto1 = com.get_rule(RuleNewAto1)178 self.assertTrue(isclass(fromAto1))179 self.assertTrue(issubclass(fromAto1, ContextFree.ReducedUnitRule))180 self.assertEqual(len(fromAto1.by_rules), 2)181 self.assertEqual(fromAto1.by_rules[0].rule, ([A], [B]))182 self.assertEqual(fromAto1.by_rules[1].rule, ([B], [C]))183 self.assertEqual(fromAto1.end_rule.rule, ([C], [1]))184 class RuleNewBto1A(Rule): rule = ([B], [1, A])185 self.assertTrue(com.have_rule(RuleNewBto1A))186 fromBto1A = com.get_rule(RuleNewBto1A)187 self.assertTrue(isclass(fromBto1A))188 self.assertTrue(issubclass(fromBto1A, ContextFree.ReducedUnitRule))189 self.assertEqual(len(fromBto1A.by_rules), 1)190 self.assertEqual(fromBto1A.by_rules[0].rule, ([B], [C]))191 self.assertEqual(fromBto1A.end_rule.rule, ([C], [1, A]))192 class RuleNewBto1(Rule): rule = ([B], [1])193 self.assertTrue(com.have_rule(RuleNewBto1))194 fromBto1 = com.get_rule(RuleNewBto1)195 self.assertTrue(isclass(fromBto1))196 self.assertTrue(issubclass(fromBto1, ContextFree.ReducedUnitRule))197 self.assertEqual(len(fromBto1.by_rules), 1)198 self.assertEqual(fromBto1.by_rules[0].rule, ([B], [C]))199 self.assertEqual(fromBto1.end_rule.rule, ([C], [1]))200 def test_simpleTestShouldNotChange(self):201 g = Grammar(terminals=[0, 1],202 nonterminals=[S, A, B, C],203 rules=[Rules],204 start_symbol=S)205 ContextFree.remove_unit_rules(g)206 # Removed207 class RuleStoA(Rule): rule=([S], [A])208 self.assertTrue(g.have_rule(RuleStoA))209 class RuleAtoB(Rule): rule=([A], [B])210 self.assertTrue(g.have_rule(RuleAtoB))211 class RuleBtoC(Rule): rule=([B], [C])212 self.assertTrue(g.have_rule(RuleBtoC))213 # Old rules214 class RuleNewSto0B0(Rule): rule = ([S], [0, B, 0])215 self.assertTrue(g.have_rule(RuleNewSto0B0))216 class RuleNewAto0A(Rule): rule = ([A], [0, A])217 self.assertTrue(g.have_rule(RuleNewAto0A))218 class RuleNewBto1B(Rule): rule = ([B], [1, B])219 self.assertTrue(g.have_rule(RuleNewBto1B))220 class RuleNewBtoAB(Rule): rule = ([B], [A, B])221 self.assertTrue(g.have_rule(RuleNewBtoAB))222 class RuleNewBtoEPS(Rule): rule = ([B], [EPS])223 self.assertTrue(g.have_rule(RuleNewBtoEPS))224 class RuleNewCto1A(Rule): rule = ([C], [1, A])225 self.assertTrue(g.have_rule(RuleNewCto1A))226 class RuleNewCto1(Rule): rule = ([C], [1])227 self.assertTrue(g.have_rule(RuleNewCto1))228 # New rules229 class RuleNewSto0A(Rule): rule = ([S], [0, A])230 self.assertFalse(g.have_rule(RuleNewSto0A))231 class RuleNewSto1B(Rule): rule = ([S], [1, B])232 self.assertFalse(g.have_rule(RuleNewSto1B))233 class RuleNewStoAB(Rule): rule = ([S], [A, B])234 self.assertFalse(g.have_rule(RuleNewStoAB))235 class RuleNewStoEPS(Rule): rule = ([S], [EPS])236 self.assertFalse(g.have_rule(RuleNewStoEPS))237 class RuleNewSto1A(Rule): rule = ([S], [1, A])238 self.assertFalse(g.have_rule(RuleNewSto1A))239 class RuleNewSto1(Rule): rule = ([S], [1])240 self.assertFalse(g.have_rule(RuleNewSto1))241 class RuleNewAto1B(Rule): rule = ([A], [1, B])242 self.assertFalse(g.have_rule(RuleNewAto1B))243 class RuleNewAtoAB(Rule): rule = ([A], [A, B])244 self.assertFalse(g.have_rule(RuleNewAtoAB))245 class RuleNewAtoEPS(Rule): rule = ([A], [EPS])246 self.assertFalse(g.have_rule(RuleNewAtoEPS))247 class RuleNewAto1A(Rule): rule = ([A], [1, A])248 self.assertFalse(g.have_rule(RuleNewAto1A))249 class RuleNewAto1(Rule): rule = ([A], [1])250 self.assertFalse(g.have_rule(RuleNewAto1))251 class RuleNewBto1A(Rule): rule = ([B], [1, A])252 self.assertFalse(g.have_rule(RuleNewBto1A))253 class RuleNewBto1(Rule): rule = ([B], [1])254 self.assertFalse(g.have_rule(RuleNewBto1))255 def test_simpleTestShouldChange(self):256 g = Grammar(terminals=[0, 1],257 nonterminals=[S, A, B, C],258 rules=[Rules],259 start_symbol=S)260 ContextFree.remove_unit_rules(g, transform_grammar=True)261 # Removed262 class RuleStoA(Rule): rule=([S], [A])263 self.assertFalse(g.have_rule(RuleStoA))264 class RuleAtoB(Rule): rule=([A], [B])265 self.assertFalse(g.have_rule(RuleAtoB))266 class RuleBtoC(Rule): rule=([B], [C])267 self.assertFalse(g.have_rule(RuleBtoC))268 # Old rules269 class RuleNewSto0B0(Rule): rule = ([S], [0, B, 0])270 self.assertTrue(g.have_rule(RuleNewSto0B0))271 class RuleNewAto0A(Rule): rule = ([A], [0, A])272 self.assertTrue(g.have_rule(RuleNewAto0A))273 class RuleNewBto1B(Rule): rule = ([B], [1, B])274 self.assertTrue(g.have_rule(RuleNewBto1B))275 class RuleNewBtoAB(Rule): rule = ([B], [A, B])276 self.assertTrue(g.have_rule(RuleNewBtoAB))277 class RuleNewBtoEPS(Rule): rule = ([B], [EPS])278 self.assertTrue(g.have_rule(RuleNewBtoEPS))279 class RuleNewCto1A(Rule): rule = ([C], [1, A])280 self.assertTrue(g.have_rule(RuleNewCto1A))281 class RuleNewCto1(Rule): rule = ([C], [1])282 self.assertTrue(g.have_rule(RuleNewCto1))283 # New rules284 class RuleNewSto0A(Rule): rule = ([S], [0, A])285 self.assertTrue(g.have_rule(RuleNewSto0A))286 fromSto0A = g.get_rule(RuleNewSto0A)287 self.assertTrue(isclass(fromSto0A))288 self.assertTrue(issubclass(fromSto0A, ContextFree.ReducedUnitRule))289 self.assertEqual(len(fromSto0A.by_rules), 1)290 self.assertEqual(fromSto0A.by_rules[0].rule, ([S], [A]))291 self.assertEqual(fromSto0A.end_rule.rule, ([A], [0, A]))292 class RuleNewSto1B(Rule): rule = ([S], [1, B])293 self.assertTrue(g.have_rule(RuleNewSto1B))294 fromSto1B = g.get_rule(RuleNewSto1B)295 self.assertTrue(isclass(fromSto1B))296 self.assertTrue(issubclass(fromSto1B, ContextFree.ReducedUnitRule))297 self.assertEqual(len(fromSto1B.by_rules), 2)298 self.assertEqual(fromSto1B.by_rules[0].rule, ([S], [A]))299 self.assertEqual(fromSto1B.by_rules[1].rule, ([A], [B]))300 self.assertEqual(fromSto1B.end_rule.rule, ([B], [1, B]))301 class RuleNewStoAB(Rule): rule = ([S], [A, B])302 self.assertTrue(g.have_rule(RuleNewStoAB))303 fromStoAB = g.get_rule(RuleNewStoAB)304 self.assertTrue(isclass(fromStoAB))305 self.assertTrue(issubclass(fromStoAB, ContextFree.ReducedUnitRule))306 self.assertEqual(len(fromStoAB.by_rules), 2)307 self.assertEqual(fromStoAB.by_rules[0].rule, ([S], [A]))308 self.assertEqual(fromStoAB.by_rules[1].rule, ([A], [B]))309 self.assertEqual(fromStoAB.end_rule.rule, ([B], [A, B]))310 class RuleNewStoEPS(Rule): rule = ([S], [EPS])311 self.assertTrue(g.have_rule(RuleNewStoEPS))312 fromStoEPS = g.get_rule(RuleNewStoEPS)313 self.assertTrue(isclass(fromStoEPS))314 self.assertTrue(issubclass(fromStoEPS, ContextFree.ReducedUnitRule))315 self.assertEqual(len(fromStoEPS.by_rules), 2)316 self.assertEqual(fromStoEPS.by_rules[0].rule, ([S], [A]))317 self.assertEqual(fromStoEPS.by_rules[1].rule, ([A], [B]))318 self.assertEqual(fromStoEPS.end_rule.rule, ([B], [EPS]))319 class RuleNewSto1A(Rule): rule = ([S], [1, A])320 self.assertTrue(g.have_rule(RuleNewSto1A))321 fromSto1A = g.get_rule(RuleNewSto1A)322 self.assertTrue(isclass(fromSto1A))323 self.assertTrue(issubclass(fromSto1A, ContextFree.ReducedUnitRule))324 self.assertEqual(len(fromSto1A.by_rules), 3)325 self.assertEqual(fromSto1A.by_rules[0].rule, ([S], [A]))326 self.assertEqual(fromSto1A.by_rules[1].rule, ([A], [B]))327 self.assertEqual(fromSto1A.by_rules[2].rule, ([B], [C]))328 self.assertEqual(fromSto1A.end_rule.rule, ([C], [1, A]))329 class RuleNewSto1(Rule): rule = ([S], [1])330 self.assertTrue(g.have_rule(RuleNewSto1))331 fromSto1 = g.get_rule(RuleNewSto1)332 self.assertTrue(isclass(fromSto1))333 self.assertTrue(issubclass(fromSto1, ContextFree.ReducedUnitRule))334 self.assertEqual(len(fromSto1.by_rules), 3)335 self.assertEqual(fromSto1.by_rules[0].rule, ([S], [A]))336 self.assertEqual(fromSto1.by_rules[1].rule, ([A], [B]))337 self.assertEqual(fromSto1.by_rules[2].rule, ([B], [C]))338 self.assertEqual(fromSto1.end_rule.rule, ([C], [1]))339 class RuleNewAto1B(Rule): rule = ([A], [1, B])340 self.assertTrue(g.have_rule(RuleNewAto1B))341 fromAto1B = g.get_rule(RuleNewAto1B)342 self.assertTrue(isclass(fromAto1B))343 self.assertTrue(issubclass(fromAto1B, ContextFree.ReducedUnitRule))344 self.assertEqual(len(fromAto1B.by_rules), 1)345 self.assertEqual(fromAto1B.by_rules[0].rule, ([A], [B]))346 self.assertEqual(fromAto1B.end_rule.rule, ([B], [1, B]))347 class RuleNewAtoAB(Rule): rule = ([A], [A, B])348 self.assertTrue(g.have_rule(RuleNewAtoAB))349 fromAtoAB = g.get_rule(RuleNewAtoAB)350 self.assertTrue(isclass(fromAtoAB))351 self.assertTrue(issubclass(fromAtoAB, ContextFree.ReducedUnitRule))352 self.assertEqual(len(fromAtoAB.by_rules), 1)353 self.assertEqual(fromAtoAB.by_rules[0].rule, ([A], [B]))354 self.assertEqual(fromAtoAB.end_rule.rule, ([B], [A, B]))355 class RuleNewAtoEPS(Rule): rule = ([A], [EPS])356 self.assertTrue(g.have_rule(RuleNewAtoEPS))357 fromAtoEPS = g.get_rule(RuleNewAtoEPS)358 self.assertTrue(isclass(fromAtoEPS))359 self.assertTrue(issubclass(fromAtoEPS, ContextFree.ReducedUnitRule))360 self.assertEqual(len(fromAtoEPS.by_rules), 1)361 self.assertEqual(fromAtoEPS.by_rules[0].rule, ([A], [B]))362 self.assertEqual(fromAtoEPS.end_rule.rule, ([B], [EPS]))363 class RuleNewAto1A(Rule): rule = ([A], [1, A])364 self.assertTrue(g.have_rule(RuleNewAto1A))365 fromAto1A = g.get_rule(RuleNewAto1A)366 self.assertTrue(isclass(fromAto1A))367 self.assertTrue(issubclass(fromAto1A, ContextFree.ReducedUnitRule))368 self.assertEqual(len(fromAto1A.by_rules), 2)369 self.assertEqual(fromAto1A.by_rules[0].rule, ([A], [B]))370 self.assertEqual(fromAto1A.by_rules[1].rule, ([B], [C]))371 self.assertEqual(fromAto1A.end_rule.rule, ([C], [1, A]))372 class RuleNewAto1(Rule): rule = ([A], [1])373 self.assertTrue(g.have_rule(RuleNewAto1))374 fromAto1 = g.get_rule(RuleNewAto1)375 self.assertTrue(isclass(fromAto1))376 self.assertTrue(issubclass(fromAto1, ContextFree.ReducedUnitRule))377 self.assertEqual(len(fromAto1.by_rules), 2)378 self.assertEqual(fromAto1.by_rules[0].rule, ([A], [B]))379 self.assertEqual(fromAto1.by_rules[1].rule, ([B], [C]))380 self.assertEqual(fromAto1.end_rule.rule, ([C], [1]))381 class RuleNewBto1A(Rule): rule = ([B], [1, A])382 self.assertTrue(g.have_rule(RuleNewBto1A))383 fromBto1A = g.get_rule(RuleNewBto1A)384 self.assertTrue(isclass(fromBto1A))385 self.assertTrue(issubclass(fromBto1A, ContextFree.ReducedUnitRule))386 self.assertEqual(len(fromBto1A.by_rules), 1)387 self.assertEqual(fromBto1A.by_rules[0].rule, ([B], [C]))388 self.assertEqual(fromBto1A.end_rule.rule, ([C], [1, A]))389 class RuleNewBto1(Rule): rule = ([B], [1])390 self.assertTrue(g.have_rule(RuleNewBto1))391 fromBto1 = g.get_rule(RuleNewBto1)392 self.assertTrue(isclass(fromBto1))393 self.assertTrue(issubclass(fromBto1, ContextFree.ReducedUnitRule))394 self.assertEqual(len(fromBto1.by_rules), 1)395 self.assertEqual(fromBto1.by_rules[0].rule, ([B], [C]))396 self.assertEqual(fromBto1.end_rule.rule, ([C], [1]))397if __name__ == '__main__':...

Full Screen

Full Screen

SimpleTest.py

Source:SimpleTest.py Github

copy

Full Screen

1#!/usr/bin/env python2"""3:Author Patrik Valkovic4:Created 22.08.2017 20:515:Licence GNUv36Part of grammpy-transforms7"""8from inspect import isclass9from unittest import main, TestCase10from grammpy import *11from grammpy_transforms import ContextFree12class S(Nonterminal): pass13class A(Nonterminal): pass14class B(Nonterminal): pass15class C(Nonterminal): pass16class D(Nonterminal): pass17class Rules(Rule):18 rules=[19 ([S], [A]),20 ([S], [B]),21 ([A], [C]),22 ([A], [0, A]),23 ([A], [1, S]),24 ([B], [D]),25 ([B], [2, B]),26 ([B], [3, S]),27 ([C], [1, C]),28 ([C], [0]),29 ([D], [3, D]),30 ([D], [2])]31"""32 -------------------------------33 | S | A | B | C | D |34--------------------------------35S| [] | [1] | [2] |[1,3]|[2,6]|36--------------------------------37A| | [] | | [3] | |38--------------------------------39B| | | [] | | [6] |40--------------------------------41C| | | | [] | |42--------------------------------43D| | | | | [] |44--------------------------------45S->A S->B A->C A->0A A->1S B->D B->2B B->3S C->1C C->0 D->3D D->246---- ---- ---- ---- 47S->A->0A48S->A->1S49S->A->C->1C50S->A->C->051S->B->2B52S->B->3S53S->B->D->3D54S->B->D->255A->C->1C56A->C->057B->D->3D58B->D->259"""60class SimpleTest(TestCase):61 def test_simpleTest(self):62 g = Grammar(terminals=[0,1,2,3],63 nonterminals=[S, A, B, C, D],64 rules=[Rules],65 start_symbol=S)66 com = ContextFree.remove_unit_rules(g)67 # Removed68 class RuleStoA(Rule): rule=([S], [A])69 self.assertFalse(com.have_rule(RuleStoA))70 class RuleStoB(Rule): rule=([S], [B])71 self.assertFalse(com.have_rule(RuleStoB))72 class RuleAtoC(Rule): rule=([A], [C])73 self.assertFalse(com.have_rule(RuleAtoC))74 class RuleBtoD(Rule): rule=([B], [D])75 self.assertFalse(com.have_rule(RuleBtoD))76 # Old rules77 class RuleNewAto0A(Rule): rule = ([A], [0, A])78 self.assertTrue(com.have_rule(RuleNewAto0A))79 class RuleNewAto1S(Rule): rule = ([A], [1, S])80 self.assertTrue(com.have_rule(RuleNewAto1S))81 class RuleNewBto2B(Rule): rule = ([B], [2, B])82 self.assertTrue(com.have_rule(RuleNewBto2B))83 class RuleNewBto3S(Rule): rule = ([B], [3, S])84 self.assertTrue(com.have_rule(RuleNewBto3S))85 class RuleNewCto1C(Rule): rule = ([C], [1, C])86 self.assertTrue(com.have_rule(RuleNewCto1C))87 class RuleNewCto0(Rule): rule = ([C], [0])88 self.assertTrue(com.have_rule(RuleNewCto0))89 class RuleNewDto3D(Rule): rule = ([D], [3, D])90 self.assertTrue(com.have_rule(RuleNewDto3D))91 class RuleNewDto2(Rule): rule = ([D], [2])92 self.assertTrue(com.have_rule(RuleNewDto2))93 # New rules94 class RuleNewSto0A(Rule): rule = ([S], [0, A])95 self.assertTrue(com.have_rule(RuleNewSto0A))96 fromSto0A = com.get_rule(RuleNewSto0A)97 self.assertTrue(isclass(fromSto0A))98 self.assertTrue(issubclass(fromSto0A, ContextFree.ReducedUnitRule))99 self.assertEqual(len(fromSto0A.by_rules), 1)100 self.assertEqual(fromSto0A.by_rules[0].rule, ([S], [A]))101 self.assertEqual(fromSto0A.end_rule.rule, ([A], [0, A]))102 class RuleNewSto1S(Rule): rule = ([S], [1, S])103 self.assertTrue(com.have_rule(RuleNewSto1S))104 fromSto1S = com.get_rule(RuleNewSto1S)105 self.assertTrue(isclass(fromSto1S))106 self.assertTrue(issubclass(fromSto1S, ContextFree.ReducedUnitRule))107 self.assertEqual(len(fromSto1S.by_rules), 1)108 self.assertEqual(fromSto1S.by_rules[0].rule, ([S], [A]))109 self.assertEqual(fromSto1S.end_rule.rule, ([A], [1, S]))110 class RuleNewSto1C(Rule): rule = ([S], [1, C])111 self.assertTrue(com.have_rule(RuleNewSto1C))112 fromSto1C = com.get_rule(RuleNewSto1C)113 self.assertTrue(isclass(fromSto1C))114 self.assertTrue(issubclass(fromSto1C, ContextFree.ReducedUnitRule))115 self.assertEqual(len(fromSto1C.by_rules), 2)116 self.assertEqual(fromSto1C.by_rules[0].rule, ([S], [A]))117 self.assertEqual(fromSto1C.by_rules[1].rule, ([A], [C]))118 self.assertEqual(fromSto1C.end_rule.rule, ([C], [1, C]))119 class RuleNewSto0(Rule): rule = ([S], [0])120 self.assertTrue(com.have_rule(RuleNewSto0))121 fromSto0 = com.get_rule(RuleNewSto0)122 self.assertTrue(isclass(fromSto0))123 self.assertTrue(issubclass(fromSto0, ContextFree.ReducedUnitRule))124 self.assertEqual(len(fromSto0.by_rules), 2)125 self.assertEqual(fromSto0.by_rules[0].rule, ([S], [A]))126 self.assertEqual(fromSto0.by_rules[1].rule, ([A], [C]))127 self.assertEqual(fromSto0.end_rule.rule, ([C], [0]))128 class RuleNewSto2B(Rule): rule = ([S], [2, B])129 self.assertTrue(com.have_rule(RuleNewSto2B))130 fromSto2B = com.get_rule(RuleNewSto2B)131 self.assertTrue(isclass(fromSto2B))132 self.assertTrue(issubclass(fromSto2B, ContextFree.ReducedUnitRule))133 self.assertEqual(len(fromSto2B.by_rules), 1)134 self.assertEqual(fromSto2B.by_rules[0].rule, ([S], [B]))135 self.assertEqual(fromSto2B.end_rule.rule, ([B], [2, B]))136 class RuleNewSto3S(Rule): rule = ([S], [3, S])137 self.assertTrue(com.have_rule(RuleNewSto3S))138 fromSto3S = com.get_rule(RuleNewSto3S)139 self.assertTrue(isclass(fromSto3S))140 self.assertTrue(issubclass(fromSto3S, ContextFree.ReducedUnitRule))141 self.assertEqual(len(fromSto3S.by_rules), 1)142 self.assertEqual(fromSto3S.by_rules[0].rule, ([S], [B]))143 self.assertEqual(fromSto3S.end_rule.rule, ([B], [3, S]))144 class RuleNewSto3D(Rule): rule = ([S], [3, D])145 self.assertTrue(com.have_rule(RuleNewSto3D))146 fromSto3D = com.get_rule(RuleNewSto3D)147 self.assertTrue(isclass(fromSto3D))148 self.assertTrue(issubclass(fromSto3D, ContextFree.ReducedUnitRule))149 self.assertEqual(len(fromSto3D.by_rules), 2)150 self.assertEqual(fromSto3D.by_rules[0].rule, ([S], [B]))151 self.assertEqual(fromSto3D.by_rules[1].rule, ([B], [D]))152 self.assertEqual(fromSto3D.end_rule.rule, ([D], [3, D]))153 class RuleNewSto2(Rule): rule = ([S], [2])154 self.assertTrue(com.have_rule(RuleNewSto2))155 fromSto2 = com.get_rule(RuleNewSto2)156 self.assertTrue(isclass(fromSto2))157 self.assertTrue(issubclass(fromSto2, ContextFree.ReducedUnitRule))158 self.assertEqual(len(fromSto2.by_rules), 2)159 self.assertEqual(fromSto2.by_rules[0].rule, ([S], [B]))160 self.assertEqual(fromSto2.by_rules[1].rule, ([B], [D]))161 self.assertEqual(fromSto2.end_rule.rule, ([D], [2]))162 class RuleNewAto1C(Rule): rule = ([A], [1, C])163 self.assertTrue(com.have_rule(RuleNewAto1C))164 fromAto1C = com.get_rule(RuleNewAto1C)165 self.assertTrue(isclass(fromAto1C))166 self.assertTrue(issubclass(fromAto1C, ContextFree.ReducedUnitRule))167 self.assertEqual(len(fromAto1C.by_rules), 1)168 self.assertEqual(fromAto1C.by_rules[0].rule, ([A], [C]))169 self.assertEqual(fromAto1C.end_rule.rule, ([C], [1, C]))170 class RuleNewAto0(Rule): rule = ([A], [0])171 self.assertTrue(com.have_rule(RuleNewAto0))172 fromAto0 = com.get_rule(RuleNewAto0)173 self.assertTrue(isclass(fromAto0))174 self.assertTrue(issubclass(fromAto0, ContextFree.ReducedUnitRule))175 self.assertEqual(len(fromAto0.by_rules), 1)176 self.assertEqual(fromAto0.by_rules[0].rule, ([A], [C]))177 self.assertEqual(fromAto0.end_rule.rule, ([C], [0]))178 class RuleNewBto3D(Rule): rule = ([B], [3, D])179 self.assertTrue(com.have_rule(RuleNewBto3D))180 fromBto3D = com.get_rule(RuleNewBto3D)181 self.assertTrue(isclass(fromBto3D))182 self.assertTrue(issubclass(fromBto3D, ContextFree.ReducedUnitRule))183 self.assertEqual(len(fromBto3D.by_rules), 1)184 self.assertEqual(fromBto3D.by_rules[0].rule, ([B], [D]))185 self.assertEqual(fromBto3D.end_rule.rule, ([D], [3, D]))186 class RuleNewBto2(Rule): rule = ([B], [2])187 self.assertTrue(com.have_rule(RuleNewBto2))188 fromBto2 = com.get_rule(RuleNewBto2)189 self.assertTrue(isclass(fromBto2))190 self.assertTrue(issubclass(fromBto2, ContextFree.ReducedUnitRule))191 self.assertEqual(len(fromBto2.by_rules), 1)192 self.assertEqual(fromBto2.by_rules[0].rule, ([B], [D]))193 self.assertEqual(fromBto2.end_rule.rule, ([D], [2]))194 def test_simpleTestShouldNotChange(self):195 g = Grammar(terminals=[0,1,2,3],196 nonterminals=[S, A, B, C, D],197 rules=[Rules],198 start_symbol=S)199 ContextFree.remove_unit_rules(g)200 # Removed201 class RuleStoA(Rule): rule = ([S], [A])202 self.assertTrue(g.have_rule(RuleStoA))203 class RuleStoB(Rule): rule = ([S], [B])204 self.assertTrue(g.have_rule(RuleStoB))205 class RuleAtoC(Rule): rule = ([A], [C])206 self.assertTrue(g.have_rule(RuleAtoC))207 class RuleBtoD(Rule): rule = ([B], [D])208 self.assertTrue(g.have_rule(RuleBtoD))209 # Old rules210 class RuleNewAto0A(Rule): rule = ([A], [0, A])211 self.assertTrue(g.have_rule(RuleNewAto0A))212 class RuleNewAto1S(Rule): rule = ([A], [1, S])213 self.assertTrue(g.have_rule(RuleNewAto1S))214 class RuleNewBto2B(Rule): rule = ([B], [2, B])215 self.assertTrue(g.have_rule(RuleNewBto2B))216 class RuleNewBto3S(Rule): rule = ([B], [3, S])217 self.assertTrue(g.have_rule(RuleNewBto3S))218 class RuleNewCto1C(Rule): rule = ([C], [1, C])219 self.assertTrue(g.have_rule(RuleNewCto1C))220 class RuleNewCto0(Rule): rule = ([C], [0])221 self.assertTrue(g.have_rule(RuleNewCto0))222 class RuleNewDto3D(Rule): rule = ([D], [3, D])223 self.assertTrue(g.have_rule(RuleNewDto3D))224 class RuleNewDto2(Rule): rule = ([D], [2])225 self.assertTrue(g.have_rule(RuleNewDto2))226 # New rules227 class RuleNewSto0A(Rule): rule = ([S], [0, A])228 self.assertFalse(g.have_rule(RuleNewSto0A))229 class RuleNewSto1S(Rule): rule = ([S], [1, S])230 self.assertFalse(g.have_rule(RuleNewSto1S))231 class RuleNewSto1C(Rule): rule = ([S], [1, C])232 self.assertFalse(g.have_rule(RuleNewSto1C))233 class RuleNewSto0(Rule): rule = ([S], [0])234 self.assertFalse(g.have_rule(RuleNewSto0))235 class RuleNewSto2B(Rule): rule = ([S], [2, B])236 self.assertFalse(g.have_rule(RuleNewSto2B))237 class RuleNewSto3S(Rule): rule = ([S], [3, S])238 self.assertFalse(g.have_rule(RuleNewSto3S))239 class RuleNewSto3D(Rule): rule = ([S], [3, D])240 self.assertFalse(g.have_rule(RuleNewSto3D))241 class RuleNewSto2(Rule): rule = ([S], [2])242 self.assertFalse(g.have_rule(RuleNewSto2))243 class RuleNewAto1C(Rule): rule = ([A], [1, C])244 self.assertFalse(g.have_rule(RuleNewAto1C))245 class RuleNewAto0(Rule): rule = ([A], [0])246 self.assertFalse(g.have_rule(RuleNewAto0))247 class RuleNewBto3D(Rule): rule = ([B], [3, D])248 self.assertFalse(g.have_rule(RuleNewBto3D))249 class RuleNewBto2(Rule): rule = ([B], [2])250 self.assertFalse(g.have_rule(RuleNewBto2))251 def test_simpleTestShouldChange(self):252 g = Grammar(terminals=[0,1,2,3],253 nonterminals=[S, A, B, C, D],254 rules=[Rules],255 start_symbol=S)256 ContextFree.remove_unit_rules(g, transform_grammar=True)257 # Removed258 class RuleStoA(Rule): rule=([S], [A])259 self.assertFalse(g.have_rule(RuleStoA))260 class RuleStoB(Rule): rule=([S], [B])261 self.assertFalse(g.have_rule(RuleStoB))262 class RuleAtoC(Rule): rule=([A], [C])263 self.assertFalse(g.have_rule(RuleAtoC))264 class RuleBtoD(Rule): rule=([B], [D])265 self.assertFalse(g.have_rule(RuleBtoD))266 # Old rules267 class RuleNewAto0A(Rule): rule = ([A], [0, A])268 self.assertTrue(g.have_rule(RuleNewAto0A))269 class RuleNewAto1S(Rule): rule = ([A], [1, S])270 self.assertTrue(g.have_rule(RuleNewAto1S))271 class RuleNewBto2B(Rule): rule = ([B], [2, B])272 self.assertTrue(g.have_rule(RuleNewBto2B))273 class RuleNewBto3S(Rule): rule = ([B], [3, S])274 self.assertTrue(g.have_rule(RuleNewBto3S))275 class RuleNewCto1C(Rule): rule = ([C], [1, C])276 self.assertTrue(g.have_rule(RuleNewCto1C))277 class RuleNewCto0(Rule): rule = ([C], [0])278 self.assertTrue(g.have_rule(RuleNewCto0))279 class RuleNewDto3D(Rule): rule = ([D], [3, D])280 self.assertTrue(g.have_rule(RuleNewDto3D))281 class RuleNewDto2(Rule): rule = ([D], [2])282 self.assertTrue(g.have_rule(RuleNewDto2))283 # New rules284 class RuleNewSto0A(Rule): rule = ([S], [0, A])285 self.assertTrue(g.have_rule(RuleNewSto0A))286 fromSto0A = g.get_rule(RuleNewSto0A)287 self.assertTrue(isclass(fromSto0A))288 self.assertTrue(issubclass(fromSto0A, ContextFree.ReducedUnitRule))289 self.assertEqual(len(fromSto0A.by_rules), 1)290 self.assertEqual(fromSto0A.by_rules[0].rule, ([S], [A]))291 self.assertEqual(fromSto0A.end_rule.rule, ([A], [0, A]))292 class RuleNewSto1S(Rule): rule = ([S], [1, S])293 self.assertTrue(g.have_rule(RuleNewSto1S))294 fromSto1S = g.get_rule(RuleNewSto1S)295 self.assertTrue(isclass(fromSto1S))296 self.assertTrue(issubclass(fromSto1S, ContextFree.ReducedUnitRule))297 self.assertEqual(len(fromSto1S.by_rules), 1)298 self.assertEqual(fromSto1S.by_rules[0].rule, ([S], [A]))299 self.assertEqual(fromSto1S.end_rule.rule, ([A], [1, S]))300 class RuleNewSto1C(Rule): rule = ([S], [1, C])301 self.assertTrue(g.have_rule(RuleNewSto1C))302 fromSto1C = g.get_rule(RuleNewSto1C)303 self.assertTrue(isclass(fromSto1C))304 self.assertTrue(issubclass(fromSto1C, ContextFree.ReducedUnitRule))305 self.assertEqual(len(fromSto1C.by_rules), 2)306 self.assertEqual(fromSto1C.by_rules[0].rule, ([S], [A]))307 self.assertEqual(fromSto1C.by_rules[1].rule, ([A], [C]))308 self.assertEqual(fromSto1C.end_rule.rule, ([C], [1, C]))309 class RuleNewSto0(Rule): rule = ([S], [0])310 self.assertTrue(g.have_rule(RuleNewSto0))311 fromSto0 = g.get_rule(RuleNewSto0)312 self.assertTrue(isclass(fromSto0))313 self.assertTrue(issubclass(fromSto0, ContextFree.ReducedUnitRule))314 self.assertEqual(len(fromSto0.by_rules), 2)315 self.assertEqual(fromSto0.by_rules[0].rule, ([S], [A]))316 self.assertEqual(fromSto0.by_rules[1].rule, ([A], [C]))317 self.assertEqual(fromSto0.end_rule.rule, ([C], [0]))318 class RuleNewSto2B(Rule): rule = ([S], [2, B])319 self.assertTrue(g.have_rule(RuleNewSto2B))320 fromSto2B = g.get_rule(RuleNewSto2B)321 self.assertTrue(isclass(fromSto2B))322 self.assertTrue(issubclass(fromSto2B, ContextFree.ReducedUnitRule))323 self.assertEqual(len(fromSto2B.by_rules), 1)324 self.assertEqual(fromSto2B.by_rules[0].rule, ([S], [B]))325 self.assertEqual(fromSto2B.end_rule.rule, ([B], [2, B]))326 class RuleNewSto3S(Rule): rule = ([S], [3, S])327 self.assertTrue(g.have_rule(RuleNewSto3S))328 fromSto3S = g.get_rule(RuleNewSto3S)329 self.assertTrue(isclass(fromSto3S))330 self.assertTrue(issubclass(fromSto3S, ContextFree.ReducedUnitRule))331 self.assertEqual(len(fromSto3S.by_rules), 1)332 self.assertEqual(fromSto3S.by_rules[0].rule, ([S], [B]))333 self.assertEqual(fromSto3S.end_rule.rule, ([B], [3, S]))334 class RuleNewSto3D(Rule): rule = ([S], [3, D])335 self.assertTrue(g.have_rule(RuleNewSto3D))336 fromSto3D = g.get_rule(RuleNewSto3D)337 self.assertTrue(isclass(fromSto3D))338 self.assertTrue(issubclass(fromSto3D, ContextFree.ReducedUnitRule))339 self.assertEqual(len(fromSto3D.by_rules), 2)340 self.assertEqual(fromSto3D.by_rules[0].rule, ([S], [B]))341 self.assertEqual(fromSto3D.by_rules[1].rule, ([B], [D]))342 self.assertEqual(fromSto3D.end_rule.rule, ([D], [3, D]))343 class RuleNewSto2(Rule): rule = ([S], [2])344 self.assertTrue(g.have_rule(RuleNewSto2))345 fromSto2 = g.get_rule(RuleNewSto2)346 self.assertTrue(isclass(fromSto2))347 self.assertTrue(issubclass(fromSto2, ContextFree.ReducedUnitRule))348 self.assertEqual(len(fromSto2.by_rules), 2)349 self.assertEqual(fromSto2.by_rules[0].rule, ([S], [B]))350 self.assertEqual(fromSto2.by_rules[1].rule, ([B], [D]))351 self.assertEqual(fromSto2.end_rule.rule, ([D], [2]))352 class RuleNewAto1C(Rule): rule = ([A], [1, C])353 self.assertTrue(g.have_rule(RuleNewAto1C))354 fromAto1C = g.get_rule(RuleNewAto1C)355 self.assertTrue(isclass(fromAto1C))356 self.assertTrue(issubclass(fromAto1C, ContextFree.ReducedUnitRule))357 self.assertEqual(len(fromAto1C.by_rules), 1)358 self.assertEqual(fromAto1C.by_rules[0].rule, ([A], [C]))359 self.assertEqual(fromAto1C.end_rule.rule, ([C], [1, C]))360 class RuleNewAto0(Rule): rule = ([A], [0])361 self.assertTrue(g.have_rule(RuleNewAto0))362 fromAto0 = g.get_rule(RuleNewAto0)363 self.assertTrue(isclass(fromAto0))364 self.assertTrue(issubclass(fromAto0, ContextFree.ReducedUnitRule))365 self.assertEqual(len(fromAto0.by_rules), 1)366 self.assertEqual(fromAto0.by_rules[0].rule, ([A], [C]))367 self.assertEqual(fromAto0.end_rule.rule, ([C], [0]))368 class RuleNewBto3D(Rule): rule = ([B], [3, D])369 self.assertTrue(g.have_rule(RuleNewBto3D))370 fromBto3D = g.get_rule(RuleNewBto3D)371 self.assertTrue(isclass(fromBto3D))372 self.assertTrue(issubclass(fromBto3D, ContextFree.ReducedUnitRule))373 self.assertEqual(len(fromBto3D.by_rules), 1)374 self.assertEqual(fromBto3D.by_rules[0].rule, ([B], [D]))375 self.assertEqual(fromBto3D.end_rule.rule, ([D], [3, D]))376 class RuleNewBto2(Rule): rule = ([B], [2])377 self.assertTrue(g.have_rule(RuleNewBto2))378 fromBto2 = g.get_rule(RuleNewBto2)379 self.assertTrue(isclass(fromBto2))380 self.assertTrue(issubclass(fromBto2, ContextFree.ReducedUnitRule))381 self.assertEqual(len(fromBto2.by_rules), 1)382 self.assertEqual(fromBto2.by_rules[0].rule, ([B], [D]))383 self.assertEqual(fromBto2.end_rule.rule, ([D], [2]))384if __name__ == '__main__':...

Full Screen

Full Screen

Node.py

Source:Node.py Github

copy

Full Screen

1import threading2from threading import currentThread3import time4from actions.Action import Action5from utils.Constants import EventType6class Node(object):7 def run(self, scenario_engine):8 raise NotImplementedError("Should have implemented this")9 def start_rule_passed(self, common_obj):10 raise NotImplementedError("Should have implemented this")11 def end_rule_passed(self, common_obj):12 raise NotImplementedError("Should have implemented this")13 def on_event(self, type):14 raise NotImplementedError("Should have implemented this")15 @staticmethod16 def of(node_json):17 if node_json is None:18 return EmptyNode()19 if node_json["type"] == "sync":20 return SyncNode(node_json["start_rule"], node_json["end_rule"], node_json["actions"], node_json["events"])21 if node_json["type"] == "loop":22 return LoopNode(node_json["start_rule"], node_json["end_rule"], node_json["actions"], node_json["events"] )23 if node_json["type"] == "parallel":24 return ParallelNode(node_json["start_rule"], node_json["end_rule"], node_json["actions"], node_json["name"], node_json["events"] )25class EmptyNode(Node):26 def run(self, nao_client):27 pass28def parse_actions(actions):29 stages = []30 for stage in actions:31 action = Action.of(stage['Action'])32 stages.append(action)33 return stages34def parse_events(events):35 stages = []36 for stage in events:37 event = Event.of(stage['Event'])38 stages.append(event)39 return stages40class SyncNode(Node):41 def __init__(self, start_rule, end_rule, actions, events):42 self.start_rule = start_rule43 self.end_rule = end_rule44 self.actions = parse_actions(actions)45 self.events = parse_events(events)46 self.common_obj = None47 self.lock = threading.Lock()48 def end_rule_passed(self, common_obj):49 return eval(self.end_rule, {"common_obj": common_obj, "options": common_obj["options"].get, "always": always, "child_ready": child_ready})50 def start_rule_passed(self, common_obj):51 return eval(self.start_rule, {"common_obj": common_obj, "options": common_obj["options"].get, "always": always, "child_ready": child_ready})52 def on_event(self, data):53 print "event"54 print type55 print self.events56 for e in self.events:57 if e.data == data:58 self.lock.acquire()59 e.run(self.common_obj)60 self.lock.release()61 print "event"62 time.sleep(0.1)63 def run(self, scenario_engine):64 print self.events65 self.common_obj = scenario_engine.common_obj66 self.common_obj["options"]["interrupt_lock"] = self.lock67 if self.common_obj.get("Analyser", None):68 for e in self.events:69 self.common_obj["Analyser"].add_event_to_lissen(e.data)70 for action in self.actions:71 self.lock.acquire()72 action.run(scenario_engine.common_obj)73 self.lock.release()74 time.sleep(0.01)75 if self.common_obj.get("Analyser", None):76 for e in self.events:77 self.common_obj["Analyser"].remove_event_to_lissen(e.data)78class LoopNode(Node):79 def __init__(self, start_rule, end_rule, actions, events):80 self.start_rule = start_rule81 self.end_rule = end_rule82 self.actions = parse_actions(actions)83 self.events = parse_events(events)84 self.common_obj = None85 self.lock = threading.Lock()86 def end_rule_passed(self, common_obj):87 return eval(self.end_rule, {"common_obj": common_obj,88 "options": common_obj["options"].get,89 "always": always,90 "child_ready": child_ready,91 "now": time.time(),92 "start": self.start,93 "clicked": common_obj["click"].is_clicked()})94 def start_rule_passed(self, common_obj):95 return eval(self.start_rule, {"common_obj": common_obj,96 "options": common_obj["options"].get,97 "always": always,98 "child_ready": child_ready})99 def on_event(self, type):100 for e in self.events:101 if e.type == type:102 self.lock.acquire()103 e.run()104 self.lock.release()105 def run(self, scenario_engine):106 print self.actions107 self.common_obj = scenario_engine.common_obj108 self.start = time.time()109 while not self.end_rule_passed(scenario_engine.common_obj):110 for action in self.actions:111 self.lock.acquire()112 action.run(scenario_engine.common_obj)113 self.lock.release()114 time.sleep(0.01)115class ParallelNode(Node):116 def __init__(self, start_rule, end_rule, actions, name, events):117 self.start_rule = start_rule118 self.end_rule = end_rule119 self.actions = parse_actions(actions)120 self.name = name121 self.events = parse_events(events)122 self.common_obj = None123 self.lock = threading.Lock()124 def end_rule_passed(self, common_obj):125 return eval(self.end_rule, {"common_obj": common_obj, "options": common_obj["options"].get, "always": always, "child_ready": child_ready})126 def start_rule_passed(self, common_obj):127 return eval(self.start_rule, {"common_obj": common_obj, "options": common_obj["options"].get, "always": always, "child_ready": child_ready})128 def on_event(self, type):129 for e in self.events:130 if e.type == type:131 self.lock.acquire()132 e.run()133 self.lock.release()134 def run(self, scenario_engine):135 print self.actions136 self.common_obj = scenario_engine.common_obj137 t = currentThread()138 while getattr(t, "do_run", True):139 for action in self.actions:140 self.lock.acquire()141 action.run(scenario_engine.common_obj)142 self.lock.release()143 time.sleep(0.01)144def always():145 return True146def child_ready():147 return True148def options(val):149 global common_obj150 return common_obj["options"].get(val, False)151class Event(object):152 def run(self, common_obj):153 raise NotImplementedError("Should have implemented this")154 @staticmethod155 def of(event_json):156 if event_json is None:157 return EmptyEvent()158 if event_json["type"] == EventType.GAZE_AVERTING.value:159 return SimpleEvent(EventType.GAZE_AVERTING, event_json["separation"], event_json["value"], event_json["actions"])160 if event_json["type"] == EventType.Emotion_OCCURRED.value:161 return SimpleEvent(EventType.Emotion_OCCURRED, event_json["separation"], event_json["value"], event_json["actions"])162 if event_json["type"] == EventType.QUESTION_DETECTED.value:163 return SimpleEvent(EventType.QUESTION_DETECTED, event_json["separation"], event_json["value"], event_json["actions"])164 if event_json["type"] == EventType.SILENCE_DETECTED.value:165 return SimpleEvent(EventType.SILENCE_DETECTED, event_json["separation"], event_json["value"], event_json["actions"])166class EmptyEvent(Event):167 def run(self, common_obj):168 pass169class SimpleEvent(Event):170 def __init__(self, type, separation, value, actions):171 self.type = type172 self.data = {"type": type, "separation": separation, "value": value}173 self.actions = parse_actions(actions)174 def run(self, common_obj):175 print self.actions176 for action in self.actions:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful