Best Atoum code snippet using parser.parse
parserc.go
Source:parserc.go
1package yaml2import (3 "bytes"4)5// The parser implements the following grammar:6//7// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END8// implicit_document ::= block_node DOCUMENT-END*9// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*10// block_node_or_indentless_sequence ::=11// ALIAS12// | properties (block_content | indentless_block_sequence)?13// | block_content14// | indentless_block_sequence15// block_node ::= ALIAS16// | properties block_content?17// | block_content18// flow_node ::= ALIAS19// | properties flow_content?20// | flow_content21// properties ::= TAG ANCHOR? | ANCHOR TAG?22// block_content ::= block_collection | flow_collection | SCALAR23// flow_content ::= flow_collection | SCALAR24// block_collection ::= block_sequence | block_mapping25// flow_collection ::= flow_sequence | flow_mapping26// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END27// indentless_sequence ::= (BLOCK-ENTRY block_node?)+28// block_mapping ::= BLOCK-MAPPING_START29// ((KEY block_node_or_indentless_sequence?)?30// (VALUE block_node_or_indentless_sequence?)?)*31// BLOCK-END32// flow_sequence ::= FLOW-SEQUENCE-START33// (flow_sequence_entry FLOW-ENTRY)*34// flow_sequence_entry?35// FLOW-SEQUENCE-END36// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?37// flow_mapping ::= FLOW-MAPPING-START38// (flow_mapping_entry FLOW-ENTRY)*39// flow_mapping_entry?40// FLOW-MAPPING-END41// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?42// Peek the next token in the token queue.43func peek_token(parser *yaml_parser_t) *yaml_token_t {44 if parser.token_available || yaml_parser_fetch_more_tokens(parser) {45 return &parser.tokens[parser.tokens_head]46 }47 return nil48}49// Remove the next token from the queue (must be called after peek_token).50func skip_token(parser *yaml_parser_t) {51 parser.token_available = false52 parser.tokens_parsed++53 parser.stream_end_produced = parser.tokens[parser.tokens_head].typ == yaml_STREAM_END_TOKEN54 parser.tokens_head++55}56// Get the next event.57func yaml_parser_parse(parser *yaml_parser_t, event *yaml_event_t) bool {58 // Erase the event object.59 *event = yaml_event_t{}60 // No events after the end of the stream or error.61 if parser.stream_end_produced || parser.error != yaml_NO_ERROR || parser.state == yaml_PARSE_END_STATE {62 return true63 }64 // Generate the next event.65 return yaml_parser_state_machine(parser, event)66}67// Set parser error.68func yaml_parser_set_parser_error(parser *yaml_parser_t, problem string, problem_mark yaml_mark_t) bool {69 parser.error = yaml_PARSER_ERROR70 parser.problem = problem71 parser.problem_mark = problem_mark72 return false73}74func yaml_parser_set_parser_error_context(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string, problem_mark yaml_mark_t) bool {75 parser.error = yaml_PARSER_ERROR76 parser.context = context77 parser.context_mark = context_mark78 parser.problem = problem79 parser.problem_mark = problem_mark80 return false81}82// State dispatcher.83func yaml_parser_state_machine(parser *yaml_parser_t, event *yaml_event_t) bool {84 //trace("yaml_parser_state_machine", "state:", parser.state.String())85 switch parser.state {86 case yaml_PARSE_STREAM_START_STATE:87 return yaml_parser_parse_stream_start(parser, event)88 case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE:89 return yaml_parser_parse_document_start(parser, event, true)90 case yaml_PARSE_DOCUMENT_START_STATE:91 return yaml_parser_parse_document_start(parser, event, false)92 case yaml_PARSE_DOCUMENT_CONTENT_STATE:93 return yaml_parser_parse_document_content(parser, event)94 case yaml_PARSE_DOCUMENT_END_STATE:95 return yaml_parser_parse_document_end(parser, event)96 case yaml_PARSE_BLOCK_NODE_STATE:97 return yaml_parser_parse_node(parser, event, true, false)98 case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:99 return yaml_parser_parse_node(parser, event, true, true)100 case yaml_PARSE_FLOW_NODE_STATE:101 return yaml_parser_parse_node(parser, event, false, false)102 case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:103 return yaml_parser_parse_block_sequence_entry(parser, event, true)104 case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:105 return yaml_parser_parse_block_sequence_entry(parser, event, false)106 case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:107 return yaml_parser_parse_indentless_sequence_entry(parser, event)108 case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:109 return yaml_parser_parse_block_mapping_key(parser, event, true)110 case yaml_PARSE_BLOCK_MAPPING_KEY_STATE:111 return yaml_parser_parse_block_mapping_key(parser, event, false)112 case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE:113 return yaml_parser_parse_block_mapping_value(parser, event)114 case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:115 return yaml_parser_parse_flow_sequence_entry(parser, event, true)116 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE:117 return yaml_parser_parse_flow_sequence_entry(parser, event, false)118 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:119 return yaml_parser_parse_flow_sequence_entry_mapping_key(parser, event)120 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:121 return yaml_parser_parse_flow_sequence_entry_mapping_value(parser, event)122 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:123 return yaml_parser_parse_flow_sequence_entry_mapping_end(parser, event)124 case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:125 return yaml_parser_parse_flow_mapping_key(parser, event, true)126 case yaml_PARSE_FLOW_MAPPING_KEY_STATE:127 return yaml_parser_parse_flow_mapping_key(parser, event, false)128 case yaml_PARSE_FLOW_MAPPING_VALUE_STATE:129 return yaml_parser_parse_flow_mapping_value(parser, event, false)130 case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:131 return yaml_parser_parse_flow_mapping_value(parser, event, true)132 default:133 panic("invalid parser state")134 }135}136// Parse the production:137// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END138// ************139func yaml_parser_parse_stream_start(parser *yaml_parser_t, event *yaml_event_t) bool {140 token := peek_token(parser)141 if token == nil {142 return false143 }144 if token.typ != yaml_STREAM_START_TOKEN {145 return yaml_parser_set_parser_error(parser, "did not find expected <stream-start>", token.start_mark)146 }147 parser.state = yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE148 *event = yaml_event_t{149 typ: yaml_STREAM_START_EVENT,150 start_mark: token.start_mark,151 end_mark: token.end_mark,152 encoding: token.encoding,153 }154 skip_token(parser)155 return true156}157// Parse the productions:158// implicit_document ::= block_node DOCUMENT-END*159// *160// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*161// *************************162func yaml_parser_parse_document_start(parser *yaml_parser_t, event *yaml_event_t, implicit bool) bool {163 token := peek_token(parser)164 if token == nil {165 return false166 }167 // Parse extra document end indicators.168 if !implicit {169 for token.typ == yaml_DOCUMENT_END_TOKEN {170 skip_token(parser)171 token = peek_token(parser)172 if token == nil {173 return false174 }175 }176 }177 if implicit && token.typ != yaml_VERSION_DIRECTIVE_TOKEN &&178 token.typ != yaml_TAG_DIRECTIVE_TOKEN &&179 token.typ != yaml_DOCUMENT_START_TOKEN &&180 token.typ != yaml_STREAM_END_TOKEN {181 // Parse an implicit document.182 if !yaml_parser_process_directives(parser, nil, nil) {183 return false184 }185 parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE)186 parser.state = yaml_PARSE_BLOCK_NODE_STATE187 *event = yaml_event_t{188 typ: yaml_DOCUMENT_START_EVENT,189 start_mark: token.start_mark,190 end_mark: token.end_mark,191 }192 } else if token.typ != yaml_STREAM_END_TOKEN {193 // Parse an explicit document.194 var version_directive *yaml_version_directive_t195 var tag_directives []yaml_tag_directive_t196 start_mark := token.start_mark197 if !yaml_parser_process_directives(parser, &version_directive, &tag_directives) {198 return false199 }200 token = peek_token(parser)201 if token == nil {202 return false203 }204 if token.typ != yaml_DOCUMENT_START_TOKEN {205 yaml_parser_set_parser_error(parser,206 "did not find expected <document start>", token.start_mark)207 return false208 }209 parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE)210 parser.state = yaml_PARSE_DOCUMENT_CONTENT_STATE211 end_mark := token.end_mark212 *event = yaml_event_t{213 typ: yaml_DOCUMENT_START_EVENT,214 start_mark: start_mark,215 end_mark: end_mark,216 version_directive: version_directive,217 tag_directives: tag_directives,218 implicit: false,219 }220 skip_token(parser)221 } else {222 // Parse the stream end.223 parser.state = yaml_PARSE_END_STATE224 *event = yaml_event_t{225 typ: yaml_STREAM_END_EVENT,226 start_mark: token.start_mark,227 end_mark: token.end_mark,228 }229 skip_token(parser)230 }231 return true232}233// Parse the productions:234// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*235// ***********236//237func yaml_parser_parse_document_content(parser *yaml_parser_t, event *yaml_event_t) bool {238 token := peek_token(parser)239 if token == nil {240 return false241 }242 if token.typ == yaml_VERSION_DIRECTIVE_TOKEN ||243 token.typ == yaml_TAG_DIRECTIVE_TOKEN ||244 token.typ == yaml_DOCUMENT_START_TOKEN ||245 token.typ == yaml_DOCUMENT_END_TOKEN ||246 token.typ == yaml_STREAM_END_TOKEN {247 parser.state = parser.states[len(parser.states)-1]248 parser.states = parser.states[:len(parser.states)-1]249 return yaml_parser_process_empty_scalar(parser, event,250 token.start_mark)251 }252 return yaml_parser_parse_node(parser, event, true, false)253}254// Parse the productions:255// implicit_document ::= block_node DOCUMENT-END*256// *************257// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*258//259func yaml_parser_parse_document_end(parser *yaml_parser_t, event *yaml_event_t) bool {260 token := peek_token(parser)261 if token == nil {262 return false263 }264 start_mark := token.start_mark265 end_mark := token.start_mark266 implicit := true267 if token.typ == yaml_DOCUMENT_END_TOKEN {268 end_mark = token.end_mark269 skip_token(parser)270 implicit = false271 }272 parser.tag_directives = parser.tag_directives[:0]273 parser.state = yaml_PARSE_DOCUMENT_START_STATE274 *event = yaml_event_t{275 typ: yaml_DOCUMENT_END_EVENT,276 start_mark: start_mark,277 end_mark: end_mark,278 implicit: implicit,279 }280 return true281}282// Parse the productions:283// block_node_or_indentless_sequence ::=284// ALIAS285// *****286// | properties (block_content | indentless_block_sequence)?287// ********** *288// | block_content | indentless_block_sequence289// *290// block_node ::= ALIAS291// *****292// | properties block_content?293// ********** *294// | block_content295// *296// flow_node ::= ALIAS297// *****298// | properties flow_content?299// ********** *300// | flow_content301// *302// properties ::= TAG ANCHOR? | ANCHOR TAG?303// *************************304// block_content ::= block_collection | flow_collection | SCALAR305// ******306// flow_content ::= flow_collection | SCALAR307// ******308func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, indentless_sequence bool) bool {309 //defer trace("yaml_parser_parse_node", "block:", block, "indentless_sequence:", indentless_sequence)()310 token := peek_token(parser)311 if token == nil {312 return false313 }314 if token.typ == yaml_ALIAS_TOKEN {315 parser.state = parser.states[len(parser.states)-1]316 parser.states = parser.states[:len(parser.states)-1]317 *event = yaml_event_t{318 typ: yaml_ALIAS_EVENT,319 start_mark: token.start_mark,320 end_mark: token.end_mark,321 anchor: token.value,322 }323 skip_token(parser)324 return true325 }326 start_mark := token.start_mark327 end_mark := token.start_mark328 var tag_token bool329 var tag_handle, tag_suffix, anchor []byte330 var tag_mark yaml_mark_t331 if token.typ == yaml_ANCHOR_TOKEN {332 anchor = token.value333 start_mark = token.start_mark334 end_mark = token.end_mark335 skip_token(parser)336 token = peek_token(parser)337 if token == nil {338 return false339 }340 if token.typ == yaml_TAG_TOKEN {341 tag_token = true342 tag_handle = token.value343 tag_suffix = token.suffix344 tag_mark = token.start_mark345 end_mark = token.end_mark346 skip_token(parser)347 token = peek_token(parser)348 if token == nil {349 return false350 }351 }352 } else if token.typ == yaml_TAG_TOKEN {353 tag_token = true354 tag_handle = token.value355 tag_suffix = token.suffix356 start_mark = token.start_mark357 tag_mark = token.start_mark358 end_mark = token.end_mark359 skip_token(parser)360 token = peek_token(parser)361 if token == nil {362 return false363 }364 if token.typ == yaml_ANCHOR_TOKEN {365 anchor = token.value366 end_mark = token.end_mark367 skip_token(parser)368 token = peek_token(parser)369 if token == nil {370 return false371 }372 }373 }374 var tag []byte375 if tag_token {376 if len(tag_handle) == 0 {377 tag = tag_suffix378 tag_suffix = nil379 } else {380 for i := range parser.tag_directives {381 if bytes.Equal(parser.tag_directives[i].handle, tag_handle) {382 tag = append([]byte(nil), parser.tag_directives[i].prefix...)383 tag = append(tag, tag_suffix...)384 break385 }386 }387 if len(tag) == 0 {388 yaml_parser_set_parser_error_context(parser,389 "while parsing a node", start_mark,390 "found undefined tag handle", tag_mark)391 return false392 }393 }394 }395 implicit := len(tag) == 0396 if indentless_sequence && token.typ == yaml_BLOCK_ENTRY_TOKEN {397 end_mark = token.end_mark398 parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE399 *event = yaml_event_t{400 typ: yaml_SEQUENCE_START_EVENT,401 start_mark: start_mark,402 end_mark: end_mark,403 anchor: anchor,404 tag: tag,405 implicit: implicit,406 style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE),407 }408 return true409 }410 if token.typ == yaml_SCALAR_TOKEN {411 var plain_implicit, quoted_implicit bool412 end_mark = token.end_mark413 if (len(tag) == 0 && token.style == yaml_PLAIN_SCALAR_STYLE) || (len(tag) == 1 && tag[0] == '!') {414 plain_implicit = true415 } else if len(tag) == 0 {416 quoted_implicit = true417 }418 parser.state = parser.states[len(parser.states)-1]419 parser.states = parser.states[:len(parser.states)-1]420 *event = yaml_event_t{421 typ: yaml_SCALAR_EVENT,422 start_mark: start_mark,423 end_mark: end_mark,424 anchor: anchor,425 tag: tag,426 value: token.value,427 implicit: plain_implicit,428 quoted_implicit: quoted_implicit,429 style: yaml_style_t(token.style),430 }431 skip_token(parser)432 return true433 }434 if token.typ == yaml_FLOW_SEQUENCE_START_TOKEN {435 // [Go] Some of the events below can be merged as they differ only on style.436 end_mark = token.end_mark437 parser.state = yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE438 *event = yaml_event_t{439 typ: yaml_SEQUENCE_START_EVENT,440 start_mark: start_mark,441 end_mark: end_mark,442 anchor: anchor,443 tag: tag,444 implicit: implicit,445 style: yaml_style_t(yaml_FLOW_SEQUENCE_STYLE),446 }447 return true448 }449 if token.typ == yaml_FLOW_MAPPING_START_TOKEN {450 end_mark = token.end_mark451 parser.state = yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE452 *event = yaml_event_t{453 typ: yaml_MAPPING_START_EVENT,454 start_mark: start_mark,455 end_mark: end_mark,456 anchor: anchor,457 tag: tag,458 implicit: implicit,459 style: yaml_style_t(yaml_FLOW_MAPPING_STYLE),460 }461 return true462 }463 if block && token.typ == yaml_BLOCK_SEQUENCE_START_TOKEN {464 end_mark = token.end_mark465 parser.state = yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE466 *event = yaml_event_t{467 typ: yaml_SEQUENCE_START_EVENT,468 start_mark: start_mark,469 end_mark: end_mark,470 anchor: anchor,471 tag: tag,472 implicit: implicit,473 style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE),474 }475 return true476 }477 if block && token.typ == yaml_BLOCK_MAPPING_START_TOKEN {478 end_mark = token.end_mark479 parser.state = yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE480 *event = yaml_event_t{481 typ: yaml_MAPPING_START_EVENT,482 start_mark: start_mark,483 end_mark: end_mark,484 anchor: anchor,485 tag: tag,486 implicit: implicit,487 style: yaml_style_t(yaml_BLOCK_MAPPING_STYLE),488 }489 return true490 }491 if len(anchor) > 0 || len(tag) > 0 {492 parser.state = parser.states[len(parser.states)-1]493 parser.states = parser.states[:len(parser.states)-1]494 *event = yaml_event_t{495 typ: yaml_SCALAR_EVENT,496 start_mark: start_mark,497 end_mark: end_mark,498 anchor: anchor,499 tag: tag,500 implicit: implicit,501 quoted_implicit: false,502 style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE),503 }504 return true505 }506 context := "while parsing a flow node"507 if block {508 context = "while parsing a block node"509 }510 yaml_parser_set_parser_error_context(parser, context, start_mark,511 "did not find expected node content", token.start_mark)512 return false513}514// Parse the productions:515// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END516// ******************** *********** * *********517//518func yaml_parser_parse_block_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {519 if first {520 token := peek_token(parser)521 parser.marks = append(parser.marks, token.start_mark)522 skip_token(parser)523 }524 token := peek_token(parser)525 if token == nil {526 return false527 }528 if token.typ == yaml_BLOCK_ENTRY_TOKEN {529 mark := token.end_mark530 skip_token(parser)531 token = peek_token(parser)532 if token == nil {533 return false534 }535 if token.typ != yaml_BLOCK_ENTRY_TOKEN && token.typ != yaml_BLOCK_END_TOKEN {536 parser.states = append(parser.states, yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE)537 return yaml_parser_parse_node(parser, event, true, false)538 } else {539 parser.state = yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE540 return yaml_parser_process_empty_scalar(parser, event, mark)541 }542 }543 if token.typ == yaml_BLOCK_END_TOKEN {544 parser.state = parser.states[len(parser.states)-1]545 parser.states = parser.states[:len(parser.states)-1]546 parser.marks = parser.marks[:len(parser.marks)-1]547 *event = yaml_event_t{548 typ: yaml_SEQUENCE_END_EVENT,549 start_mark: token.start_mark,550 end_mark: token.end_mark,551 }552 skip_token(parser)553 return true554 }555 context_mark := parser.marks[len(parser.marks)-1]556 parser.marks = parser.marks[:len(parser.marks)-1]557 return yaml_parser_set_parser_error_context(parser,558 "while parsing a block collection", context_mark,559 "did not find expected '-' indicator", token.start_mark)560}561// Parse the productions:562// indentless_sequence ::= (BLOCK-ENTRY block_node?)+563// *********** *564func yaml_parser_parse_indentless_sequence_entry(parser *yaml_parser_t, event *yaml_event_t) bool {565 token := peek_token(parser)566 if token == nil {567 return false568 }569 if token.typ == yaml_BLOCK_ENTRY_TOKEN {570 mark := token.end_mark571 skip_token(parser)572 token = peek_token(parser)573 if token == nil {574 return false575 }576 if token.typ != yaml_BLOCK_ENTRY_TOKEN &&577 token.typ != yaml_KEY_TOKEN &&578 token.typ != yaml_VALUE_TOKEN &&579 token.typ != yaml_BLOCK_END_TOKEN {580 parser.states = append(parser.states, yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE)581 return yaml_parser_parse_node(parser, event, true, false)582 }583 parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE584 return yaml_parser_process_empty_scalar(parser, event, mark)585 }586 parser.state = parser.states[len(parser.states)-1]587 parser.states = parser.states[:len(parser.states)-1]588 *event = yaml_event_t{589 typ: yaml_SEQUENCE_END_EVENT,590 start_mark: token.start_mark,591 end_mark: token.start_mark, // [Go] Shouldn't this be token.end_mark?592 }593 return true594}595// Parse the productions:596// block_mapping ::= BLOCK-MAPPING_START597// *******************598// ((KEY block_node_or_indentless_sequence?)?599// *** *600// (VALUE block_node_or_indentless_sequence?)?)*601//602// BLOCK-END603// *********604//605func yaml_parser_parse_block_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {606 if first {607 token := peek_token(parser)608 parser.marks = append(parser.marks, token.start_mark)609 skip_token(parser)610 }611 token := peek_token(parser)612 if token == nil {613 return false614 }615 if token.typ == yaml_KEY_TOKEN {616 mark := token.end_mark617 skip_token(parser)618 token = peek_token(parser)619 if token == nil {620 return false621 }622 if token.typ != yaml_KEY_TOKEN &&623 token.typ != yaml_VALUE_TOKEN &&624 token.typ != yaml_BLOCK_END_TOKEN {625 parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_VALUE_STATE)626 return yaml_parser_parse_node(parser, event, true, true)627 } else {628 parser.state = yaml_PARSE_BLOCK_MAPPING_VALUE_STATE629 return yaml_parser_process_empty_scalar(parser, event, mark)630 }631 } else if token.typ == yaml_BLOCK_END_TOKEN {632 parser.state = parser.states[len(parser.states)-1]633 parser.states = parser.states[:len(parser.states)-1]634 parser.marks = parser.marks[:len(parser.marks)-1]635 *event = yaml_event_t{636 typ: yaml_MAPPING_END_EVENT,637 start_mark: token.start_mark,638 end_mark: token.end_mark,639 }640 skip_token(parser)641 return true642 }643 context_mark := parser.marks[len(parser.marks)-1]644 parser.marks = parser.marks[:len(parser.marks)-1]645 return yaml_parser_set_parser_error_context(parser,646 "while parsing a block mapping", context_mark,647 "did not find expected key", token.start_mark)648}649// Parse the productions:650// block_mapping ::= BLOCK-MAPPING_START651//652// ((KEY block_node_or_indentless_sequence?)?653//654// (VALUE block_node_or_indentless_sequence?)?)*655// ***** *656// BLOCK-END657//658//659func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool {660 token := peek_token(parser)661 if token == nil {662 return false663 }664 if token.typ == yaml_VALUE_TOKEN {665 mark := token.end_mark666 skip_token(parser)667 token = peek_token(parser)668 if token == nil {669 return false670 }671 if token.typ != yaml_KEY_TOKEN &&672 token.typ != yaml_VALUE_TOKEN &&673 token.typ != yaml_BLOCK_END_TOKEN {674 parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_KEY_STATE)675 return yaml_parser_parse_node(parser, event, true, true)676 }677 parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE678 return yaml_parser_process_empty_scalar(parser, event, mark)679 }680 parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE681 return yaml_parser_process_empty_scalar(parser, event, token.start_mark)682}683// Parse the productions:684// flow_sequence ::= FLOW-SEQUENCE-START685// *******************686// (flow_sequence_entry FLOW-ENTRY)*687// * **********688// flow_sequence_entry?689// *690// FLOW-SEQUENCE-END691// *****************692// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?693// *694//695func yaml_parser_parse_flow_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {696 if first {697 token := peek_token(parser)698 parser.marks = append(parser.marks, token.start_mark)699 skip_token(parser)700 }701 token := peek_token(parser)702 if token == nil {703 return false704 }705 if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN {706 if !first {707 if token.typ == yaml_FLOW_ENTRY_TOKEN {708 skip_token(parser)709 token = peek_token(parser)710 if token == nil {711 return false712 }713 } else {714 context_mark := parser.marks[len(parser.marks)-1]715 parser.marks = parser.marks[:len(parser.marks)-1]716 return yaml_parser_set_parser_error_context(parser,717 "while parsing a flow sequence", context_mark,718 "did not find expected ',' or ']'", token.start_mark)719 }720 }721 if token.typ == yaml_KEY_TOKEN {722 parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE723 *event = yaml_event_t{724 typ: yaml_MAPPING_START_EVENT,725 start_mark: token.start_mark,726 end_mark: token.end_mark,727 implicit: true,728 style: yaml_style_t(yaml_FLOW_MAPPING_STYLE),729 }730 skip_token(parser)731 return true732 } else if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN {733 parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE)734 return yaml_parser_parse_node(parser, event, false, false)735 }736 }737 parser.state = parser.states[len(parser.states)-1]738 parser.states = parser.states[:len(parser.states)-1]739 parser.marks = parser.marks[:len(parser.marks)-1]740 *event = yaml_event_t{741 typ: yaml_SEQUENCE_END_EVENT,742 start_mark: token.start_mark,743 end_mark: token.end_mark,744 }745 skip_token(parser)746 return true747}748//749// Parse the productions:750// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?751// *** *752//753func yaml_parser_parse_flow_sequence_entry_mapping_key(parser *yaml_parser_t, event *yaml_event_t) bool {754 token := peek_token(parser)755 if token == nil {756 return false757 }758 if token.typ != yaml_VALUE_TOKEN &&759 token.typ != yaml_FLOW_ENTRY_TOKEN &&760 token.typ != yaml_FLOW_SEQUENCE_END_TOKEN {761 parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE)762 return yaml_parser_parse_node(parser, event, false, false)763 }764 mark := token.end_mark765 skip_token(parser)766 parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE767 return yaml_parser_process_empty_scalar(parser, event, mark)768}769// Parse the productions:770// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?771// ***** *772//773func yaml_parser_parse_flow_sequence_entry_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool {774 token := peek_token(parser)775 if token == nil {776 return false777 }778 if token.typ == yaml_VALUE_TOKEN {779 skip_token(parser)780 token := peek_token(parser)781 if token == nil {782 return false783 }784 if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_SEQUENCE_END_TOKEN {785 parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE)786 return yaml_parser_parse_node(parser, event, false, false)787 }788 }789 parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE790 return yaml_parser_process_empty_scalar(parser, event, token.start_mark)791}792// Parse the productions:793// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?794// *795//796func yaml_parser_parse_flow_sequence_entry_mapping_end(parser *yaml_parser_t, event *yaml_event_t) bool {797 token := peek_token(parser)798 if token == nil {799 return false800 }801 parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE802 *event = yaml_event_t{803 typ: yaml_MAPPING_END_EVENT,804 start_mark: token.start_mark,805 end_mark: token.start_mark, // [Go] Shouldn't this be end_mark?806 }807 return true808}809// Parse the productions:810// flow_mapping ::= FLOW-MAPPING-START811// ******************812// (flow_mapping_entry FLOW-ENTRY)*813// * **********814// flow_mapping_entry?815// ******************816// FLOW-MAPPING-END817// ****************818// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?819// * *** *820//821func yaml_parser_parse_flow_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool {822 if first {823 token := peek_token(parser)824 parser.marks = append(parser.marks, token.start_mark)825 skip_token(parser)826 }827 token := peek_token(parser)828 if token == nil {829 return false830 }831 if token.typ != yaml_FLOW_MAPPING_END_TOKEN {832 if !first {833 if token.typ == yaml_FLOW_ENTRY_TOKEN {834 skip_token(parser)835 token = peek_token(parser)836 if token == nil {837 return false838 }839 } else {840 context_mark := parser.marks[len(parser.marks)-1]841 parser.marks = parser.marks[:len(parser.marks)-1]842 return yaml_parser_set_parser_error_context(parser,843 "while parsing a flow mapping", context_mark,844 "did not find expected ',' or '}'", token.start_mark)845 }846 }847 if token.typ == yaml_KEY_TOKEN {848 skip_token(parser)849 token = peek_token(parser)850 if token == nil {851 return false852 }853 if token.typ != yaml_VALUE_TOKEN &&854 token.typ != yaml_FLOW_ENTRY_TOKEN &&855 token.typ != yaml_FLOW_MAPPING_END_TOKEN {856 parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_VALUE_STATE)857 return yaml_parser_parse_node(parser, event, false, false)858 } else {859 parser.state = yaml_PARSE_FLOW_MAPPING_VALUE_STATE860 return yaml_parser_process_empty_scalar(parser, event, token.start_mark)861 }862 } else if token.typ != yaml_FLOW_MAPPING_END_TOKEN {863 parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE)864 return yaml_parser_parse_node(parser, event, false, false)865 }866 }867 parser.state = parser.states[len(parser.states)-1]868 parser.states = parser.states[:len(parser.states)-1]869 parser.marks = parser.marks[:len(parser.marks)-1]870 *event = yaml_event_t{871 typ: yaml_MAPPING_END_EVENT,872 start_mark: token.start_mark,873 end_mark: token.end_mark,874 }875 skip_token(parser)876 return true877}878// Parse the productions:879// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?880// * ***** *881//882func yaml_parser_parse_flow_mapping_value(parser *yaml_parser_t, event *yaml_event_t, empty bool) bool {883 token := peek_token(parser)884 if token == nil {885 return false886 }887 if empty {888 parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE889 return yaml_parser_process_empty_scalar(parser, event, token.start_mark)890 }891 if token.typ == yaml_VALUE_TOKEN {892 skip_token(parser)893 token = peek_token(parser)894 if token == nil {895 return false896 }897 if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_MAPPING_END_TOKEN {898 parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_KEY_STATE)899 return yaml_parser_parse_node(parser, event, false, false)900 }901 }902 parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE903 return yaml_parser_process_empty_scalar(parser, event, token.start_mark)904}905// Generate an empty scalar event.906func yaml_parser_process_empty_scalar(parser *yaml_parser_t, event *yaml_event_t, mark yaml_mark_t) bool {907 *event = yaml_event_t{908 typ: yaml_SCALAR_EVENT,909 start_mark: mark,910 end_mark: mark,911 value: nil, // Empty912 implicit: true,913 style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE),914 }915 return true916}917var default_tag_directives = []yaml_tag_directive_t{918 {[]byte("!"), []byte("!")},919 {[]byte("!!"), []byte("tag:yaml.org,2002:")},920}921// Parse directives.922func yaml_parser_process_directives(parser *yaml_parser_t,923 version_directive_ref **yaml_version_directive_t,924 tag_directives_ref *[]yaml_tag_directive_t) bool {925 var version_directive *yaml_version_directive_t926 var tag_directives []yaml_tag_directive_t927 token := peek_token(parser)928 if token == nil {929 return false930 }931 for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN {932 if token.typ == yaml_VERSION_DIRECTIVE_TOKEN {933 if version_directive != nil {934 yaml_parser_set_parser_error(parser,935 "found duplicate %YAML directive", token.start_mark)936 return false937 }938 if token.major != 1 || token.minor != 1 {939 yaml_parser_set_parser_error(parser,940 "found incompatible YAML document", token.start_mark)941 return false942 }943 version_directive = &yaml_version_directive_t{944 major: token.major,945 minor: token.minor,946 }947 } else if token.typ == yaml_TAG_DIRECTIVE_TOKEN {948 value := yaml_tag_directive_t{949 handle: token.value,950 prefix: token.prefix,951 }952 if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) {953 return false954 }955 tag_directives = append(tag_directives, value)956 }957 skip_token(parser)958 token = peek_token(parser)959 if token == nil {960 return false961 }962 }963 for i := range default_tag_directives {964 if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) {965 return false966 }967 }968 if version_directive_ref != nil {969 *version_directive_ref = version_directive970 }971 if tag_directives_ref != nil {972 *tag_directives_ref = tag_directives973 }974 return true975}976// Append a tag directive to the directives stack.977func yaml_parser_append_tag_directive(parser *yaml_parser_t, value yaml_tag_directive_t, allow_duplicates bool, mark yaml_mark_t) bool {978 for i := range parser.tag_directives {979 if bytes.Equal(value.handle, parser.tag_directives[i].handle) {980 if allow_duplicates {981 return true982 }983 return yaml_parser_set_parser_error(parser, "found duplicate %TAG directive", mark)984 }985 }986 // [Go] I suspect the copy is unnecessary. This was likely done987 // because there was no way to track ownership of the data.988 value_copy := yaml_tag_directive_t{989 handle: make([]byte, len(value.handle)),990 prefix: make([]byte, len(value.prefix)),991 }992 copy(value_copy.handle, value.handle)993 copy(value_copy.prefix, value.prefix)994 parser.tag_directives = append(parser.tag_directives, value_copy)995 return true996}...
ConnectionStringParserTest.php
Source:ConnectionStringParserTest.php
...37 * @link https://github.com/windowsazure/azure-sdk-for-php38 */39class ConnectionStringParserTest extends \PHPUnit_Framework_TestCase40{41 private function _parseTest($connectionString)42 {43 // Setup44 $arguments = func_get_args();45 $count = func_num_args();46 $expected = array();47 for ($i = 1; $i < $count; $i += 2) {48 $expected[$arguments[$i]] = $arguments[$i + 1];49 }50 // Test51 $actual = ConnectionStringParser::parseConnectionString('connectionString', $connectionString);52 // Assert53 $this->assertEquals($expected, $actual);54 }55 private function _parseTestFail($value)56 {57 // Setup58 $this->setExpectedException('\RuntimeException');59 // Test60 ConnectionStringParser::parseConnectionString('connectionString', $value);61 }62 /**63 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::parseConnectionString 64 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::__construct65 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_parse66 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_createException67 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipWhiteSpaces68 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractKey69 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractString70 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipOperator71 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractValue72 */73 public function testKeyNames()74 {75 $this->_parseTest('a=b', 'a', 'b');76 $this->_parseTest(' a =b; c = d', 'a', 'b', 'c', 'd');77 $this->_parseTest('a b=c', 'a b', 'c');78 $this->_parseTest("'a b'=c", 'a b', 'c');79 $this->_parseTest('"a b"=c', 'a b', 'c');80 $this->_parseTest('"a=b"=c', 'a=b', 'c');81 $this->_parseTest('a=b=c', 'a', 'b=c');82 $this->_parseTest("'a='=b", 'a=', 'b');83 $this->_parseTest('"a="=b', 'a=', 'b');84 $this->_parseTest("\"a'b\"=c", "a'b", 'c');85 $this->_parseTest("'a\"b'=c", 'a"b', 'c');86 $this->_parseTest("a'b=c", "a'b", 'c');87 $this->_parseTest('a"b=c', 'a"b', 'c');88 $this->_parseTest("a'=b", "a'", 'b');89 $this->_parseTest('a"=b', 'a"', 'b');90 }91 /**92 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::parseConnectionString 93 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::__construct94 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_parse95 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_createException96 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipWhiteSpaces97 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractKey98 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractString99 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipOperator100 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractValue101 */102 public function testAssignments()103 {104 $this->_parseTest('a=b', 'a', 'b');105 $this->_parseTest('a = b', 'a', 'b');106 $this->_parseTest('a==b', 'a', '=b');107 }108 /**109 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::parseConnectionString 110 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::__construct111 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_parse112 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_createException113 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipWhiteSpaces114 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractKey115 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractString116 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipOperator117 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractValue118 */119 public function testValues()120 {121 $this->_parseTest('a=b', 'a', 'b');122 $this->_parseTest('a= b ', 'a', 'b');123 $this->_parseTest('a= b ;c= d;', 'a', 'b', 'c', 'd');124 $this->_parseTest('a=', 'a', '');125 $this->_parseTest('a=;', 'a', '');126 $this->_parseTest('a=;b=', 'a', '', 'b', '');127 $this->_parseTest('a==b', 'a', '=b');128 $this->_parseTest('a=b=;c==d=', 'a', 'b=', 'c', '=d=');129 $this->_parseTest("a='b c'", 'a', 'b c');130 $this->_parseTest('a="b c"', 'a', 'b c');131 $this->_parseTest("a=\"b'c\"", 'a', "b'c");132 $this->_parseTest("a='b\"c'", 'a', 'b"c');133 $this->_parseTest("a='b=c'", 'a', 'b=c');134 $this->_parseTest('a="b=c"', 'a', 'b=c');135 $this->_parseTest("a='b;c=d'", 'a', 'b;c=d');136 $this->_parseTest('a="b;c=d"', 'a', 'b;c=d');137 $this->_parseTest("a='b c' ", 'a', 'b c');138 $this->_parseTest('a="b c" ', 'a', 'b c');139 $this->_parseTest("a=b'c", 'a', "b'c");140 $this->_parseTest('a=b"c', 'a', 'b"c');141 $this->_parseTest("a=b'", 'a', "b'");142 $this->_parseTest('a=b"', 'a', 'b"');143 }144 /**145 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::parseConnectionString 146 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::__construct147 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_parse148 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_createException149 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipWhiteSpaces150 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractKey151 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractString152 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipOperator153 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractValue154 */155 public function testSeparators()156 {157 $this->_parseTest('a=b;', 'a', 'b');158 $this->_parseTest('a=b', 'a', 'b');159 $this->_parseTest('a=b;c=d', 'a', 'b', 'c', 'd');160 $this->_parseTest('a=b;c=d;', 'a', 'b', 'c', 'd');161 $this->_parseTest('a=b ; c=d', 'a', 'b', 'c', 'd');162 }163 /**164 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::parseConnectionString 165 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::__construct166 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_parse167 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_createException168 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipWhiteSpaces169 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractKey170 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractString171 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_skipOperator172 * @covers WindowsAzure\Common\Internal\ConnectionStringParser::_extractValue173 */174 public function testInvalidInputFail()175 {176 $this->_parseTestFail(';'); // Separator without an assignment;177 $this->_parseTestFail('=b'); // Missing key name;178 $this->_parseTestFail("''=b"); // Empty key name;179 $this->_parseTestFail('""=b'); // Empty key name;180 $this->_parseTestFail('test'); // Missing assignment;181 $this->_parseTestFail(';a=b'); // Separator without key=value;182 $this->_parseTestFail('a=b;;'); // Two separators at the end;183 $this->_parseTestFail('a=b;;c=d'); // Two separators in the middle.184 $this->_parseTestFail("'a=b"); // Runaway single-quoted string at the beginning of the key name;185 $this->_parseTestFail('"a=b'); // Runaway double-quoted string at the beginning of the key name;186 $this->_parseTestFail("'=b"); // Runaway single-quoted string in key name;187 $this->_parseTestFail('"=b'); // Runaway double-quoted string in key name;188 $this->_parseTestFail("a='b"); // Runaway single-quoted string in value;189 $this->_parseTestFail('a="b'); // Runaway double-quoted string in value;190 $this->_parseTestFail("a='b'c"); // Extra character after single-quoted value;191 $this->_parseTestFail('a="b"c'); // Extra character after double-quoted value;192 $this->_parseTestFail("'a'b=c"); // Extra character after single-quoted key;193 $this->_parseTestFail('"a"b=c'); // Extra character after double-quoted key;194 }195}...
xml_test.php
Source:xml_test.php
...3require_once(dirname(__FILE__) . '/../autorun.php');4require_once(dirname(__FILE__) . '/../xml.php');5Mock::generate('SimpleScorer');67if (! function_exists('xml_parser_create')) {8 SimpleTest::ignore('TestOfXmlStructureParsing');9 SimpleTest::ignore('TestOfXmlResultsParsing');10}1112class TestOfNestingTags extends UnitTestCase {13 function testGroupSize() {14 $nesting = new NestingGroupTag(array('SIZE' => 2));15 $this->assertEqual($nesting->getSize(), 2);16 }17}1819class TestOfXmlStructureParsing extends UnitTestCase {20 function testValidXml() {21 $listener = new MockSimpleScorer();22 $listener->expectNever('paintGroupStart');23 $listener->expectNever('paintGroupEnd');24 $listener->expectNever('paintCaseStart');25 $listener->expectNever('paintCaseEnd');26 $parser = new SimpleTestXmlParser($listener);27 $this->assertTrue($parser->parse("<?xml version=\"1.0\"?>\n"));28 $this->assertTrue($parser->parse("<run>\n"));29 $this->assertTrue($parser->parse("</run>\n"));30 }3132 function testEmptyGroup() {33 $listener = new MockSimpleScorer();34 $listener->expectOnce('paintGroupStart', array('a_group', 7));35 $listener->expectOnce('paintGroupEnd', array('a_group'));36 $parser = new SimpleTestXmlParser($listener);37 $parser->parse("<?xml version=\"1.0\"?>\n");38 $parser->parse("<run>\n");39 $this->assertTrue($parser->parse("<group size=\"7\">\n"));40 $this->assertTrue($parser->parse("<name>a_group</name>\n"));41 $this->assertTrue($parser->parse("</group>\n"));42 $parser->parse("</run>\n");43 }4445 function testEmptyCase() {46 $listener = new MockSimpleScorer();47 $listener->expectOnce('paintCaseStart', array('a_case'));48 $listener->expectOnce('paintCaseEnd', array('a_case'));49 $parser = new SimpleTestXmlParser($listener);50 $parser->parse("<?xml version=\"1.0\"?>\n");51 $parser->parse("<run>\n");52 $this->assertTrue($parser->parse("<case>\n"));53 $this->assertTrue($parser->parse("<name>a_case</name>\n"));54 $this->assertTrue($parser->parse("</case>\n"));55 $parser->parse("</run>\n");56 }5758 function testEmptyMethod() {59 $listener = new MockSimpleScorer();60 $listener->expectOnce('paintCaseStart', array('a_case'));61 $listener->expectOnce('paintCaseEnd', array('a_case'));62 $listener->expectOnce('paintMethodStart', array('a_method'));63 $listener->expectOnce('paintMethodEnd', array('a_method'));64 $parser = new SimpleTestXmlParser($listener);65 $parser->parse("<?xml version=\"1.0\"?>\n");66 $parser->parse("<run>\n");67 $parser->parse("<case>\n");68 $parser->parse("<name>a_case</name>\n");69 $this->assertTrue($parser->parse("<test>\n"));70 $this->assertTrue($parser->parse("<name>a_method</name>\n"));71 $this->assertTrue($parser->parse("</test>\n"));72 $parser->parse("</case>\n");73 $parser->parse("</run>\n");74 }7576 function testNestedGroup() {77 $listener = new MockSimpleScorer();78 $listener->expectAt(0, 'paintGroupStart', array('a_group', 7));79 $listener->expectAt(1, 'paintGroupStart', array('b_group', 3));80 $listener->expectCallCount('paintGroupStart', 2);81 $listener->expectAt(0, 'paintGroupEnd', array('b_group'));82 $listener->expectAt(1, 'paintGroupEnd', array('a_group'));83 $listener->expectCallCount('paintGroupEnd', 2);8485 $parser = new SimpleTestXmlParser($listener);86 $parser->parse("<?xml version=\"1.0\"?>\n");87 $parser->parse("<run>\n");8889 $this->assertTrue($parser->parse("<group size=\"7\">\n"));90 $this->assertTrue($parser->parse("<name>a_group</name>\n"));91 $this->assertTrue($parser->parse("<group size=\"3\">\n"));92 $this->assertTrue($parser->parse("<name>b_group</name>\n"));93 $this->assertTrue($parser->parse("</group>\n"));94 $this->assertTrue($parser->parse("</group>\n"));95 $parser->parse("</run>\n");96 }97}9899class AnyOldSignal {100 public $stuff = true;101}102103class TestOfXmlResultsParsing extends UnitTestCase {104105 function sendValidStart(&$parser) {106 $parser->parse("<?xml version=\"1.0\"?>\n");107 $parser->parse("<run>\n");108 $parser->parse("<case>\n");109 $parser->parse("<name>a_case</name>\n");110 $parser->parse("<test>\n");111 $parser->parse("<name>a_method</name>\n");112 }113114 function sendValidEnd(&$parser) {115 $parser->parse("</test>\n");116 $parser->parse("</case>\n");117 $parser->parse("</run>\n");118 }119120 function testPass() {121 $listener = new MockSimpleScorer();122 $listener->expectOnce('paintPass', array('a_message'));123 $parser = new SimpleTestXmlParser($listener);124 $this->sendValidStart($parser);125 $this->assertTrue($parser->parse("<pass>a_message</pass>\n"));126 $this->sendValidEnd($parser);127 }128129 function testFail() {130 $listener = new MockSimpleScorer();131 $listener->expectOnce('paintFail', array('a_message'));132 $parser = new SimpleTestXmlParser($listener);133 $this->sendValidStart($parser);134 $this->assertTrue($parser->parse("<fail>a_message</fail>\n"));135 $this->sendValidEnd($parser);136 }137138 function testException() {139 $listener = new MockSimpleScorer();140 $listener->expectOnce('paintError', array('a_message'));141 $parser = new SimpleTestXmlParser($listener);142 $this->sendValidStart($parser);143 $this->assertTrue($parser->parse("<exception>a_message</exception>\n"));144 $this->sendValidEnd($parser);145 }146147 function testSkip() {148 $listener = new MockSimpleScorer();149 $listener->expectOnce('paintSkip', array('a_message'));150 $parser = new SimpleTestXmlParser($listener);151 $this->sendValidStart($parser);152 $this->assertTrue($parser->parse("<skip>a_message</skip>\n"));153 $this->sendValidEnd($parser);154 }155156 function testSignal() {157 $signal = new AnyOldSignal();158 $signal->stuff = "Hello";159 $listener = new MockSimpleScorer();160 $listener->expectOnce('paintSignal', array('a_signal', $signal));161 $parser = new SimpleTestXmlParser($listener);162 $this->sendValidStart($parser);163 $this->assertTrue($parser->parse(164 "<signal type=\"a_signal\"><![CDATA[" .165 serialize($signal) . "]]></signal>\n"));166 $this->sendValidEnd($parser);167 }168169 function testMessage() {170 $listener = new MockSimpleScorer();171 $listener->expectOnce('paintMessage', array('a_message'));172 $parser = new SimpleTestXmlParser($listener);173 $this->sendValidStart($parser);174 $this->assertTrue($parser->parse("<message>a_message</message>\n"));175 $this->sendValidEnd($parser);176 }177178 function testFormattedMessage() {179 $listener = new MockSimpleScorer();180 $listener->expectOnce('paintFormattedMessage', array("\na\tmessage\n"));181 $parser = new SimpleTestXmlParser($listener);182 $this->sendValidStart($parser);183 $this->assertTrue($parser->parse("<formatted><![CDATA[\na\tmessage\n]]></formatted>\n"));184 $this->sendValidEnd($parser);185 }186}
...
apiparser_visitor.go
Source:apiparser_visitor.go
1package api // ApiParser2import "github.com/zeromicro/antlr"3// A complete Visitor for a parse tree produced by ApiParserParser.4type ApiParserVisitor interface {5 antlr.ParseTreeVisitor6 // Visit a parse tree produced by ApiParserParser#api.7 VisitApi(ctx *ApiContext) interface{}8 // Visit a parse tree produced by ApiParserParser#spec.9 VisitSpec(ctx *SpecContext) interface{}10 // Visit a parse tree produced by ApiParserParser#syntaxLit.11 VisitSyntaxLit(ctx *SyntaxLitContext) interface{}12 // Visit a parse tree produced by ApiParserParser#importSpec.13 VisitImportSpec(ctx *ImportSpecContext) interface{}14 // Visit a parse tree produced by ApiParserParser#importLit.15 VisitImportLit(ctx *ImportLitContext) interface{}16 // Visit a parse tree produced by ApiParserParser#importBlock.17 VisitImportBlock(ctx *ImportBlockContext) interface{}18 // Visit a parse tree produced by ApiParserParser#importBlockValue.19 VisitImportBlockValue(ctx *ImportBlockValueContext) interface{}20 // Visit a parse tree produced by ApiParserParser#importValue.21 VisitImportValue(ctx *ImportValueContext) interface{}22 // Visit a parse tree produced by ApiParserParser#infoSpec.23 VisitInfoSpec(ctx *InfoSpecContext) interface{}24 // Visit a parse tree produced by ApiParserParser#typeSpec.25 VisitTypeSpec(ctx *TypeSpecContext) interface{}26 // Visit a parse tree produced by ApiParserParser#typeLit.27 VisitTypeLit(ctx *TypeLitContext) interface{}28 // Visit a parse tree produced by ApiParserParser#typeBlock.29 VisitTypeBlock(ctx *TypeBlockContext) interface{}30 // Visit a parse tree produced by ApiParserParser#typeLitBody.31 VisitTypeLitBody(ctx *TypeLitBodyContext) interface{}32 // Visit a parse tree produced by ApiParserParser#typeBlockBody.33 VisitTypeBlockBody(ctx *TypeBlockBodyContext) interface{}34 // Visit a parse tree produced by ApiParserParser#typeStruct.35 VisitTypeStruct(ctx *TypeStructContext) interface{}36 // Visit a parse tree produced by ApiParserParser#typeAlias.37 VisitTypeAlias(ctx *TypeAliasContext) interface{}38 // Visit a parse tree produced by ApiParserParser#typeBlockStruct.39 VisitTypeBlockStruct(ctx *TypeBlockStructContext) interface{}40 // Visit a parse tree produced by ApiParserParser#typeBlockAlias.41 VisitTypeBlockAlias(ctx *TypeBlockAliasContext) interface{}42 // Visit a parse tree produced by ApiParserParser#field.43 VisitField(ctx *FieldContext) interface{}44 // Visit a parse tree produced by ApiParserParser#normalField.45 VisitNormalField(ctx *NormalFieldContext) interface{}46 // Visit a parse tree produced by ApiParserParser#anonymousFiled.47 VisitAnonymousFiled(ctx *AnonymousFiledContext) interface{}48 // Visit a parse tree produced by ApiParserParser#dataType.49 VisitDataType(ctx *DataTypeContext) interface{}50 // Visit a parse tree produced by ApiParserParser#pointerType.51 VisitPointerType(ctx *PointerTypeContext) interface{}52 // Visit a parse tree produced by ApiParserParser#mapType.53 VisitMapType(ctx *MapTypeContext) interface{}54 // Visit a parse tree produced by ApiParserParser#arrayType.55 VisitArrayType(ctx *ArrayTypeContext) interface{}56 // Visit a parse tree produced by ApiParserParser#serviceSpec.57 VisitServiceSpec(ctx *ServiceSpecContext) interface{}58 // Visit a parse tree produced by ApiParserParser#atServer.59 VisitAtServer(ctx *AtServerContext) interface{}60 // Visit a parse tree produced by ApiParserParser#serviceApi.61 VisitServiceApi(ctx *ServiceApiContext) interface{}62 // Visit a parse tree produced by ApiParserParser#serviceRoute.63 VisitServiceRoute(ctx *ServiceRouteContext) interface{}64 // Visit a parse tree produced by ApiParserParser#atDoc.65 VisitAtDoc(ctx *AtDocContext) interface{}66 // Visit a parse tree produced by ApiParserParser#atHandler.67 VisitAtHandler(ctx *AtHandlerContext) interface{}68 // Visit a parse tree produced by ApiParserParser#route.69 VisitRoute(ctx *RouteContext) interface{}70 // Visit a parse tree produced by ApiParserParser#body.71 VisitBody(ctx *BodyContext) interface{}72 // Visit a parse tree produced by ApiParserParser#replybody.73 VisitReplybody(ctx *ReplybodyContext) interface{}74 // Visit a parse tree produced by ApiParserParser#kvLit.75 VisitKvLit(ctx *KvLitContext) interface{}76 // Visit a parse tree produced by ApiParserParser#serviceName.77 VisitServiceName(ctx *ServiceNameContext) interface{}78 // Visit a parse tree produced by ApiParserParser#path.79 VisitPath(ctx *PathContext) interface{}80}...
Parser.parseMacroTag.phpt
Source:Parser.parseMacroTag.phpt
1<?php2/**3 * Test: Nette\Latte\Parser::parseMacroTag().4 *5 * @author David Grudl6 * @package Nette\Latte7 * @subpackage UnitTests8 */9use Nette\Latte;10require __DIR__ . '/../bootstrap.php';11require __DIR__ . '/Template.inc';12$parser = new Latte\Parser();13Assert::equal( array('?', 'echo', ''), $parser->parseMacroTag('? echo') );14Assert::equal( array('?', 'echo', ''), $parser->parseMacroTag('?echo') );15Assert::equal( array('?', '', ''), $parser->parseMacroTag('?') );16Assert::equal( array('=', '$var', '|escape'), $parser->parseMacroTag('$var') );17Assert::equal( array('=', '$var', ''), $parser->parseMacroTag('!$var') );18Assert::equal( array('=', '$var', ''), $parser->parseMacroTag('! $var') );19Assert::equal( array('_', '"I love Nette"', ''), $parser->parseMacroTag('!_"I love Nette"') );20Assert::equal( array('_', '$var', '|escape'), $parser->parseMacroTag('_$var') );21Assert::equal( array('_', '$var', '|escape'), $parser->parseMacroTag('_ $var') );22Assert::equal( array('_', '', '|escape'), $parser->parseMacroTag('_') );23Assert::equal( array('/_', '', ''), $parser->parseMacroTag('/_') );24Assert::equal( array('=', '$var', ''), $parser->parseMacroTag('!=$var') );25Assert::equal( array('=', '$var', '|escape'), $parser->parseMacroTag('=$var') );26Assert::equal( array('=', '$var', '|escape'), $parser->parseMacroTag('= $var') );27Assert::equal( array('=', 'function()', '|escape'), $parser->parseMacroTag('function()') );28Assert::equal( array('=', 'md5()', '|escape'), $parser->parseMacroTag('md5()') );29Assert::equal( array('foo:bar', '', ''), $parser->parseMacroTag('foo:bar') );30Assert::equal( array('=', ':bar', '|escape'), $parser->parseMacroTag(':bar') );31Assert::equal( array('=', 'class::member', '|escape'), $parser->parseMacroTag('class::member') );32Assert::equal( array('Link', '$var', ''), $parser->parseMacroTag('Link $var') );33Assert::equal( array('link', '$var', ''), $parser->parseMacroTag('link $var') );34Assert::equal( array('link', '$var', ''), $parser->parseMacroTag('link$var') );35Assert::equal( array('block', '#name', ''), $parser->parseMacroTag('block #name') );36Assert::equal( array('block', '#name', ''), $parser->parseMacroTag('block#name') );37Assert::equal( array('/block', '', ''), $parser->parseMacroTag('/block') );38Assert::equal( array('/block', '#name', ''), $parser->parseMacroTag('/block#name') );39Assert::equal( array('/', '', ''), $parser->parseMacroTag('/') );40Assert::equal( array('l', '', ''), $parser->parseMacroTag('l') );41Assert::equal( array('=', '10', '|escape'), $parser->parseMacroTag('10') );42Assert::equal( array('=', "'str'", '|escape'), $parser->parseMacroTag("'str'") );43Assert::equal( array('=', '+10', '|escape'), $parser->parseMacroTag('+10') );44Assert::equal( array('=', '-10', '|escape'), $parser->parseMacroTag('-10') );...
parse
Using AI Code Generation
1$parser = new Parser();2$parser->parse('1.html');3$parser = new Parser();4$parser->parse('2.html');5$parser = new Parser();6$parser->parse('3.html');7$parser = new Parser();8$parser->parse('4.html');9$parser = new Parser();10$parser->parse('5.html');11$parser = new Parser();12$parser->parse('6.html');13$parser = new Parser();14$parser->parse('7.html');15$parser = new Parser();16$parser->parse('8.html');17$parser = new Parser();18$parser->parse('9.html');19$parser = new Parser();20$parser->parse('10.html');21$parser = new Parser();22$parser->parse('11.html');23$parser = new Parser();24$parser->parse('12.html');25$parser = new Parser();26$parser->parse('13.html');27$parser = new Parser();28$parser->parse('14.html');29$parser = new Parser();30$parser->parse('15.html');31$parser = new Parser();32$parser->parse('16.html');
parse
Using AI Code Generation
1require_once('parser.php');2$parser = new Parser();3$parser->parse('test.php');4require_once('parser.php');5$parser = new Parser();6$parser->parse('test.php');7require_once('parser.php');8$parser = new Parser();9$parser->parse('test.php');10require_once('parser.php');11$parser = new Parser();12$parser->parse('test.php');13require_once('parser.php');14$parser = new Parser();15$parser->parse('test.php');16require_once('parser.php');17$parser = new Parser();18$parser->parse('test.php');19require_once('parser.php');20$parser = new Parser();21$parser->parse('test.php');22require_once('parser.php');23$parser = new Parser();24$parser->parse('test.php');25require_once('parser.php');26$parser = new Parser();27$parser->parse('test.php');28require_once('parser.php');29$parser = new Parser();30$parser->parse('test.php');
parse
Using AI Code Generation
1$parser = new Parser();2$parser->parse($path, $file_name);3$parser = new Parser();4$parser->parse($path, $file_name);5$parser = new Parser();6$parser->parse($path, $file_name);7$parser = new Parser();8$parser->parse($path, $file_name);9$parser = new Parser();10$parser->parse($path, $file_name);11$parser = new Parser();12$parser->parse($path, $file_name);13$parser = new Parser();14$parser->parse($path, $file_name);15$parser = new Parser();16$parser->parse($path, $file_name);17$parser = new Parser();18$parser->parse($path, $file_name);19$parser = new Parser();20$parser->parse($path, $file_name);21How to use PHP parse_ini_file() function?22How to use parse_ini_file() function in PHP?23How to use parse_str() function in PHP?24How to use parse_url() function in PHP?25How to use parse_str() function in PHP?26How to use parse_url() function in PHP?
parse
Using AI Code Generation
1$parser = new Parser();2$parser->parse('test.html', '1.php');3$parser = new Parser();4$parser->parse('test.html', '2.php');5$parser = new Parser();6$parser->parse('test.html', '3.php');7$parser = new Parser();8$parser->parse('test.html', '4.php');9$parser = new Parser();10$parser->parse('test.html', '5.php');11$parser = new Parser();12$parser->parse('test.html', '6.php');13$parser = new Parser();14$parser->parse('test.html', '7.php');15$parser = new Parser();16$parser->parse('test.html', '8.php');17$parser = new Parser();18$parser->parse('test.html', '9.php');19$parser = new Parser();20$parser->parse('test.html', '10.php');21$parser = new Parser();22$parser->parse('test.html', '11.php');23$parser = new Parser();24$parser->parse('test.html', '12.php');25$parser = new Parser();26$parser->parse('test.html', '13.php');
parse
Using AI Code Generation
1require_once('parser.php');2$parser = new parser();3$parser->parse('1.php');4$parser->parse('2.php');5$parser->parse('3.php');6$parser->parse('4.php');7$parser->parse('5.php');8$parser->parse('6.php');9$parser->parse('7.php');10$parser->parse('8.php');11$parser->parse('9.php');12$parser->parse('10.php');13$parser->parse('11.php');14$parser->parse('12.php');15$parser->parse('13.php');16$parser->parse('14.php');17$parser->parse('15.php');18$parser->parse('16.php');19$parser->parse('17.php');20$parser->parse('18.php');21$parser->parse('19.php');22$parser->parse('20.php');23$parser->parse('21.php');24$parser->parse('22.php');25$parser->parse('23.php');26$parser->parse('24.php');27$parser->parse('25.php');28$parser->parse('26.php');29$parser->parse('27.php');30$parser->parse('28.php');31$parser->parse('29.php');
parse
Using AI Code Generation
1require_once 'parser.php';2$parser = new Parser();3$parser->parse();4{5 public function parse()6 {7 }8}9require_once 'parser.php';10$parser = new Parser();11$parser->parse();12{13 public function parse()14 {15 }16}17require_once 'parser.php';18$parser = new Parser();19$parser->parse();20{21 public function parse()22 {23 }24}25require_once 'parser.php';26$parser = new Parser();27$parser->parse();28{29 public function parse()30 {31 }32}33require_once 'parser.php';34$parser = new Parser();35$parser->parse();36{37 public function parse()38 {39 }40}41require_once 'parser.php';42$parser = new Parser();43$parser->parse();44{
parse
Using AI Code Generation
1require_once 'parser.php';2$parser = new Parser();3$parser->parse('test.txt');4 (5 (6 (7 (8 (9 (10 (11 (12 (13 (
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with parse on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!