apiparser_parser7.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. package api
  2. import (
  3. "reflect"
  4. "github.com/zeromicro/antlr"
  5. )
  6. // Part 7
  7. // The apiparser_parser.go file was split into multiple files because it
  8. // was too large and caused a possible memory overflow during goctl installation.
  9. // IServiceRouteContext is an interface to support dynamic dispatch.
  10. type IServiceRouteContext interface {
  11. antlr.ParserRuleContext
  12. // GetParser returns the parser.
  13. GetParser() antlr.Parser
  14. // IsServiceRouteContext differentiates from other interfaces.
  15. IsServiceRouteContext()
  16. }
  17. type ServiceRouteContext struct {
  18. *antlr.BaseParserRuleContext
  19. parser antlr.Parser
  20. }
  21. func NewEmptyServiceRouteContext() *ServiceRouteContext {
  22. p := new(ServiceRouteContext)
  23. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  24. p.RuleIndex = ApiParserParserRULE_serviceRoute
  25. return p
  26. }
  27. func (*ServiceRouteContext) IsServiceRouteContext() {}
  28. func NewServiceRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceRouteContext {
  29. p := new(ServiceRouteContext)
  30. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  31. p.parser = parser
  32. p.RuleIndex = ApiParserParserRULE_serviceRoute
  33. return p
  34. }
  35. func (s *ServiceRouteContext) GetParser() antlr.Parser { return s.parser }
  36. func (s *ServiceRouteContext) Route() IRouteContext {
  37. t := s.GetTypedRuleContext(reflect.TypeOf((*IRouteContext)(nil)).Elem(), 0)
  38. if t == nil {
  39. return nil
  40. }
  41. return t.(IRouteContext)
  42. }
  43. func (s *ServiceRouteContext) AtServer() IAtServerContext {
  44. t := s.GetTypedRuleContext(reflect.TypeOf((*IAtServerContext)(nil)).Elem(), 0)
  45. if t == nil {
  46. return nil
  47. }
  48. return t.(IAtServerContext)
  49. }
  50. func (s *ServiceRouteContext) AtHandler() IAtHandlerContext {
  51. t := s.GetTypedRuleContext(reflect.TypeOf((*IAtHandlerContext)(nil)).Elem(), 0)
  52. if t == nil {
  53. return nil
  54. }
  55. return t.(IAtHandlerContext)
  56. }
  57. func (s *ServiceRouteContext) AtDoc() IAtDocContext {
  58. t := s.GetTypedRuleContext(reflect.TypeOf((*IAtDocContext)(nil)).Elem(), 0)
  59. if t == nil {
  60. return nil
  61. }
  62. return t.(IAtDocContext)
  63. }
  64. func (s *ServiceRouteContext) GetRuleContext() antlr.RuleContext {
  65. return s
  66. }
  67. func (s *ServiceRouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  68. return antlr.TreesStringTree(s, ruleNames, recog)
  69. }
  70. func (s *ServiceRouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
  71. switch t := visitor.(type) {
  72. case ApiParserVisitor:
  73. return t.VisitServiceRoute(s)
  74. default:
  75. return t.VisitChildren(s)
  76. }
  77. }
  78. func (p *ApiParserParser) ServiceRoute() (localctx IServiceRouteContext) {
  79. localctx = NewServiceRouteContext(p, p.GetParserRuleContext(), p.GetState())
  80. p.EnterRule(localctx, 56, ApiParserParserRULE_serviceRoute)
  81. var _la int
  82. defer func() {
  83. p.ExitRule()
  84. }()
  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 localctx
  127. }
  128. // IAtDocContext is an interface to support dynamic dispatch.
  129. type IAtDocContext interface {
  130. antlr.ParserRuleContext
  131. // GetParser returns the parser.
  132. GetParser() antlr.Parser
  133. // GetLp returns the lp token.
  134. GetLp() antlr.Token
  135. // GetRp returns the rp token.
  136. GetRp() antlr.Token
  137. // 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. }
  144. type AtDocContext struct {
  145. *antlr.BaseParserRuleContext
  146. parser antlr.Parser
  147. lp antlr.Token
  148. rp antlr.Token
  149. }
  150. func NewEmptyAtDocContext() *AtDocContext {
  151. p := new(AtDocContext)
  152. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  153. p.RuleIndex = ApiParserParserRULE_atDoc
  154. return p
  155. }
  156. func (*AtDocContext) IsAtDocContext() {}
  157. func NewAtDocContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtDocContext {
  158. p := new(AtDocContext)
  159. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  160. p.parser = parser
  161. p.RuleIndex = ApiParserParserRULE_atDoc
  162. return p
  163. }
  164. func (s *AtDocContext) GetParser() antlr.Parser { return s.parser }
  165. func (s *AtDocContext) GetLp() antlr.Token { return s.lp }
  166. func (s *AtDocContext) GetRp() antlr.Token { return s.rp }
  167. func (s *AtDocContext) SetLp(v antlr.Token) { s.lp = v }
  168. func (s *AtDocContext) SetRp(v antlr.Token) { s.rp = v }
  169. func (s *AtDocContext) ATDOC() antlr.TerminalNode {
  170. return s.GetToken(ApiParserParserATDOC, 0)
  171. }
  172. func (s *AtDocContext) STRING() antlr.TerminalNode {
  173. return s.GetToken(ApiParserParserSTRING, 0)
  174. }
  175. func (s *AtDocContext) AllKvLit() []IKvLitContext {
  176. ts := s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
  177. tst := make([]IKvLitContext, len(ts))
  178. for i, t := range ts {
  179. if t != nil {
  180. tst[i] = t.(IKvLitContext)
  181. }
  182. }
  183. return tst
  184. }
  185. func (s *AtDocContext) KvLit(i int) IKvLitContext {
  186. t := s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
  187. if t == nil {
  188. return nil
  189. }
  190. return t.(IKvLitContext)
  191. }
  192. func (s *AtDocContext) GetRuleContext() antlr.RuleContext {
  193. return s
  194. }
  195. func (s *AtDocContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  196. return antlr.TreesStringTree(s, ruleNames, recog)
  197. }
  198. func (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. }
  206. func (p *ApiParserParser) AtDoc() (localctx IAtDocContext) {
  207. localctx = NewAtDocContext(p, p.GetParserRuleContext(), p.GetState())
  208. p.EnterRule(localctx, 58, ApiParserParserRULE_atDoc)
  209. var _la int
  210. 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. _m := p.Match(ApiParserParserT__1)
  236. localctx.(*AtDocContext).lp = _m
  237. }
  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. _m := p.Match(ApiParserParserT__2)
  269. localctx.(*AtDocContext).rp = _m
  270. }
  271. }
  272. return localctx
  273. }
  274. // IAtHandlerContext is an interface to support dynamic dispatch.
  275. type IAtHandlerContext interface {
  276. antlr.ParserRuleContext
  277. // GetParser returns the parser.
  278. GetParser() antlr.Parser
  279. // IsAtHandlerContext differentiates from other interfaces.
  280. IsAtHandlerContext()
  281. }
  282. type AtHandlerContext struct {
  283. *antlr.BaseParserRuleContext
  284. parser antlr.Parser
  285. }
  286. func NewEmptyAtHandlerContext() *AtHandlerContext {
  287. p := new(AtHandlerContext)
  288. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  289. p.RuleIndex = ApiParserParserRULE_atHandler
  290. return p
  291. }
  292. func (*AtHandlerContext) IsAtHandlerContext() {}
  293. func NewAtHandlerContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtHandlerContext {
  294. p := new(AtHandlerContext)
  295. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  296. p.parser = parser
  297. p.RuleIndex = ApiParserParserRULE_atHandler
  298. return p
  299. }
  300. func (s *AtHandlerContext) GetParser() antlr.Parser { return s.parser }
  301. func (s *AtHandlerContext) ATHANDLER() antlr.TerminalNode {
  302. return s.GetToken(ApiParserParserATHANDLER, 0)
  303. }
  304. func (s *AtHandlerContext) ID() antlr.TerminalNode {
  305. return s.GetToken(ApiParserParserID, 0)
  306. }
  307. func (s *AtHandlerContext) GetRuleContext() antlr.RuleContext {
  308. return s
  309. }
  310. func (s *AtHandlerContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  311. return antlr.TreesStringTree(s, ruleNames, recog)
  312. }
  313. func (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. }
  321. func (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 localctx
  348. }
  349. // IRouteContext is an interface to support dynamic dispatch.
  350. type IRouteContext interface {
  351. antlr.ParserRuleContext
  352. // GetParser returns the parser.
  353. GetParser() antlr.Parser
  354. // GetHttpMethod returns the httpMethod token.
  355. GetHttpMethod() antlr.Token
  356. // SetHttpMethod sets the httpMethod token.
  357. SetHttpMethod(antlr.Token)
  358. // GetRequest returns the request rule contexts.
  359. GetRequest() IBodyContext
  360. // GetResponse returns the response rule contexts.
  361. GetResponse() IReplybodyContext
  362. // SetRequest sets the request rule contexts.
  363. SetRequest(IBodyContext)
  364. // SetResponse sets the response rule contexts.
  365. SetResponse(IReplybodyContext)
  366. // IsRouteContext differentiates from other interfaces.
  367. IsRouteContext()
  368. }
  369. type RouteContext struct {
  370. *antlr.BaseParserRuleContext
  371. parser antlr.Parser
  372. httpMethod antlr.Token
  373. request IBodyContext
  374. response IReplybodyContext
  375. }
  376. func NewEmptyRouteContext() *RouteContext {
  377. p := new(RouteContext)
  378. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  379. p.RuleIndex = ApiParserParserRULE_route
  380. return p
  381. }
  382. func (*RouteContext) IsRouteContext() {}
  383. func NewRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RouteContext {
  384. p := new(RouteContext)
  385. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  386. p.parser = parser
  387. p.RuleIndex = ApiParserParserRULE_route
  388. return p
  389. }
  390. func (s *RouteContext) GetParser() antlr.Parser { return s.parser }
  391. func (s *RouteContext) GetHttpMethod() antlr.Token { return s.httpMethod }
  392. func (s *RouteContext) SetHttpMethod(v antlr.Token) { s.httpMethod = v }
  393. func (s *RouteContext) GetRequest() IBodyContext { return s.request }
  394. func (s *RouteContext) GetResponse() IReplybodyContext { return s.response }
  395. func (s *RouteContext) SetRequest(v IBodyContext) { s.request = v }
  396. func (s *RouteContext) SetResponse(v IReplybodyContext) { s.response = v }
  397. func (s *RouteContext) Path() IPathContext {
  398. t := s.GetTypedRuleContext(reflect.TypeOf((*IPathContext)(nil)).Elem(), 0)
  399. if t == nil {
  400. return nil
  401. }
  402. return t.(IPathContext)
  403. }
  404. func (s *RouteContext) ID() antlr.TerminalNode {
  405. return s.GetToken(ApiParserParserID, 0)
  406. }
  407. func (s *RouteContext) Body() IBodyContext {
  408. t := s.GetTypedRuleContext(reflect.TypeOf((*IBodyContext)(nil)).Elem(), 0)
  409. if t == nil {
  410. return nil
  411. }
  412. return t.(IBodyContext)
  413. }
  414. func (s *RouteContext) Replybody() IReplybodyContext {
  415. t := s.GetTypedRuleContext(reflect.TypeOf((*IReplybodyContext)(nil)).Elem(), 0)
  416. if t == nil {
  417. return nil
  418. }
  419. return t.(IReplybodyContext)
  420. }
  421. func (s *RouteContext) GetRuleContext() antlr.RuleContext {
  422. return s
  423. }
  424. func (s *RouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  425. return antlr.TreesStringTree(s, ruleNames, recog)
  426. }
  427. func (s *RouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
  428. switch t := visitor.(type) {
  429. case ApiParserVisitor:
  430. return t.VisitRoute(s)
  431. default:
  432. return t.VisitChildren(s)
  433. }
  434. }
  435. func (p *ApiParserParser) Route() (localctx IRouteContext) {
  436. localctx = NewRouteContext(p, p.GetParserRuleContext(), p.GetState())
  437. p.EnterRule(localctx, 62, ApiParserParserRULE_route)
  438. var _la int
  439. defer func() {
  440. p.ExitRule()
  441. }()
  442. defer func() {
  443. if err := recover(); err != nil {
  444. if v, ok := err.(antlr.RecognitionException); ok {
  445. localctx.SetException(v)
  446. p.GetErrorHandler().ReportError(p, v)
  447. p.GetErrorHandler().Recover(p, v)
  448. } else {
  449. panic(err)
  450. }
  451. }
  452. }()
  453. p.EnterOuterAlt(localctx, 1)
  454. checkHTTPMethod(p)
  455. {
  456. p.SetState(291)
  457. _m := p.Match(ApiParserParserID)
  458. localctx.(*RouteContext).httpMethod = _m
  459. }
  460. {
  461. p.SetState(292)
  462. p.Path()
  463. }
  464. p.SetState(294)
  465. p.GetErrorHandler().Sync(p)
  466. _la = p.GetTokenStream().LA(1)
  467. if _la == ApiParserParserT__1 {
  468. {
  469. p.SetState(293)
  470. _x := p.Body()
  471. localctx.(*RouteContext).request = _x
  472. }
  473. }
  474. p.SetState(297)
  475. p.GetErrorHandler().Sync(p)
  476. _la = p.GetTokenStream().LA(1)
  477. if _la == ApiParserParserT__9 {
  478. {
  479. p.SetState(296)
  480. _x := p.Replybody()
  481. localctx.(*RouteContext).response = _x
  482. }
  483. }
  484. return localctx
  485. }