Best Gauge code snippet using parser.Error
apic.go
Source:apic.go
1package yaml2import (3 "io"4)5func yaml_insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) {6 //fmt.Println("yaml_insert_token", "pos:", pos, "typ:", token.typ, "head:", parser.tokens_head, "len:", len(parser.tokens))7 // Check if we can move the queue at the beginning of the buffer.8 if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) {9 if parser.tokens_head != len(parser.tokens) {10 copy(parser.tokens, parser.tokens[parser.tokens_head:])11 }12 parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head]13 parser.tokens_head = 014 }15 parser.tokens = append(parser.tokens, *token)16 if pos < 0 {17 return18 }19 copy(parser.tokens[parser.tokens_head+pos+1:], parser.tokens[parser.tokens_head+pos:])20 parser.tokens[parser.tokens_head+pos] = *token21}22// Create a new parser object.23func yaml_parser_initialize(parser *yaml_parser_t) bool {24 *parser = yaml_parser_t{25 raw_buffer: make([]byte, 0, input_raw_buffer_size),26 buffer: make([]byte, 0, input_buffer_size),27 }28 return true29}30// Destroy a parser object.31func yaml_parser_delete(parser *yaml_parser_t) {32 *parser = yaml_parser_t{}33}34// String read handler.35func yaml_string_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) {36 if parser.input_pos == len(parser.input) {37 return 0, io.EOF38 }39 n = copy(buffer, parser.input[parser.input_pos:])40 parser.input_pos += n41 return n, nil42}43// Reader read handler.44func yaml_reader_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) {45 return parser.input_reader.Read(buffer)46}47// Set a string input.48func yaml_parser_set_input_string(parser *yaml_parser_t, input []byte) {49 if parser.read_handler != nil {50 panic("must set the input source only once")51 }52 parser.read_handler = yaml_string_read_handler53 parser.input = input54 parser.input_pos = 055}56// Set a file input.57func yaml_parser_set_input_reader(parser *yaml_parser_t, r io.Reader) {58 if parser.read_handler != nil {59 panic("must set the input source only once")60 }61 parser.read_handler = yaml_reader_read_handler62 parser.input_reader = r63}64// Set the source encoding.65func yaml_parser_set_encoding(parser *yaml_parser_t, encoding yaml_encoding_t) {66 if parser.encoding != yaml_ANY_ENCODING {67 panic("must set the encoding only once")68 }69 parser.encoding = encoding70}71var disableLineWrapping = false72// Create a new emitter object.73func yaml_emitter_initialize(emitter *yaml_emitter_t) {74 *emitter = yaml_emitter_t{75 buffer: make([]byte, output_buffer_size),76 raw_buffer: make([]byte, 0, output_raw_buffer_size),77 states: make([]yaml_emitter_state_t, 0, initial_stack_size),78 events: make([]yaml_event_t, 0, initial_queue_size),79 }80 if disableLineWrapping {81 emitter.best_width = -182 }83}84// Destroy an emitter object.85func yaml_emitter_delete(emitter *yaml_emitter_t) {86 *emitter = yaml_emitter_t{}87}88// String write handler.89func yaml_string_write_handler(emitter *yaml_emitter_t, buffer []byte) error {90 *emitter.output_buffer = append(*emitter.output_buffer, buffer...)91 return nil92}93// yaml_writer_write_handler uses emitter.output_writer to write the94// emitted text.95func yaml_writer_write_handler(emitter *yaml_emitter_t, buffer []byte) error {96 _, err := emitter.output_writer.Write(buffer)97 return err98}99// Set a string output.100func yaml_emitter_set_output_string(emitter *yaml_emitter_t, output_buffer *[]byte) {101 if emitter.write_handler != nil {102 panic("must set the output target only once")103 }104 emitter.write_handler = yaml_string_write_handler105 emitter.output_buffer = output_buffer106}107// Set a file output.108func yaml_emitter_set_output_writer(emitter *yaml_emitter_t, w io.Writer) {109 if emitter.write_handler != nil {110 panic("must set the output target only once")111 }112 emitter.write_handler = yaml_writer_write_handler113 emitter.output_writer = w114}115// Set the output encoding.116func yaml_emitter_set_encoding(emitter *yaml_emitter_t, encoding yaml_encoding_t) {117 if emitter.encoding != yaml_ANY_ENCODING {118 panic("must set the output encoding only once")119 }120 emitter.encoding = encoding121}122// Set the canonical output style.123func yaml_emitter_set_canonical(emitter *yaml_emitter_t, canonical bool) {124 emitter.canonical = canonical125}126//// Set the indentation increment.127func yaml_emitter_set_indent(emitter *yaml_emitter_t, indent int) {128 if indent < 2 || indent > 9 {129 indent = 2130 }131 emitter.best_indent = indent132}133// Set the preferred line width.134func yaml_emitter_set_width(emitter *yaml_emitter_t, width int) {135 if width < 0 {136 width = -1137 }138 emitter.best_width = width139}140// Set if unescaped non-ASCII characters are allowed.141func yaml_emitter_set_unicode(emitter *yaml_emitter_t, unicode bool) {142 emitter.unicode = unicode143}144// Set the preferred line break character.145func yaml_emitter_set_break(emitter *yaml_emitter_t, line_break yaml_break_t) {146 emitter.line_break = line_break147}148///*149// * Destroy a token object.150// */151//152//YAML_DECLARE(void)153//yaml_token_delete(yaml_token_t *token)154//{155// assert(token); // Non-NULL token object expected.156//157// switch (token.type)158// {159// case YAML_TAG_DIRECTIVE_TOKEN:160// yaml_free(token.data.tag_directive.handle);161// yaml_free(token.data.tag_directive.prefix);162// break;163//164// case YAML_ALIAS_TOKEN:165// yaml_free(token.data.alias.value);166// break;167//168// case YAML_ANCHOR_TOKEN:169// yaml_free(token.data.anchor.value);170// break;171//172// case YAML_TAG_TOKEN:173// yaml_free(token.data.tag.handle);174// yaml_free(token.data.tag.suffix);175// break;176//177// case YAML_SCALAR_TOKEN:178// yaml_free(token.data.scalar.value);179// break;180//181// default:182// break;183// }184//185// memset(token, 0, sizeof(yaml_token_t));186//}187//188///*189// * Check if a string is a valid UTF-8 sequence.190// *191// * Check 'reader.c' for more details on UTF-8 encoding.192// */193//194//static int195//yaml_check_utf8(yaml_char_t *start, size_t length)196//{197// yaml_char_t *end = start+length;198// yaml_char_t *pointer = start;199//200// while (pointer < end) {201// unsigned char octet;202// unsigned int width;203// unsigned int value;204// size_t k;205//206// octet = pointer[0];207// width = (octet & 0x80) == 0x00 ? 1 :208// (octet & 0xE0) == 0xC0 ? 2 :209// (octet & 0xF0) == 0xE0 ? 3 :210// (octet & 0xF8) == 0xF0 ? 4 : 0;211// value = (octet & 0x80) == 0x00 ? octet & 0x7F :212// (octet & 0xE0) == 0xC0 ? octet & 0x1F :213// (octet & 0xF0) == 0xE0 ? octet & 0x0F :214// (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;215// if (!width) return 0;216// if (pointer+width > end) return 0;217// for (k = 1; k < width; k ++) {218// octet = pointer[k];219// if ((octet & 0xC0) != 0x80) return 0;220// value = (value << 6) + (octet & 0x3F);221// }222// if (!((width == 1) ||223// (width == 2 && value >= 0x80) ||224// (width == 3 && value >= 0x800) ||225// (width == 4 && value >= 0x10000))) return 0;226//227// pointer += width;228// }229//230// return 1;231//}232//233// Create STREAM-START.234func yaml_stream_start_event_initialize(event *yaml_event_t, encoding yaml_encoding_t) {235 *event = yaml_event_t{236 typ: yaml_STREAM_START_EVENT,237 encoding: encoding,238 }239}240// Create STREAM-END.241func yaml_stream_end_event_initialize(event *yaml_event_t) {242 *event = yaml_event_t{243 typ: yaml_STREAM_END_EVENT,244 }245}246// Create DOCUMENT-START.247func yaml_document_start_event_initialize(248 event *yaml_event_t,249 version_directive *yaml_version_directive_t,250 tag_directives []yaml_tag_directive_t,251 implicit bool,252) {253 *event = yaml_event_t{254 typ: yaml_DOCUMENT_START_EVENT,255 version_directive: version_directive,256 tag_directives: tag_directives,257 implicit: implicit,258 }259}260// Create DOCUMENT-END.261func yaml_document_end_event_initialize(event *yaml_event_t, implicit bool) {262 *event = yaml_event_t{263 typ: yaml_DOCUMENT_END_EVENT,264 implicit: implicit,265 }266}267///*268// * Create ALIAS.269// */270//271//YAML_DECLARE(int)272//yaml_alias_event_initialize(event *yaml_event_t, anchor *yaml_char_t)273//{274// mark yaml_mark_t = { 0, 0, 0 }275// anchor_copy *yaml_char_t = NULL276//277// assert(event) // Non-NULL event object is expected.278// assert(anchor) // Non-NULL anchor is expected.279//280// if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0281//282// anchor_copy = yaml_strdup(anchor)283// if (!anchor_copy)284// return 0285//286// ALIAS_EVENT_INIT(*event, anchor_copy, mark, mark)287//288// return 1289//}290// Create SCALAR.291func yaml_scalar_event_initialize(event *yaml_event_t, anchor, tag, value []byte, plain_implicit, quoted_implicit bool, style yaml_scalar_style_t) bool {292 *event = yaml_event_t{293 typ: yaml_SCALAR_EVENT,294 anchor: anchor,295 tag: tag,296 value: value,297 implicit: plain_implicit,298 quoted_implicit: quoted_implicit,299 style: yaml_style_t(style),300 }301 return true302}303// Create SEQUENCE-START.304func yaml_sequence_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_sequence_style_t) bool {305 *event = yaml_event_t{306 typ: yaml_SEQUENCE_START_EVENT,307 anchor: anchor,308 tag: tag,309 implicit: implicit,310 style: yaml_style_t(style),311 }312 return true313}314// Create SEQUENCE-END.315func yaml_sequence_end_event_initialize(event *yaml_event_t) bool {316 *event = yaml_event_t{317 typ: yaml_SEQUENCE_END_EVENT,318 }319 return true320}321// Create MAPPING-START.322func yaml_mapping_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_mapping_style_t) {323 *event = yaml_event_t{324 typ: yaml_MAPPING_START_EVENT,325 anchor: anchor,326 tag: tag,327 implicit: implicit,328 style: yaml_style_t(style),329 }330}331// Create MAPPING-END.332func yaml_mapping_end_event_initialize(event *yaml_event_t) {333 *event = yaml_event_t{334 typ: yaml_MAPPING_END_EVENT,335 }336}337// Destroy an event object.338func yaml_event_delete(event *yaml_event_t) {339 *event = yaml_event_t{}340}341///*342// * Create a document object.343// */344//345//YAML_DECLARE(int)346//yaml_document_initialize(document *yaml_document_t,347// version_directive *yaml_version_directive_t,348// tag_directives_start *yaml_tag_directive_t,349// tag_directives_end *yaml_tag_directive_t,350// start_implicit int, end_implicit int)351//{352// struct {353// error yaml_error_type_t354// } context355// struct {356// start *yaml_node_t357// end *yaml_node_t358// top *yaml_node_t359// } nodes = { NULL, NULL, NULL }360// version_directive_copy *yaml_version_directive_t = NULL361// struct {362// start *yaml_tag_directive_t363// end *yaml_tag_directive_t364// top *yaml_tag_directive_t365// } tag_directives_copy = { NULL, NULL, NULL }366// value yaml_tag_directive_t = { NULL, NULL }367// mark yaml_mark_t = { 0, 0, 0 }368//369// assert(document) // Non-NULL document object is expected.370// assert((tag_directives_start && tag_directives_end) ||371// (tag_directives_start == tag_directives_end))372// // Valid tag directives are expected.373//374// if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error375//376// if (version_directive) {377// version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t))378// if (!version_directive_copy) goto error379// version_directive_copy.major = version_directive.major380// version_directive_copy.minor = version_directive.minor381// }382//383// if (tag_directives_start != tag_directives_end) {384// tag_directive *yaml_tag_directive_t385// if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE))386// goto error387// for (tag_directive = tag_directives_start388// tag_directive != tag_directives_end; tag_directive ++) {389// assert(tag_directive.handle)390// assert(tag_directive.prefix)391// if (!yaml_check_utf8(tag_directive.handle,392// strlen((char *)tag_directive.handle)))393// goto error394// if (!yaml_check_utf8(tag_directive.prefix,395// strlen((char *)tag_directive.prefix)))396// goto error397// value.handle = yaml_strdup(tag_directive.handle)398// value.prefix = yaml_strdup(tag_directive.prefix)399// if (!value.handle || !value.prefix) goto error400// if (!PUSH(&context, tag_directives_copy, value))401// goto error402// value.handle = NULL403// value.prefix = NULL404// }405// }406//407// DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy,408// tag_directives_copy.start, tag_directives_copy.top,409// start_implicit, end_implicit, mark, mark)410//411// return 1412//413//error:414// STACK_DEL(&context, nodes)415// yaml_free(version_directive_copy)416// while (!STACK_EMPTY(&context, tag_directives_copy)) {417// value yaml_tag_directive_t = POP(&context, tag_directives_copy)418// yaml_free(value.handle)419// yaml_free(value.prefix)420// }421// STACK_DEL(&context, tag_directives_copy)422// yaml_free(value.handle)423// yaml_free(value.prefix)424//425// return 0426//}427//428///*429// * Destroy a document object.430// */431//432//YAML_DECLARE(void)433//yaml_document_delete(document *yaml_document_t)434//{435// struct {436// error yaml_error_type_t437// } context438// tag_directive *yaml_tag_directive_t439//440// context.error = YAML_NO_ERROR // Eliminate a compiler warning.441//442// assert(document) // Non-NULL document object is expected.443//444// while (!STACK_EMPTY(&context, document.nodes)) {445// node yaml_node_t = POP(&context, document.nodes)446// yaml_free(node.tag)447// switch (node.type) {448// case YAML_SCALAR_NODE:449// yaml_free(node.data.scalar.value)450// break451// case YAML_SEQUENCE_NODE:452// STACK_DEL(&context, node.data.sequence.items)453// break454// case YAML_MAPPING_NODE:455// STACK_DEL(&context, node.data.mapping.pairs)456// break457// default:458// assert(0) // Should not happen.459// }460// }461// STACK_DEL(&context, document.nodes)462//463// yaml_free(document.version_directive)464// for (tag_directive = document.tag_directives.start465// tag_directive != document.tag_directives.end466// tag_directive++) {467// yaml_free(tag_directive.handle)468// yaml_free(tag_directive.prefix)469// }470// yaml_free(document.tag_directives.start)471//472// memset(document, 0, sizeof(yaml_document_t))473//}474//475///**476// * Get a document node.477// */478//479//YAML_DECLARE(yaml_node_t *)480//yaml_document_get_node(document *yaml_document_t, index int)481//{482// assert(document) // Non-NULL document object is expected.483//484// if (index > 0 && document.nodes.start + index <= document.nodes.top) {485// return document.nodes.start + index - 1486// }487// return NULL488//}489//490///**491// * Get the root object.492// */493//494//YAML_DECLARE(yaml_node_t *)495//yaml_document_get_root_node(document *yaml_document_t)496//{497// assert(document) // Non-NULL document object is expected.498//499// if (document.nodes.top != document.nodes.start) {500// return document.nodes.start501// }502// return NULL503//}504//505///*506// * Add a scalar node to a document.507// */508//509//YAML_DECLARE(int)510//yaml_document_add_scalar(document *yaml_document_t,511// tag *yaml_char_t, value *yaml_char_t, length int,512// style yaml_scalar_style_t)513//{514// struct {515// error yaml_error_type_t516// } context517// mark yaml_mark_t = { 0, 0, 0 }518// tag_copy *yaml_char_t = NULL519// value_copy *yaml_char_t = NULL520// node yaml_node_t521//522// assert(document) // Non-NULL document object is expected.523// assert(value) // Non-NULL value is expected.524//525// if (!tag) {526// tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG527// }528//529// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error530// tag_copy = yaml_strdup(tag)531// if (!tag_copy) goto error532//533// if (length < 0) {534// length = strlen((char *)value)535// }536//537// if (!yaml_check_utf8(value, length)) goto error538// value_copy = yaml_malloc(length+1)539// if (!value_copy) goto error540// memcpy(value_copy, value, length)541// value_copy[length] = '\0'542//543// SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark)544// if (!PUSH(&context, document.nodes, node)) goto error545//546// return document.nodes.top - document.nodes.start547//548//error:549// yaml_free(tag_copy)550// yaml_free(value_copy)551//552// return 0553//}554//555///*556// * Add a sequence node to a document.557// */558//559//YAML_DECLARE(int)560//yaml_document_add_sequence(document *yaml_document_t,561// tag *yaml_char_t, style yaml_sequence_style_t)562//{563// struct {564// error yaml_error_type_t565// } context566// mark yaml_mark_t = { 0, 0, 0 }567// tag_copy *yaml_char_t = NULL568// struct {569// start *yaml_node_item_t570// end *yaml_node_item_t571// top *yaml_node_item_t572// } items = { NULL, NULL, NULL }573// node yaml_node_t574//575// assert(document) // Non-NULL document object is expected.576//577// if (!tag) {578// tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG579// }580//581// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error582// tag_copy = yaml_strdup(tag)583// if (!tag_copy) goto error584//585// if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error586//587// SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,588// style, mark, mark)589// if (!PUSH(&context, document.nodes, node)) goto error590//591// return document.nodes.top - document.nodes.start592//593//error:594// STACK_DEL(&context, items)595// yaml_free(tag_copy)596//597// return 0598//}599//600///*601// * Add a mapping node to a document.602// */603//604//YAML_DECLARE(int)605//yaml_document_add_mapping(document *yaml_document_t,606// tag *yaml_char_t, style yaml_mapping_style_t)607//{608// struct {609// error yaml_error_type_t610// } context611// mark yaml_mark_t = { 0, 0, 0 }612// tag_copy *yaml_char_t = NULL613// struct {614// start *yaml_node_pair_t615// end *yaml_node_pair_t616// top *yaml_node_pair_t617// } pairs = { NULL, NULL, NULL }618// node yaml_node_t619//620// assert(document) // Non-NULL document object is expected.621//622// if (!tag) {623// tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG624// }625//626// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error627// tag_copy = yaml_strdup(tag)628// if (!tag_copy) goto error629//630// if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error631//632// MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end,633// style, mark, mark)634// if (!PUSH(&context, document.nodes, node)) goto error635//636// return document.nodes.top - document.nodes.start637//638//error:639// STACK_DEL(&context, pairs)640// yaml_free(tag_copy)641//642// return 0643//}644//645///*646// * Append an item to a sequence node.647// */648//649//YAML_DECLARE(int)650//yaml_document_append_sequence_item(document *yaml_document_t,651// sequence int, item int)652//{653// struct {654// error yaml_error_type_t655// } context656//657// assert(document) // Non-NULL document is required.658// assert(sequence > 0659// && document.nodes.start + sequence <= document.nodes.top)660// // Valid sequence id is required.661// assert(document.nodes.start[sequence-1].type == YAML_SEQUENCE_NODE)662// // A sequence node is required.663// assert(item > 0 && document.nodes.start + item <= document.nodes.top)664// // Valid item id is required.665//666// if (!PUSH(&context,667// document.nodes.start[sequence-1].data.sequence.items, item))668// return 0669//670// return 1671//}672//673///*674// * Append a pair of a key and a value to a mapping node.675// */676//677//YAML_DECLARE(int)678//yaml_document_append_mapping_pair(document *yaml_document_t,679// mapping int, key int, value int)680//{681// struct {682// error yaml_error_type_t683// } context684//685// pair yaml_node_pair_t686//687// assert(document) // Non-NULL document is required.688// assert(mapping > 0689// && document.nodes.start + mapping <= document.nodes.top)690// // Valid mapping id is required.691// assert(document.nodes.start[mapping-1].type == YAML_MAPPING_NODE)692// // A mapping node is required.693// assert(key > 0 && document.nodes.start + key <= document.nodes.top)694// // Valid key id is required.695// assert(value > 0 && document.nodes.start + value <= document.nodes.top)696// // Valid value id is required.697//698// pair.key = key699// pair.value = value700//701// if (!PUSH(&context,702// document.nodes.start[mapping-1].data.mapping.pairs, pair))703// return 0704//705// return 1706//}707//708//...
apiparser_parser8.go
Source:apiparser_parser8.go
...74 defer func() {75 if err := recover(); err != nil {76 if v, ok := err.(antlr.RecognitionException); ok {77 localctx.SetException(v)78 p.GetErrorHandler().ReportError(p, v)79 p.GetErrorHandler().Recover(p, v)80 } else {81 panic(err)82 }83 }84 }()85 p.EnterOuterAlt(localctx, 1)86 {87 p.SetState(302)88 var _m = p.Match(ApiParserParserT__1)89 localctx.(*BodyContext).lp = _m90 }91 p.SetState(304)92 p.GetErrorHandler().Sync(p)93 _la = p.GetTokenStream().LA(1)94 if _la == ApiParserParserID {95 {96 p.SetState(303)97 p.Match(ApiParserParserID)98 }99 }100 {101 p.SetState(306)102 var _m = p.Match(ApiParserParserT__2)103 localctx.(*BodyContext).rp = _m104 }105 return localctx106}107// IReplybodyContext is an interface to support dynamic dispatch.108type IReplybodyContext interface {109 antlr.ParserRuleContext110 // GetParser returns the parser.111 GetParser() antlr.Parser112 // GetLp returns the lp token.113 GetLp() antlr.Token114 // GetRp returns the rp token.115 GetRp() antlr.Token116 // SetLp sets the lp token.117 SetLp(antlr.Token)118 // SetRp sets the rp token.119 SetRp(antlr.Token)120 // IsReplybodyContext differentiates from other interfaces.121 IsReplybodyContext()122}123type ReplybodyContext struct {124 *antlr.BaseParserRuleContext125 parser antlr.Parser126 lp antlr.Token127 rp antlr.Token128}129func NewEmptyReplybodyContext() *ReplybodyContext {130 var p = new(ReplybodyContext)131 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)132 p.RuleIndex = ApiParserParserRULE_replybody133 return p134}135func (*ReplybodyContext) IsReplybodyContext() {}136func NewReplybodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ReplybodyContext {137 var p = new(ReplybodyContext)138 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)139 p.parser = parser140 p.RuleIndex = ApiParserParserRULE_replybody141 return p142}143func (s *ReplybodyContext) GetParser() antlr.Parser { return s.parser }144func (s *ReplybodyContext) GetLp() antlr.Token { return s.lp }145func (s *ReplybodyContext) GetRp() antlr.Token { return s.rp }146func (s *ReplybodyContext) SetLp(v antlr.Token) { s.lp = v }147func (s *ReplybodyContext) SetRp(v antlr.Token) { s.rp = v }148func (s *ReplybodyContext) DataType() IDataTypeContext {149 var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)150 if t == nil {151 return nil152 }153 return t.(IDataTypeContext)154}155func (s *ReplybodyContext) GetRuleContext() antlr.RuleContext {156 return s157}158func (s *ReplybodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {159 return antlr.TreesStringTree(s, ruleNames, recog)160}161func (s *ReplybodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {162 switch t := visitor.(type) {163 case ApiParserVisitor:164 return t.VisitReplybody(s)165 default:166 return t.VisitChildren(s)167 }168}169func (p *ApiParserParser) Replybody() (localctx IReplybodyContext) {170 localctx = NewReplybodyContext(p, p.GetParserRuleContext(), p.GetState())171 p.EnterRule(localctx, 66, ApiParserParserRULE_replybody)172 var _la int173 defer func() {174 p.ExitRule()175 }()176 defer func() {177 if err := recover(); err != nil {178 if v, ok := err.(antlr.RecognitionException); ok {179 localctx.SetException(v)180 p.GetErrorHandler().ReportError(p, v)181 p.GetErrorHandler().Recover(p, v)182 } else {183 panic(err)184 }185 }186 }()187 p.EnterOuterAlt(localctx, 1)188 {189 p.SetState(308)190 var _m = p.Match(ApiParserParserT__1)191 localctx.(*ReplybodyContext).lp = _m192 }193 p.SetState(310)194 p.GetErrorHandler().Sync(p)195 _la = p.GetTokenStream().LA(1)196 if ((_la)&-(0x1f+1)) == 0 && ((1<<uint(_la))&((1<<ApiParserParserT__5)|(1<<ApiParserParserT__6)|(1<<ApiParserParserT__7)|(1<<ApiParserParserINTERFACE)|(1<<ApiParserParserID))) != 0 {197 {198 p.SetState(309)199 p.DataType()200 }201 }202 {203 p.SetState(312)204 var _m = p.Match(ApiParserParserT__2)205 localctx.(*ReplybodyContext).rp = _m206 }207 return localctx208}209// IKvLitContext is an interface to support dynamic dispatch.210type IKvLitContext interface {211 antlr.ParserRuleContext212 // GetParser returns the parser.213 GetParser() antlr.Parser214 // GetKey returns the key token.215 GetKey() antlr.Token216 // GetValue returns the value token.217 GetValue() antlr.Token218 // SetKey sets the key token.219 SetKey(antlr.Token)220 // SetValue sets the value token.221 SetValue(antlr.Token)222 // IsKvLitContext differentiates from other interfaces.223 IsKvLitContext()224}225type KvLitContext struct {226 *antlr.BaseParserRuleContext227 parser antlr.Parser228 key antlr.Token229 value antlr.Token230}231func NewEmptyKvLitContext() *KvLitContext {232 var p = new(KvLitContext)233 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)234 p.RuleIndex = ApiParserParserRULE_kvLit235 return p236}237func (*KvLitContext) IsKvLitContext() {}238func NewKvLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *KvLitContext {239 var p = new(KvLitContext)240 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)241 p.parser = parser242 p.RuleIndex = ApiParserParserRULE_kvLit243 return p244}245func (s *KvLitContext) GetParser() antlr.Parser { return s.parser }246func (s *KvLitContext) GetKey() antlr.Token { return s.key }247func (s *KvLitContext) GetValue() antlr.Token { return s.value }248func (s *KvLitContext) SetKey(v antlr.Token) { s.key = v }249func (s *KvLitContext) SetValue(v antlr.Token) { s.value = v }250func (s *KvLitContext) ID() antlr.TerminalNode {251 return s.GetToken(ApiParserParserID, 0)252}253func (s *KvLitContext) LINE_VALUE() antlr.TerminalNode {254 return s.GetToken(ApiParserParserLINE_VALUE, 0)255}256func (s *KvLitContext) GetRuleContext() antlr.RuleContext {257 return s258}259func (s *KvLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {260 return antlr.TreesStringTree(s, ruleNames, recog)261}262func (s *KvLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {263 switch t := visitor.(type) {264 case ApiParserVisitor:265 return t.VisitKvLit(s)266 default:267 return t.VisitChildren(s)268 }269}270func (p *ApiParserParser) KvLit() (localctx IKvLitContext) {271 localctx = NewKvLitContext(p, p.GetParserRuleContext(), p.GetState())272 p.EnterRule(localctx, 68, ApiParserParserRULE_kvLit)273 defer func() {274 p.ExitRule()275 }()276 defer func() {277 if err := recover(); err != nil {278 if v, ok := err.(antlr.RecognitionException); ok {279 localctx.SetException(v)280 p.GetErrorHandler().ReportError(p, v)281 p.GetErrorHandler().Recover(p, v)282 } else {283 panic(err)284 }285 }286 }()287 p.EnterOuterAlt(localctx, 1)288 {289 p.SetState(314)290 var _m = p.Match(ApiParserParserID)291 localctx.(*KvLitContext).key = _m292 }293 checkKeyValue(p)294 {295 p.SetState(316)296 var _m = p.Match(ApiParserParserLINE_VALUE)297 localctx.(*KvLitContext).value = _m298 }299 return localctx300}301// IServiceNameContext is an interface to support dynamic dispatch.302type IServiceNameContext interface {303 antlr.ParserRuleContext304 // GetParser returns the parser.305 GetParser() antlr.Parser306 // IsServiceNameContext differentiates from other interfaces.307 IsServiceNameContext()308}309type ServiceNameContext struct {310 *antlr.BaseParserRuleContext311 parser antlr.Parser312}313func NewEmptyServiceNameContext() *ServiceNameContext {314 var p = new(ServiceNameContext)315 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)316 p.RuleIndex = ApiParserParserRULE_serviceName317 return p318}319func (*ServiceNameContext) IsServiceNameContext() {}320func NewServiceNameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceNameContext {321 var p = new(ServiceNameContext)322 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)323 p.parser = parser324 p.RuleIndex = ApiParserParserRULE_serviceName325 return p326}327func (s *ServiceNameContext) GetParser() antlr.Parser { return s.parser }328func (s *ServiceNameContext) AllID() []antlr.TerminalNode {329 return s.GetTokens(ApiParserParserID)330}331func (s *ServiceNameContext) ID(i int) antlr.TerminalNode {332 return s.GetToken(ApiParserParserID, i)333}334func (s *ServiceNameContext) GetRuleContext() antlr.RuleContext {335 return s336}337func (s *ServiceNameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {338 return antlr.TreesStringTree(s, ruleNames, recog)339}340func (s *ServiceNameContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {341 switch t := visitor.(type) {342 case ApiParserVisitor:343 return t.VisitServiceName(s)344 default:345 return t.VisitChildren(s)346 }347}348func (p *ApiParserParser) ServiceName() (localctx IServiceNameContext) {349 localctx = NewServiceNameContext(p, p.GetParserRuleContext(), p.GetState())350 p.EnterRule(localctx, 70, ApiParserParserRULE_serviceName)351 var _la int352 defer func() {353 p.ExitRule()354 }()355 defer func() {356 if err := recover(); err != nil {357 if v, ok := err.(antlr.RecognitionException); ok {358 localctx.SetException(v)359 p.GetErrorHandler().ReportError(p, v)360 p.GetErrorHandler().Recover(p, v)361 } else {362 panic(err)363 }364 }365 }()366 p.EnterOuterAlt(localctx, 1)367 p.SetState(322)368 p.GetErrorHandler().Sync(p)369 for ok := true; ok; ok = _la == ApiParserParserID {370 {371 p.SetState(318)372 p.Match(ApiParserParserID)373 }374 p.SetState(320)375 p.GetErrorHandler().Sync(p)376 _la = p.GetTokenStream().LA(1)377 if _la == ApiParserParserT__9 {378 {379 p.SetState(319)380 p.Match(ApiParserParserT__9)381 }382 }383 p.SetState(324)384 p.GetErrorHandler().Sync(p)385 _la = p.GetTokenStream().LA(1)386 }387 return localctx388}389// IPathContext is an interface to support dynamic dispatch.390type IPathContext interface {391 antlr.ParserRuleContext392 // GetParser returns the parser.393 GetParser() antlr.Parser394 // IsPathContext differentiates from other interfaces.395 IsPathContext()396}397type PathContext struct {398 *antlr.BaseParserRuleContext399 parser antlr.Parser400}401func NewEmptyPathContext() *PathContext {402 var p = new(PathContext)403 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)404 p.RuleIndex = ApiParserParserRULE_path405 return p406}407func (*PathContext) IsPathContext() {}408func NewPathContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PathContext {409 var p = new(PathContext)410 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)411 p.parser = parser412 p.RuleIndex = ApiParserParserRULE_path413 return p414}415func (s *PathContext) GetParser() antlr.Parser { return s.parser }416func (s *PathContext) AllID() []antlr.TerminalNode {417 return s.GetTokens(ApiParserParserID)418}419func (s *PathContext) ID(i int) antlr.TerminalNode {420 return s.GetToken(ApiParserParserID, i)421}422func (s *PathContext) GetRuleContext() antlr.RuleContext {423 return s424}425func (s *PathContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {426 return antlr.TreesStringTree(s, ruleNames, recog)427}428func (s *PathContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {429 switch t := visitor.(type) {430 case ApiParserVisitor:431 return t.VisitPath(s)432 default:433 return t.VisitChildren(s)434 }435}436func (p *ApiParserParser) Path() (localctx IPathContext) {437 localctx = NewPathContext(p, p.GetParserRuleContext(), p.GetState())438 p.EnterRule(localctx, 72, ApiParserParserRULE_path)439 var _la int440 defer func() {441 p.ExitRule()442 }()443 defer func() {444 if err := recover(); err != nil {445 if v, ok := err.(antlr.RecognitionException); ok {446 localctx.SetException(v)447 p.GetErrorHandler().ReportError(p, v)448 p.GetErrorHandler().Recover(p, v)449 } else {450 panic(err)451 }452 }453 }()454 p.SetState(346)455 p.GetErrorHandler().Sync(p)456 switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 39, p.GetParserRuleContext()) {457 case 1:458 p.EnterOuterAlt(localctx, 1)459 p.SetState(341)460 p.GetErrorHandler().Sync(p)461 for ok := true; ok; ok = _la == ApiParserParserT__10 || _la == ApiParserParserT__11 {462 p.SetState(341)463 p.GetErrorHandler().Sync(p)464 switch p.GetTokenStream().LA(1) {465 case ApiParserParserT__10:466 {467 p.SetState(326)468 p.Match(ApiParserParserT__10)469 }470 {471 p.SetState(327)472 p.Match(ApiParserParserID)473 }474 p.SetState(332)475 p.GetErrorHandler().Sync(p)476 _la = p.GetTokenStream().LA(1)477 for _la == ApiParserParserT__9 {478 {479 p.SetState(328)480 p.Match(ApiParserParserT__9)481 }482 {483 p.SetState(329)484 p.Match(ApiParserParserID)485 }486 p.SetState(334)487 p.GetErrorHandler().Sync(p)488 _la = p.GetTokenStream().LA(1)489 }490 case ApiParserParserT__11:491 {492 p.SetState(335)493 p.Match(ApiParserParserT__11)494 }495 {496 p.SetState(336)497 p.Match(ApiParserParserID)498 }499 p.SetState(339)500 p.GetErrorHandler().Sync(p)501 _la = p.GetTokenStream().LA(1)502 if _la == ApiParserParserT__9 {503 {504 p.SetState(337)505 p.Match(ApiParserParserT__9)506 }507 {508 p.SetState(338)509 p.Match(ApiParserParserID)510 }511 }512 default:513 panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))514 }515 p.SetState(343)516 p.GetErrorHandler().Sync(p)517 _la = p.GetTokenStream().LA(1)518 }519 case 2:520 p.EnterOuterAlt(localctx, 2)521 {522 p.SetState(345)523 p.Match(ApiParserParserT__10)524 }525 }526 return localctx527}...
apiparser_parser7.go
Source:apiparser_parser7.go
...85 defer func() {86 if err := recover(); err != nil {87 if v, ok := err.(antlr.RecognitionException); ok {88 localctx.SetException(v)89 p.GetErrorHandler().ReportError(p, v)90 p.GetErrorHandler().Recover(p, v)91 } else {92 panic(err)93 }94 }95 }()96 p.EnterOuterAlt(localctx, 1)97 p.SetState(264)98 p.GetErrorHandler().Sync(p)99 _la = p.GetTokenStream().LA(1)100 if _la == ApiParserParserATDOC {101 {102 p.SetState(263)103 p.AtDoc()104 }105 }106 p.SetState(268)107 p.GetErrorHandler().Sync(p)108 switch p.GetTokenStream().LA(1) {109 case ApiParserParserATSERVER:110 {111 p.SetState(266)112 p.AtServer()113 }114 case ApiParserParserATHANDLER:115 {116 p.SetState(267)117 p.AtHandler()118 }119 default:120 panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))121 }122 {123 p.SetState(270)124 p.Route()125 }126 return localctx127}128// IAtDocContext is an interface to support dynamic dispatch.129type IAtDocContext interface {130 antlr.ParserRuleContext131 // GetParser returns the parser.132 GetParser() antlr.Parser133 // GetLp returns the lp token.134 GetLp() antlr.Token135 // GetRp returns the rp token.136 GetRp() antlr.Token137 // SetLp sets the lp token.138 SetLp(antlr.Token)139 // SetRp sets the rp token.140 SetRp(antlr.Token)141 // IsAtDocContext differentiates from other interfaces.142 IsAtDocContext()143}144type AtDocContext struct {145 *antlr.BaseParserRuleContext146 parser antlr.Parser147 lp antlr.Token148 rp antlr.Token149}150func NewEmptyAtDocContext() *AtDocContext {151 var p = new(AtDocContext)152 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)153 p.RuleIndex = ApiParserParserRULE_atDoc154 return p155}156func (*AtDocContext) IsAtDocContext() {}157func NewAtDocContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtDocContext {158 var p = new(AtDocContext)159 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)160 p.parser = parser161 p.RuleIndex = ApiParserParserRULE_atDoc162 return p163}164func (s *AtDocContext) GetParser() antlr.Parser { return s.parser }165func (s *AtDocContext) GetLp() antlr.Token { return s.lp }166func (s *AtDocContext) GetRp() antlr.Token { return s.rp }167func (s *AtDocContext) SetLp(v antlr.Token) { s.lp = v }168func (s *AtDocContext) SetRp(v antlr.Token) { s.rp = v }169func (s *AtDocContext) ATDOC() antlr.TerminalNode {170 return s.GetToken(ApiParserParserATDOC, 0)171}172func (s *AtDocContext) STRING() antlr.TerminalNode {173 return s.GetToken(ApiParserParserSTRING, 0)174}175func (s *AtDocContext) AllKvLit() []IKvLitContext {176 var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())177 var tst = make([]IKvLitContext, len(ts))178 for i, t := range ts {179 if t != nil {180 tst[i] = t.(IKvLitContext)181 }182 }183 return tst184}185func (s *AtDocContext) KvLit(i int) IKvLitContext {186 var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)187 if t == nil {188 return nil189 }190 return t.(IKvLitContext)191}192func (s *AtDocContext) GetRuleContext() antlr.RuleContext {193 return s194}195func (s *AtDocContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {196 return antlr.TreesStringTree(s, ruleNames, recog)197}198func (s *AtDocContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {199 switch t := visitor.(type) {200 case ApiParserVisitor:201 return t.VisitAtDoc(s)202 default:203 return t.VisitChildren(s)204 }205}206func (p *ApiParserParser) AtDoc() (localctx IAtDocContext) {207 localctx = NewAtDocContext(p, p.GetParserRuleContext(), p.GetState())208 p.EnterRule(localctx, 58, ApiParserParserRULE_atDoc)209 var _la int210 defer func() {211 p.ExitRule()212 }()213 defer func() {214 if err := recover(); err != nil {215 if v, ok := err.(antlr.RecognitionException); ok {216 localctx.SetException(v)217 p.GetErrorHandler().ReportError(p, v)218 p.GetErrorHandler().Recover(p, v)219 } else {220 panic(err)221 }222 }223 }()224 p.EnterOuterAlt(localctx, 1)225 {226 p.SetState(272)227 p.Match(ApiParserParserATDOC)228 }229 p.SetState(274)230 p.GetErrorHandler().Sync(p)231 _la = p.GetTokenStream().LA(1)232 if _la == ApiParserParserT__1 {233 {234 p.SetState(273)235 var _m = p.Match(ApiParserParserT__1)236 localctx.(*AtDocContext).lp = _m237 }238 }239 p.SetState(282)240 p.GetErrorHandler().Sync(p)241 switch p.GetTokenStream().LA(1) {242 case ApiParserParserID:243 p.SetState(277)244 p.GetErrorHandler().Sync(p)245 for ok := true; ok; ok = _la == ApiParserParserID {246 {247 p.SetState(276)248 p.KvLit()249 }250 p.SetState(279)251 p.GetErrorHandler().Sync(p)252 _la = p.GetTokenStream().LA(1)253 }254 case ApiParserParserSTRING:255 {256 p.SetState(281)257 p.Match(ApiParserParserSTRING)258 }259 default:260 panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))261 }262 p.SetState(285)263 p.GetErrorHandler().Sync(p)264 _la = p.GetTokenStream().LA(1)265 if _la == ApiParserParserT__2 {266 {267 p.SetState(284)268 var _m = p.Match(ApiParserParserT__2)269 localctx.(*AtDocContext).rp = _m270 }271 }272 return localctx273}274// IAtHandlerContext is an interface to support dynamic dispatch.275type IAtHandlerContext interface {276 antlr.ParserRuleContext277 // GetParser returns the parser.278 GetParser() antlr.Parser279 // IsAtHandlerContext differentiates from other interfaces.280 IsAtHandlerContext()281}282type AtHandlerContext struct {283 *antlr.BaseParserRuleContext284 parser antlr.Parser285}286func NewEmptyAtHandlerContext() *AtHandlerContext {287 var p = new(AtHandlerContext)288 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)289 p.RuleIndex = ApiParserParserRULE_atHandler290 return p291}292func (*AtHandlerContext) IsAtHandlerContext() {}293func NewAtHandlerContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtHandlerContext {294 var p = new(AtHandlerContext)295 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)296 p.parser = parser297 p.RuleIndex = ApiParserParserRULE_atHandler298 return p299}300func (s *AtHandlerContext) GetParser() antlr.Parser { return s.parser }301func (s *AtHandlerContext) ATHANDLER() antlr.TerminalNode {302 return s.GetToken(ApiParserParserATHANDLER, 0)303}304func (s *AtHandlerContext) ID() antlr.TerminalNode {305 return s.GetToken(ApiParserParserID, 0)306}307func (s *AtHandlerContext) GetRuleContext() antlr.RuleContext {308 return s309}310func (s *AtHandlerContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {311 return antlr.TreesStringTree(s, ruleNames, recog)312}313func (s *AtHandlerContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {314 switch t := visitor.(type) {315 case ApiParserVisitor:316 return t.VisitAtHandler(s)317 default:318 return t.VisitChildren(s)319 }320}321func (p *ApiParserParser) AtHandler() (localctx IAtHandlerContext) {322 localctx = NewAtHandlerContext(p, p.GetParserRuleContext(), p.GetState())323 p.EnterRule(localctx, 60, ApiParserParserRULE_atHandler)324 defer func() {325 p.ExitRule()326 }()327 defer func() {328 if err := recover(); err != nil {329 if v, ok := err.(antlr.RecognitionException); ok {330 localctx.SetException(v)331 p.GetErrorHandler().ReportError(p, v)332 p.GetErrorHandler().Recover(p, v)333 } else {334 panic(err)335 }336 }337 }()338 p.EnterOuterAlt(localctx, 1)339 {340 p.SetState(287)341 p.Match(ApiParserParserATHANDLER)342 }343 {344 p.SetState(288)345 p.Match(ApiParserParserID)346 }347 return localctx348}349// IRouteContext is an interface to support dynamic dispatch.350type IRouteContext interface {351 antlr.ParserRuleContext352 // GetParser returns the parser.353 GetParser() antlr.Parser354 // GetHttpMethod returns the httpMethod token.355 GetHttpMethod() antlr.Token356 // GetReturnToken returns the returnToken token.357 GetReturnToken() antlr.Token358 // SetHttpMethod sets the httpMethod token.359 SetHttpMethod(antlr.Token)360 // SetReturnToken sets the returnToken token.361 SetReturnToken(antlr.Token)362 // GetRequest returns the request rule contexts.363 GetRequest() IBodyContext364 // GetResponse returns the response rule contexts.365 GetResponse() IReplybodyContext366 // SetRequest sets the request rule contexts.367 SetRequest(IBodyContext)368 // SetResponse sets the response rule contexts.369 SetResponse(IReplybodyContext)370 // IsRouteContext differentiates from other interfaces.371 IsRouteContext()372}373type RouteContext struct {374 *antlr.BaseParserRuleContext375 parser antlr.Parser376 httpMethod antlr.Token377 request IBodyContext378 returnToken antlr.Token379 response IReplybodyContext380}381func NewEmptyRouteContext() *RouteContext {382 var p = new(RouteContext)383 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)384 p.RuleIndex = ApiParserParserRULE_route385 return p386}387func (*RouteContext) IsRouteContext() {}388func NewRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RouteContext {389 var p = new(RouteContext)390 p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)391 p.parser = parser392 p.RuleIndex = ApiParserParserRULE_route393 return p394}395func (s *RouteContext) GetParser() antlr.Parser { return s.parser }396func (s *RouteContext) GetHttpMethod() antlr.Token { return s.httpMethod }397func (s *RouteContext) GetReturnToken() antlr.Token { return s.returnToken }398func (s *RouteContext) SetHttpMethod(v antlr.Token) { s.httpMethod = v }399func (s *RouteContext) SetReturnToken(v antlr.Token) { s.returnToken = v }400func (s *RouteContext) GetRequest() IBodyContext { return s.request }401func (s *RouteContext) GetResponse() IReplybodyContext { return s.response }402func (s *RouteContext) SetRequest(v IBodyContext) { s.request = v }403func (s *RouteContext) SetResponse(v IReplybodyContext) { s.response = v }404func (s *RouteContext) Path() IPathContext {405 var t = s.GetTypedRuleContext(reflect.TypeOf((*IPathContext)(nil)).Elem(), 0)406 if t == nil {407 return nil408 }409 return t.(IPathContext)410}411func (s *RouteContext) AllID() []antlr.TerminalNode {412 return s.GetTokens(ApiParserParserID)413}414func (s *RouteContext) ID(i int) antlr.TerminalNode {415 return s.GetToken(ApiParserParserID, i)416}417func (s *RouteContext) Body() IBodyContext {418 var t = s.GetTypedRuleContext(reflect.TypeOf((*IBodyContext)(nil)).Elem(), 0)419 if t == nil {420 return nil421 }422 return t.(IBodyContext)423}424func (s *RouteContext) Replybody() IReplybodyContext {425 var t = s.GetTypedRuleContext(reflect.TypeOf((*IReplybodyContext)(nil)).Elem(), 0)426 if t == nil {427 return nil428 }429 return t.(IReplybodyContext)430}431func (s *RouteContext) GetRuleContext() antlr.RuleContext {432 return s433}434func (s *RouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {435 return antlr.TreesStringTree(s, ruleNames, recog)436}437func (s *RouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {438 switch t := visitor.(type) {439 case ApiParserVisitor:440 return t.VisitRoute(s)441 default:442 return t.VisitChildren(s)443 }444}445func (p *ApiParserParser) Route() (localctx IRouteContext) {446 localctx = NewRouteContext(p, p.GetParserRuleContext(), p.GetState())447 p.EnterRule(localctx, 62, ApiParserParserRULE_route)448 var _la int449 defer func() {450 p.ExitRule()451 }()452 defer func() {453 if err := recover(); err != nil {454 if v, ok := err.(antlr.RecognitionException); ok {455 localctx.SetException(v)456 p.GetErrorHandler().ReportError(p, v)457 p.GetErrorHandler().Recover(p, v)458 } else {459 panic(err)460 }461 }462 }()463 p.EnterOuterAlt(localctx, 1)464 checkHTTPMethod(p)465 {466 p.SetState(291)467 var _m = p.Match(ApiParserParserID)468 localctx.(*RouteContext).httpMethod = _m469 }470 {471 p.SetState(292)472 p.Path()473 }474 p.SetState(294)475 p.GetErrorHandler().Sync(p)476 if p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 28, p.GetParserRuleContext()) == 1 {477 {478 p.SetState(293)479 var _x = p.Body()480 localctx.(*RouteContext).request = _x481 }482 }483 p.SetState(297)484 p.GetErrorHandler().Sync(p)485 _la = p.GetTokenStream().LA(1)486 if _la == ApiParserParserID {487 {488 p.SetState(296)489 var _m = p.Match(ApiParserParserID)490 localctx.(*RouteContext).returnToken = _m491 }492 }493 p.SetState(300)494 p.GetErrorHandler().Sync(p)495 _la = p.GetTokenStream().LA(1)496 if _la == ApiParserParserT__1 {497 {498 p.SetState(299)499 var _x = p.Replybody()500 localctx.(*RouteContext).response = _x501 }502 }503 return localctx504}...
readerc.go
Source:readerc.go
...68 parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)+size_read]69 if err == io.EOF {70 parser.eof = true71 } else if err != nil {72 return yaml_parser_set_reader_error(parser, "input error: "+err.Error(), parser.offset, -1)73 }74 return true75}76// Ensure that the buffer contains at least `length` characters.77// Return true on success, false on failure.78//79// The length is supposed to be significantly less that the buffer size.80func yaml_parser_update_buffer(parser *yaml_parser_t, length int) bool {81 if parser.read_handler == nil {82 panic("read handler must be set")83 }84 // [Go] This function was changed to guarantee the requested length size at EOF.85 // The fact we need to do this is pretty awful, but the description above implies86 // for that to be the case, and there are tests ...
type_test.go
Source:type_test.go
...45 },46 CommentExpr: ast.NewTextExpr("// pointer type"),47 }))48 _, err = parser.Accept(fieldAccept, `interface`)49 assert.Error(t, err)50 _, err = parser.Accept(fieldAccept, `map`)51 assert.Error(t, err)52 })53 t.Run("normal", func(t *testing.T) {54 v, err := parser.Accept(fieldAccept, `User int`)55 assert.Nil(t, err)56 f := v.(*ast.TypeField)57 assert.True(t, f.Equal(&ast.TypeField{58 Name: ast.NewTextExpr("User"),59 DataType: &ast.Literal{Literal: ast.NewTextExpr("int")},60 }))61 v, err = parser.Accept(fieldAccept, `Foo Bar`)62 assert.Nil(t, err)63 f = v.(*ast.TypeField)64 assert.True(t, f.Equal(&ast.TypeField{65 Name: ast.NewTextExpr("Foo"),66 DataType: &ast.Literal{Literal: ast.NewTextExpr("Bar")},67 }))68 v, err = parser.Accept(fieldAccept, `Foo map[int]Bar`)69 assert.Nil(t, err)70 f = v.(*ast.TypeField)71 assert.True(t, f.Equal(&ast.TypeField{72 Name: ast.NewTextExpr("Foo"),73 DataType: &ast.Map{74 MapExpr: ast.NewTextExpr("map[int]Bar"),75 Map: ast.NewTextExpr("map"),76 LBrack: ast.NewTextExpr("["),77 RBrack: ast.NewTextExpr("]"),78 Key: ast.NewTextExpr("int"),79 Value: &ast.Literal{Literal: ast.NewTextExpr("Bar")},80 },81 }))82 })83}84func TestDataType_ID(t *testing.T) {85 dt := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {86 return p.DataType().Accept(visitor)87 }88 t.Run("Struct", func(t *testing.T) {89 v, err := parser.Accept(dt, `Foo`)90 assert.Nil(t, err)91 id := v.(ast.DataType)92 assert.True(t, id.Equal(&ast.Literal{Literal: ast.NewTextExpr("Foo")}))93 })94 t.Run("basic", func(t *testing.T) {95 v, err := parser.Accept(dt, `int`)96 assert.Nil(t, err)97 id := v.(ast.DataType)98 assert.True(t, id.Equal(&ast.Literal{Literal: ast.NewTextExpr("int")}))99 })100 t.Run("wrong", func(t *testing.T) {101 _, err := parser.Accept(dt, `map`)102 assert.Error(t, err)103 })104}105func TestDataType_Map(t *testing.T) {106 dt := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {107 return p.MapType().Accept(visitor)108 }109 t.Run("basicKey", func(t *testing.T) {110 v, err := parser.Accept(dt, `map[int]Bar`)111 assert.Nil(t, err)112 m := v.(ast.DataType)113 assert.True(t, m.Equal(&ast.Map{114 MapExpr: ast.NewTextExpr("map[int]Bar"),115 Map: ast.NewTextExpr("map"),116 LBrack: ast.NewTextExpr("["),117 RBrack: ast.NewTextExpr("]"),118 Key: ast.NewTextExpr("int"),119 Value: &ast.Literal{Literal: ast.NewTextExpr("Bar")},120 }))121 })122 t.Run("wrong", func(t *testing.T) {123 _, err := parser.Accept(dt, `map[var]Bar`)124 assert.Error(t, err)125 _, err = parser.Accept(dt, `map[*User]Bar`)126 assert.Error(t, err)127 _, err = parser.Accept(dt, `map[User]Bar`)128 assert.Error(t, err)129 })130}131func TestDataType_Array(t *testing.T) {132 dt := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {133 return p.ArrayType().Accept(visitor)134 }135 t.Run("basic", func(t *testing.T) {136 v, err := parser.Accept(dt, `[]int`)137 assert.Nil(t, err)138 array := v.(ast.DataType)139 assert.True(t, array.Equal(&ast.Array{140 ArrayExpr: ast.NewTextExpr("[]int"),141 LBrack: ast.NewTextExpr("["),142 RBrack: ast.NewTextExpr("]"),143 Literal: &ast.Literal{Literal: ast.NewTextExpr("int")},144 }))145 })146 t.Run("pointer", func(t *testing.T) {147 v, err := parser.Accept(dt, `[]*User`)148 assert.Nil(t, err)149 array := v.(ast.DataType)150 assert.True(t, array.Equal(&ast.Array{151 ArrayExpr: ast.NewTextExpr("[]*User"),152 LBrack: ast.NewTextExpr("["),153 RBrack: ast.NewTextExpr("]"),154 Literal: &ast.Pointer{155 PointerExpr: ast.NewTextExpr("*User"),156 Star: ast.NewTextExpr("*"),157 Name: ast.NewTextExpr("User"),158 },159 }))160 })161 t.Run("interface{}", func(t *testing.T) {162 v, err := parser.Accept(dt, `[]interface{}`)163 assert.Nil(t, err)164 array := v.(ast.DataType)165 assert.True(t, array.Equal(&ast.Array{166 ArrayExpr: ast.NewTextExpr("[]interface{}"),167 LBrack: ast.NewTextExpr("["),168 RBrack: ast.NewTextExpr("]"),169 Literal: &ast.Interface{Literal: ast.NewTextExpr("interface{}")},170 }))171 })172 t.Run("wrong", func(t *testing.T) {173 _, err := parser.Accept(dt, `[]var`)174 assert.Error(t, err)175 _, err = parser.Accept(dt, `[]interface`)176 assert.Error(t, err)177 })178}179func TestDataType_Interface(t *testing.T) {180 dt := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {181 return p.DataType().Accept(visitor)182 }183 t.Run("normal", func(t *testing.T) {184 v, err := parser.Accept(dt, `interface{}`)185 assert.Nil(t, err)186 inter := v.(ast.DataType)187 assert.True(t, inter.Equal(&ast.Interface{Literal: ast.NewTextExpr("interface{}")}))188 })189 t.Run("wrong", func(t *testing.T) {190 _, err := parser.Accept(dt, `interface`)191 assert.Error(t, err)192 })193 t.Run("wrong", func(t *testing.T) {194 _, err := parser.Accept(dt, `interface{`)195 assert.Error(t, err)196 })197}198func TestDataType_Time(t *testing.T) {199 dt := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {200 return p.DataType().Accept(visitor)201 }202 t.Run("normal", func(t *testing.T) {203 _, err := parser.Accept(dt, `time.Time`)204 assert.Error(t, err)205 })206}207func TestDataType_Pointer(t *testing.T) {208 dt := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {209 return p.PointerType().Accept(visitor)210 }211 t.Run("normal", func(t *testing.T) {212 v, err := parser.Accept(dt, `*int`)213 assert.Nil(t, err)214 assert.True(t, v.(ast.DataType).Equal(&ast.Pointer{215 PointerExpr: ast.NewTextExpr("*int"),216 Star: ast.NewTextExpr("*"),217 Name: ast.NewTextExpr("int"),218 }))219 })220 t.Run("wrong", func(t *testing.T) {221 _, err := parser.Accept(dt, `int`)222 assert.Error(t, err)223 })224}225func TestAlias(t *testing.T) {226 fn := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {227 return p.TypeAlias().Accept(visitor)228 }229 t.Run("normal", func(t *testing.T) {230 _, err := parser.Accept(fn, `Foo int`)231 assert.Error(t, err)232 _, err = parser.Accept(fn, `Foo=int`)233 assert.Error(t, err)234 _, err = parser.Accept(fn, `235 Foo int // comment`)236 assert.Error(t, err)237 _, err = parser.Accept(fn, `238 Foo int /**comment*/`)239 assert.Error(t, err)240 })241 t.Run("wrong", func(t *testing.T) {242 _, err := parser.Accept(fn, `Foo var`)243 assert.Error(t, err)244 _, err = parser.Accept(fn, `Foo 2`)245 assert.Error(t, err)246 })247}248func TestTypeStruct(t *testing.T) {249 fn := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {250 return p.TypeStruct().Accept(visitor)251 }252 t.Run("normal", func(t *testing.T) {253 v, err := parser.Accept(fn, "Foo {\n\t\t\tFoo string\n\t\t\tBar int `json:\"bar\"``\n\t\t}")254 assert.Nil(t, err)255 s := v.(*ast.TypeStruct)256 assert.True(t, s.Equal(&ast.TypeStruct{257 Name: ast.NewTextExpr("Foo"),258 LBrace: ast.NewTextExpr("{"),259 RBrace: ast.NewTextExpr("}"),260 Fields: []*ast.TypeField{261 {262 Name: ast.NewTextExpr("Foo"),263 DataType: &ast.Literal{Literal: ast.NewTextExpr("string")},264 },265 {266 Name: ast.NewTextExpr("Bar"),267 DataType: &ast.Literal{Literal: ast.NewTextExpr("int")},268 Tag: ast.NewTextExpr("`json:\"bar\"`"),269 },270 },271 }))272 v, err = parser.Accept(fn, "Foo struct{\n\t\t\tFoo string\n\t\t\tBar int `json:\"bar\"``\n\t\t}")273 assert.Nil(t, err)274 s = v.(*ast.TypeStruct)275 assert.True(t, s.Equal(&ast.TypeStruct{276 Name: ast.NewTextExpr("Foo"),277 LBrace: ast.NewTextExpr("{"),278 RBrace: ast.NewTextExpr("}"),279 Struct: ast.NewTextExpr("struct"),280 Fields: []*ast.TypeField{281 {282 Name: ast.NewTextExpr("Foo"),283 DataType: &ast.Literal{Literal: ast.NewTextExpr("string")},284 },285 {286 Name: ast.NewTextExpr("Bar"),287 DataType: &ast.Literal{Literal: ast.NewTextExpr("int")},288 Tag: ast.NewTextExpr("`json:\"bar\"`"),289 },290 },291 }))292 })293}294func TestTypeBlock(t *testing.T) {295 fn := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {296 return p.TypeBlock().Accept(visitor)297 }298 t.Run("normal", func(t *testing.T) {299 _, err := parser.Accept(fn, `type(300 // doc301 Foo int302 )`)303 assert.Error(t, err)304 v, err := parser.Accept(fn, `type (305 // doc306 Foo {307 Bar int308 }309 )`)310 assert.Nil(t, err)311 st := v.([]ast.TypeExpr)312 assert.True(t, st[0].Equal(&ast.TypeStruct{313 Name: ast.NewTextExpr("Foo"),314 LBrace: ast.NewTextExpr("{"),315 RBrace: ast.NewTextExpr("}"),316 DocExpr: []ast.Expr{317 ast.NewTextExpr("// doc"),318 },319 Fields: []*ast.TypeField{320 {321 Name: ast.NewTextExpr("Bar"),322 DataType: &ast.Literal{Literal: ast.NewTextExpr("int")},323 },324 },325 }))326 })327}328func TestTypeLit(t *testing.T) {329 fn := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {330 return p.TypeLit().Accept(visitor)331 }332 t.Run("normal", func(t *testing.T) {333 _, err := parser.Accept(fn, `type Foo int`)334 assert.Error(t, err)335 _, err = parser.Accept(fn, `type Foo = int`)336 assert.Error(t, err)337 _, err = parser.Accept(fn, `338 // doc339 type Foo = int // comment`)340 assert.Error(t, err)341 v, err := parser.Accept(fn, `342 // doc343 type Foo {// comment344 Bar int345 }`)346 assert.Nil(t, err)347 st := v.(*ast.TypeStruct)348 assert.True(t, st.Equal(&ast.TypeStruct{349 Name: ast.NewTextExpr("Foo"),350 Fields: []*ast.TypeField{351 {352 Name: ast.NewTextExpr("Bar"),353 DataType: &ast.Literal{Literal: ast.NewTextExpr("int")},354 DocExpr: []ast.Expr{355 ast.NewTextExpr("// comment"),356 },357 },358 },359 DocExpr: []ast.Expr{360 ast.NewTextExpr("// doc"),361 },362 }))363 v, err = parser.Accept(fn, `364 // doc365 type Foo {// comment366 Bar367 }`)368 assert.Nil(t, err)369 st = v.(*ast.TypeStruct)370 assert.True(t, st.Equal(&ast.TypeStruct{371 Name: ast.NewTextExpr("Foo"),372 Fields: []*ast.TypeField{373 {374 IsAnonymous: true,375 DataType: &ast.Literal{Literal: ast.NewTextExpr("Bar")},376 DocExpr: []ast.Expr{377 ast.NewTextExpr("// comment"),378 },379 },380 },381 DocExpr: []ast.Expr{382 ast.NewTextExpr("// doc"),383 },384 }))385 })386 t.Run("wrong", func(t *testing.T) {387 _, err := parser.Accept(fn, `type Foo`)388 assert.Error(t, err)389 })390}391func TestTypeUnExported(t *testing.T) {392 fn := func(p *api.ApiParserParser, visitor *ast.ApiVisitor) interface{} {393 return p.TypeSpec().Accept(visitor)394 }395 t.Run("type", func(t *testing.T) {396 _, err := parser.Accept(fn, `type foo {}`)397 assert.Nil(t, err)398 })399 t.Run("field", func(t *testing.T) {400 _, err := parser.Accept(fn, `type Foo {401 name int402 }`)...
ucd.go
Source:ucd.go
...88 rangeStart, rangeEnd rune89 partHandler func(p *Parser)90 commentHandler func(s string)91}92func (p *Parser) setError(err error, msg string) {93 if p.err == nil && err != nil {94 if msg == "" {95 p.err = fmt.Errorf("ucd:line:%d: %v", p.line, err)96 } else {97 p.err = fmt.Errorf("ucd:line:%d:%s: %v", p.line, msg, err)98 }99 }100}101func (p *Parser) getField(i int) string {102 if i >= len(p.field) {103 return ""104 }105 return p.field[i]106}107// Err returns a non-nil error if any error occurred during parsing.108func (p *Parser) Err() error {109 return p.err110}111// New returns a Parser for the given Reader.112func New(r io.Reader, o ...Option) *Parser {113 p := &Parser{114 scanner: bufio.NewScanner(r),115 }116 for _, f := range o {117 f(p)118 }119 return p120}121// Next parses the next line in the file. It returns true if a line was parsed122// and false if it reached the end of the file.123func (p *Parser) Next() bool {124 if !p.keepRanges && p.rangeStart < p.rangeEnd {125 p.rangeStart++126 return true127 }128 p.comment = ""129 p.field = p.field[:0]130 p.parsedRange = false131 for p.scanner.Scan() && p.err == nil {132 p.line++133 s := p.scanner.Text()134 if s == "" {135 continue136 }137 if s[0] == '#' {138 if p.commentHandler != nil {139 p.commentHandler(strings.TrimSpace(s[1:]))140 }141 continue142 }143 // Parse line144 if i := strings.IndexByte(s, '#'); i != -1 {145 p.comment = strings.TrimSpace(s[i+1:])146 s = s[:i]147 }148 if s[0] == '@' {149 if p.partHandler != nil {150 p.field = append(p.field, strings.TrimSpace(s[1:]))151 p.partHandler(p)152 p.field = p.field[:0]153 }154 p.comment = ""155 continue156 }157 for {158 i := strings.IndexByte(s, ';')159 if i == -1 {160 p.field = append(p.field, strings.TrimSpace(s))161 break162 }163 p.field = append(p.field, strings.TrimSpace(s[:i]))164 s = s[i+1:]165 }166 if !p.keepRanges {167 p.rangeStart, p.rangeEnd = p.getRange(0)168 }169 return true170 }171 p.setError(p.scanner.Err(), "scanner failed")172 return false173}174func parseRune(b string) (rune, error) {175 if len(b) > 2 && b[0] == 'U' && b[1] == '+' {176 b = b[2:]177 }178 x, err := strconv.ParseUint(b, 16, 32)179 return rune(x), err180}181func (p *Parser) parseRune(s string) rune {182 x, err := parseRune(s)183 p.setError(err, "failed to parse rune")184 return x185}186// Rune parses and returns field i as a rune.187func (p *Parser) Rune(i int) rune {188 if i > 0 || p.keepRanges {189 return p.parseRune(p.getField(i))190 }191 return p.rangeStart192}193// Runes interprets and returns field i as a sequence of runes.194func (p *Parser) Runes(i int) (runes []rune) {195 add := func(s string) {196 if s = strings.TrimSpace(s); len(s) > 0 {197 runes = append(runes, p.parseRune(s))198 }199 }200 for b := p.getField(i); ; {201 i := strings.IndexByte(b, ' ')202 if i == -1 {203 add(b)204 break205 }206 add(b[:i])207 b = b[i+1:]208 }209 return210}211var (212 errIncorrectLegacyRange = errors.New("ucd: unmatched <* First>")213 // reRange matches one line of a legacy rune range.214 reRange = regexp.MustCompile("^([0-9A-F]*);<([^,]*), ([^>]*)>(.*)$")215)216// Range parses and returns field i as a rune range. A range is inclusive at217// both ends. If the field only has one rune, first and last will be identical.218// It supports the legacy format for ranges used in UnicodeData.txt.219func (p *Parser) Range(i int) (first, last rune) {220 if !p.keepRanges {221 return p.rangeStart, p.rangeStart222 }223 return p.getRange(i)224}225func (p *Parser) getRange(i int) (first, last rune) {226 b := p.getField(i)227 if k := strings.Index(b, ".."); k != -1 {228 return p.parseRune(b[:k]), p.parseRune(b[k+2:])229 }230 // The first field may not be a rune, in which case we may ignore any error231 // and set the range as 0..0.232 x, err := parseRune(b)233 if err != nil {234 // Disable range parsing henceforth. This ensures that an error will be235 // returned if the user subsequently will try to parse this field as236 // a Rune.237 p.keepRanges = true238 }239 // Special case for UnicodeData that was retained for backwards compatibility.240 if i == 0 && len(p.field) > 1 && strings.HasSuffix(p.field[1], "First>") {241 if p.parsedRange {242 return p.rangeStart, p.rangeEnd243 }244 mf := reRange.FindStringSubmatch(p.scanner.Text())245 p.line++246 if mf == nil || !p.scanner.Scan() {247 p.setError(errIncorrectLegacyRange, "")248 return x, x249 }250 // Using Bytes would be more efficient here, but Text is a lot easier251 // and this is not a frequent case.252 ml := reRange.FindStringSubmatch(p.scanner.Text())253 if ml == nil || mf[2] != ml[2] || ml[3] != "Last" || mf[4] != ml[4] {254 p.setError(errIncorrectLegacyRange, "")255 return x, x256 }257 p.rangeStart, p.rangeEnd = x, p.parseRune(p.scanner.Text()[:len(ml[1])])258 p.parsedRange = true259 return p.rangeStart, p.rangeEnd260 }261 return x, x262}263// bools recognizes all valid UCD boolean values.264var bools = map[string]bool{265 "": false,266 "N": false,267 "No": false,268 "F": false,269 "False": false,270 "Y": true,271 "Yes": true,272 "T": true,273 "True": true,274}275// Bool parses and returns field i as a boolean value.276func (p *Parser) Bool(i int) bool {277 f := p.getField(i)278 for s, v := range bools {279 if f == s {280 return v281 }282 }283 p.setError(strconv.ErrSyntax, "error parsing bool")284 return false285}286// Int parses and returns field i as an integer value.287func (p *Parser) Int(i int) int {288 x, err := strconv.ParseInt(string(p.getField(i)), 10, 64)289 p.setError(err, "error parsing int")290 return int(x)291}292// Uint parses and returns field i as an unsigned integer value.293func (p *Parser) Uint(i int) uint {294 x, err := strconv.ParseUint(string(p.getField(i)), 10, 64)295 p.setError(err, "error parsing uint")296 return uint(x)297}298// Float parses and returns field i as a decimal value.299func (p *Parser) Float(i int) float64 {300 x, err := strconv.ParseFloat(string(p.getField(i)), 64)301 p.setError(err, "error parsing float")302 return x303}304// String parses and returns field i as a string value.305func (p *Parser) String(i int) string {306 return string(p.getField(i))307}308// Strings parses and returns field i as a space-separated list of strings.309func (p *Parser) Strings(i int) []string {310 ss := strings.Split(string(p.getField(i)), " ")311 for i, s := range ss {312 ss[i] = strings.TrimSpace(s)313 }314 return ss315}316// Comment returns the comments for the current line.317func (p *Parser) Comment() string {318 return string(p.comment)319}320var errUndefinedEnum = errors.New("ucd: undefined enum value")321// Enum interprets and returns field i as a value that must be one of the values322// in enum.323func (p *Parser) Enum(i int, enum ...string) string {324 f := p.getField(i)325 for _, s := range enum {326 if f == s {327 return s328 }329 }330 p.setError(errUndefinedEnum, "error parsing enum")331 return ""332}...
Error
Using AI Code Generation
1import (2type BaseErrorListener struct {3}4func (b *BaseErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) {5 fmt.Println("line", line, ":", column, " ", msg)6}7func main() {8 input := antlr.NewInputStream("1 + 2 + 3 + 4")9 lexer := NewExprLexer(input)10 stream := antlr.NewCommonTokenStream(lexer, 0)11 p := NewExprParser(stream)12 p.AddErrorListener(&BaseErrorListener{})13 tree := p.Prog()14 fmt.Println(tree.ToStringTree(nil, p))15}
Error
Using AI Code Generation
1import (2func main() {3 if len(args) < 2 {4 fmt.Println("Please provide a file name")5 }6 file, err := os.Open(fileName)7 if err != nil {8 fmt.Println(err)9 }10 fmt.Printf("%T11 fmt.Println(file.Name(), "opened successfully")12}13import (14func main() {15 if len(args) < 2 {16 fmt.Println("Please provide a file name")17 }18 file, err := os.Open(fileName)19 if err != nil {20 fmt.Println(err)21 }22 fmt.Printf("%T23 fmt.Println(file.Name(), "opened successfully")24}25import (26func main() {27 if len(args) < 2 {28 fmt.Println("Please provide a file name")29 }30 file, err := os.Open(fileName)31 if err != nil {32 fmt.Println(err)33 }34 fmt.Printf("%T35 fmt.Println(file.Name(), "opened successfully")36}37import (38func main() {39 if len(args) < 2 {40 fmt.Println("Please provide a file name")41 }42 file, err := os.Open(fileName)43 if err != nil {44 fmt.Println(err.Error())45 }46 fmt.Printf("%T47 fmt.Println(file.Name(), "opened successfully")48}
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.
Get 100 minutes of automation test minutes FREE!!