urn_parser.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // Generated from /home/leodido/workspaces/go/src/github.com/leodido/go-urn/grammar/Urn.g4 by ANTLR 4.7.
  2. package grammar // Urn
  3. import (
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "github.com/antlr/antlr4/runtime/Go/antlr"
  8. )
  9. // Suppress unused import errors
  10. var _ = fmt.Printf
  11. var _ = reflect.Copy
  12. var _ = strconv.Itoa
  13. var parserATN = []uint16{
  14. 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 7, 45, 4,
  15. 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
  16. 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 7, 4, 22, 10, 4, 12, 4, 14, 4, 25,
  17. 11, 4, 3, 4, 5, 4, 28, 10, 4, 3, 4, 6, 4, 31, 10, 4, 13, 4, 14, 4, 32,
  18. 3, 4, 5, 4, 36, 10, 4, 3, 4, 3, 4, 5, 4, 40, 10, 4, 3, 4, 5, 4, 43, 10,
  19. 4, 3, 4, 2, 2, 5, 2, 4, 6, 2, 3, 3, 2, 5, 6, 2, 49, 2, 8, 3, 2, 2, 2, 4,
  20. 15, 3, 2, 2, 2, 6, 42, 3, 2, 2, 2, 8, 9, 7, 3, 2, 2, 9, 10, 7, 5, 2, 2,
  21. 10, 11, 5, 4, 3, 2, 11, 12, 7, 5, 2, 2, 12, 13, 5, 6, 4, 2, 13, 14, 7,
  22. 2, 2, 3, 14, 3, 3, 2, 2, 2, 15, 16, 7, 4, 2, 2, 16, 17, 6, 3, 2, 3, 17,
  23. 18, 6, 3, 3, 3, 18, 5, 3, 2, 2, 2, 19, 23, 7, 4, 2, 2, 20, 22, 9, 2, 2,
  24. 2, 21, 20, 3, 2, 2, 2, 22, 25, 3, 2, 2, 2, 23, 21, 3, 2, 2, 2, 23, 24,
  25. 3, 2, 2, 2, 24, 27, 3, 2, 2, 2, 25, 23, 3, 2, 2, 2, 26, 28, 5, 6, 4, 2,
  26. 27, 26, 3, 2, 2, 2, 27, 28, 3, 2, 2, 2, 28, 43, 3, 2, 2, 2, 29, 31, 9,
  27. 2, 2, 2, 30, 29, 3, 2, 2, 2, 31, 32, 3, 2, 2, 2, 32, 30, 3, 2, 2, 2, 32,
  28. 33, 3, 2, 2, 2, 33, 35, 3, 2, 2, 2, 34, 36, 5, 6, 4, 2, 35, 34, 3, 2, 2,
  29. 2, 35, 36, 3, 2, 2, 2, 36, 43, 3, 2, 2, 2, 37, 39, 7, 4, 2, 2, 38, 40,
  30. 5, 6, 4, 2, 39, 38, 3, 2, 2, 2, 39, 40, 3, 2, 2, 2, 40, 43, 3, 2, 2, 2,
  31. 41, 43, 7, 3, 2, 2, 42, 19, 3, 2, 2, 2, 42, 30, 3, 2, 2, 2, 42, 37, 3,
  32. 2, 2, 2, 42, 41, 3, 2, 2, 2, 43, 7, 3, 2, 2, 2, 8, 23, 27, 32, 35, 39,
  33. 42,
  34. }
  35. var deserializer = antlr.NewATNDeserializer(nil)
  36. var deserializedATN = deserializer.DeserializeFromUInt16(parserATN)
  37. var literalNames = []string{
  38. "", "", "", "':'", "'-'", "' '",
  39. }
  40. var symbolicNames = []string{
  41. "", "Urn", "Part", "Colon", "Hyphen", "Whitespace",
  42. }
  43. var ruleNames = []string{
  44. "urn", "iD", "sS",
  45. }
  46. var decisionToDFA = make([]*antlr.DFA, len(deserializedATN.DecisionToState))
  47. func init() {
  48. for index, ds := range deserializedATN.DecisionToState {
  49. decisionToDFA[index] = antlr.NewDFA(ds, index)
  50. }
  51. }
  52. type UrnParser struct {
  53. *antlr.BaseParser
  54. }
  55. func NewUrnParser(input antlr.TokenStream) *UrnParser {
  56. this := new(UrnParser)
  57. this.BaseParser = antlr.NewBaseParser(input)
  58. this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, antlr.NewPredictionContextCache())
  59. this.RuleNames = ruleNames
  60. this.LiteralNames = literalNames
  61. this.SymbolicNames = symbolicNames
  62. this.GrammarFileName = "Urn.g4"
  63. return this
  64. }
  65. func isIdentifier(s string) bool {
  66. for i, r := range s {
  67. // !unicode.IsLetter(r) etc. when (if) we'll need unicode
  68. if (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && (r < '0' || r > '9') && (r != '-' || (i == 0 && r == '-')) {
  69. return false
  70. }
  71. }
  72. return true
  73. }
  74. // UrnParser tokens.
  75. const (
  76. UrnParserEOF = antlr.TokenEOF
  77. UrnParserUrn = 1
  78. UrnParserPart = 2
  79. UrnParserColon = 3
  80. UrnParserHyphen = 4
  81. UrnParserWhitespace = 5
  82. )
  83. // UrnParser rules.
  84. const (
  85. UrnParserRULE_urn = 0
  86. UrnParserRULE_iD = 1
  87. UrnParserRULE_sS = 2
  88. )
  89. // IUrnContext is an interface to support dynamic dispatch.
  90. type IUrnContext interface {
  91. antlr.ParserRuleContext
  92. // GetParser returns the parser.
  93. GetParser() antlr.Parser
  94. // IsUrnContext differentiates from other interfaces.
  95. IsUrnContext()
  96. }
  97. type UrnContext struct {
  98. *antlr.BaseParserRuleContext
  99. parser antlr.Parser
  100. }
  101. func NewEmptyUrnContext() *UrnContext {
  102. var p = new(UrnContext)
  103. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  104. p.RuleIndex = UrnParserRULE_urn
  105. return p
  106. }
  107. func (*UrnContext) IsUrnContext() {}
  108. func NewUrnContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *UrnContext {
  109. var p = new(UrnContext)
  110. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  111. p.parser = parser
  112. p.RuleIndex = UrnParserRULE_urn
  113. return p
  114. }
  115. func (s *UrnContext) GetParser() antlr.Parser { return s.parser }
  116. func (s *UrnContext) Urn() antlr.TerminalNode {
  117. return s.GetToken(UrnParserUrn, 0)
  118. }
  119. func (s *UrnContext) AllColon() []antlr.TerminalNode {
  120. return s.GetTokens(UrnParserColon)
  121. }
  122. func (s *UrnContext) Colon(i int) antlr.TerminalNode {
  123. return s.GetToken(UrnParserColon, i)
  124. }
  125. func (s *UrnContext) ID() IIDContext {
  126. var t = s.GetTypedRuleContext(reflect.TypeOf((*IIDContext)(nil)).Elem(), 0)
  127. if t == nil {
  128. return nil
  129. }
  130. return t.(IIDContext)
  131. }
  132. func (s *UrnContext) SS() ISSContext {
  133. var t = s.GetTypedRuleContext(reflect.TypeOf((*ISSContext)(nil)).Elem(), 0)
  134. if t == nil {
  135. return nil
  136. }
  137. return t.(ISSContext)
  138. }
  139. func (s *UrnContext) EOF() antlr.TerminalNode {
  140. return s.GetToken(UrnParserEOF, 0)
  141. }
  142. func (s *UrnContext) GetRuleContext() antlr.RuleContext {
  143. return s
  144. }
  145. func (s *UrnContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  146. return antlr.TreesStringTree(s, ruleNames, recog)
  147. }
  148. func (s *UrnContext) EnterRule(listener antlr.ParseTreeListener) {
  149. if listenerT, ok := listener.(UrnListener); ok {
  150. listenerT.EnterUrn(s)
  151. }
  152. }
  153. func (s *UrnContext) ExitRule(listener antlr.ParseTreeListener) {
  154. if listenerT, ok := listener.(UrnListener); ok {
  155. listenerT.ExitUrn(s)
  156. }
  157. }
  158. func (p *UrnParser) Urn() (localctx IUrnContext) {
  159. localctx = NewUrnContext(p, p.GetParserRuleContext(), p.GetState())
  160. p.EnterRule(localctx, 0, UrnParserRULE_urn)
  161. defer func() {
  162. p.ExitRule()
  163. }()
  164. defer func() {
  165. if err := recover(); err != nil {
  166. if v, ok := err.(antlr.RecognitionException); ok {
  167. localctx.SetException(v)
  168. p.GetErrorHandler().ReportError(p, v)
  169. p.GetErrorHandler().Recover(p, v)
  170. } else {
  171. panic(err)
  172. }
  173. }
  174. }()
  175. p.EnterOuterAlt(localctx, 1)
  176. {
  177. p.SetState(6)
  178. p.Match(UrnParserUrn)
  179. }
  180. {
  181. p.SetState(7)
  182. p.Match(UrnParserColon)
  183. }
  184. {
  185. p.SetState(8)
  186. p.ID()
  187. }
  188. {
  189. p.SetState(9)
  190. p.Match(UrnParserColon)
  191. }
  192. {
  193. p.SetState(10)
  194. p.SS()
  195. }
  196. {
  197. p.SetState(11)
  198. p.Match(UrnParserEOF)
  199. }
  200. return localctx
  201. }
  202. // IIDContext is an interface to support dynamic dispatch.
  203. type IIDContext interface {
  204. antlr.ParserRuleContext
  205. // GetParser returns the parser.
  206. GetParser() antlr.Parser
  207. // IsIDContext differentiates from other interfaces.
  208. IsIDContext()
  209. }
  210. type IDContext struct {
  211. *antlr.BaseParserRuleContext
  212. parser antlr.Parser
  213. }
  214. func NewEmptyIDContext() *IDContext {
  215. var p = new(IDContext)
  216. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  217. p.RuleIndex = UrnParserRULE_iD
  218. return p
  219. }
  220. func (*IDContext) IsIDContext() {}
  221. func NewIDContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IDContext {
  222. var p = new(IDContext)
  223. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  224. p.parser = parser
  225. p.RuleIndex = UrnParserRULE_iD
  226. return p
  227. }
  228. func (s *IDContext) GetParser() antlr.Parser { return s.parser }
  229. func (s *IDContext) Part() antlr.TerminalNode {
  230. return s.GetToken(UrnParserPart, 0)
  231. }
  232. func (s *IDContext) GetRuleContext() antlr.RuleContext {
  233. return s
  234. }
  235. func (s *IDContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  236. return antlr.TreesStringTree(s, ruleNames, recog)
  237. }
  238. func (s *IDContext) EnterRule(listener antlr.ParseTreeListener) {
  239. if listenerT, ok := listener.(UrnListener); ok {
  240. listenerT.EnterID(s)
  241. }
  242. }
  243. func (s *IDContext) ExitRule(listener antlr.ParseTreeListener) {
  244. if listenerT, ok := listener.(UrnListener); ok {
  245. listenerT.ExitID(s)
  246. }
  247. }
  248. func (p *UrnParser) ID() (localctx IIDContext) {
  249. localctx = NewIDContext(p, p.GetParserRuleContext(), p.GetState())
  250. p.EnterRule(localctx, 2, UrnParserRULE_iD)
  251. defer func() {
  252. p.ExitRule()
  253. }()
  254. defer func() {
  255. if err := recover(); err != nil {
  256. if v, ok := err.(antlr.RecognitionException); ok {
  257. localctx.SetException(v)
  258. p.GetErrorHandler().ReportError(p, v)
  259. p.GetErrorHandler().Recover(p, v)
  260. } else {
  261. panic(err)
  262. }
  263. }
  264. }()
  265. p.EnterOuterAlt(localctx, 1)
  266. {
  267. p.SetState(13)
  268. p.Match(UrnParserPart)
  269. }
  270. p.SetState(14)
  271. if !(len(localctx.(*IDContext).GetText()) <= 32) {
  272. panic(antlr.NewFailedPredicateException(p, "len($ctx.GetText()) <= 32", "exceed max (32) number of characters"))
  273. }
  274. p.SetState(15)
  275. if !(isIdentifier(localctx.(*IDContext).GetText())) {
  276. panic(antlr.NewFailedPredicateException(p, "isIdentifier($ctx.GetText())", "is not a valid identifier"))
  277. }
  278. return localctx
  279. }
  280. // ISSContext is an interface to support dynamic dispatch.
  281. type ISSContext interface {
  282. antlr.ParserRuleContext
  283. // GetParser returns the parser.
  284. GetParser() antlr.Parser
  285. // IsSSContext differentiates from other interfaces.
  286. IsSSContext()
  287. }
  288. type SSContext struct {
  289. *antlr.BaseParserRuleContext
  290. parser antlr.Parser
  291. }
  292. func NewEmptySSContext() *SSContext {
  293. var p = new(SSContext)
  294. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
  295. p.RuleIndex = UrnParserRULE_sS
  296. return p
  297. }
  298. func (*SSContext) IsSSContext() {}
  299. func NewSSContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SSContext {
  300. var p = new(SSContext)
  301. p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
  302. p.parser = parser
  303. p.RuleIndex = UrnParserRULE_sS
  304. return p
  305. }
  306. func (s *SSContext) GetParser() antlr.Parser { return s.parser }
  307. func (s *SSContext) Part() antlr.TerminalNode {
  308. return s.GetToken(UrnParserPart, 0)
  309. }
  310. func (s *SSContext) SS() ISSContext {
  311. var t = s.GetTypedRuleContext(reflect.TypeOf((*ISSContext)(nil)).Elem(), 0)
  312. if t == nil {
  313. return nil
  314. }
  315. return t.(ISSContext)
  316. }
  317. func (s *SSContext) AllColon() []antlr.TerminalNode {
  318. return s.GetTokens(UrnParserColon)
  319. }
  320. func (s *SSContext) Colon(i int) antlr.TerminalNode {
  321. return s.GetToken(UrnParserColon, i)
  322. }
  323. func (s *SSContext) AllHyphen() []antlr.TerminalNode {
  324. return s.GetTokens(UrnParserHyphen)
  325. }
  326. func (s *SSContext) Hyphen(i int) antlr.TerminalNode {
  327. return s.GetToken(UrnParserHyphen, i)
  328. }
  329. func (s *SSContext) Urn() antlr.TerminalNode {
  330. return s.GetToken(UrnParserUrn, 0)
  331. }
  332. func (s *SSContext) GetRuleContext() antlr.RuleContext {
  333. return s
  334. }
  335. func (s *SSContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
  336. return antlr.TreesStringTree(s, ruleNames, recog)
  337. }
  338. func (s *SSContext) EnterRule(listener antlr.ParseTreeListener) {
  339. if listenerT, ok := listener.(UrnListener); ok {
  340. listenerT.EnterSS(s)
  341. }
  342. }
  343. func (s *SSContext) ExitRule(listener antlr.ParseTreeListener) {
  344. if listenerT, ok := listener.(UrnListener); ok {
  345. listenerT.ExitSS(s)
  346. }
  347. }
  348. func (p *UrnParser) SS() (localctx ISSContext) {
  349. localctx = NewSSContext(p, p.GetParserRuleContext(), p.GetState())
  350. p.EnterRule(localctx, 4, UrnParserRULE_sS)
  351. var _la int
  352. 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. var _alt int
  367. p.SetState(40)
  368. p.GetErrorHandler().Sync(p)
  369. switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 5, p.GetParserRuleContext()) {
  370. case 1:
  371. p.EnterOuterAlt(localctx, 1)
  372. {
  373. p.SetState(17)
  374. p.Match(UrnParserPart)
  375. }
  376. p.SetState(21)
  377. p.GetErrorHandler().Sync(p)
  378. _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 0, p.GetParserRuleContext())
  379. for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
  380. if _alt == 1 {
  381. p.SetState(18)
  382. _la = p.GetTokenStream().LA(1)
  383. if !(_la == UrnParserColon || _la == UrnParserHyphen) {
  384. p.GetErrorHandler().RecoverInline(p)
  385. } else {
  386. p.GetErrorHandler().ReportMatch(p)
  387. p.Consume()
  388. }
  389. }
  390. p.SetState(23)
  391. p.GetErrorHandler().Sync(p)
  392. _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 0, p.GetParserRuleContext())
  393. }
  394. p.SetState(25)
  395. p.GetErrorHandler().Sync(p)
  396. _la = p.GetTokenStream().LA(1)
  397. if (((_la) & -(0x1f+1)) == 0 && ((1 << uint(_la)) & ((1 << UrnParserUrn) | (1 << UrnParserPart) | (1 << UrnParserColon) | (1 << UrnParserHyphen))) != 0) {
  398. {
  399. p.SetState(24)
  400. p.SS()
  401. }
  402. }
  403. case 2:
  404. p.EnterOuterAlt(localctx, 2)
  405. p.SetState(28)
  406. p.GetErrorHandler().Sync(p)
  407. _alt = 1
  408. for ok := true; ok; ok = _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
  409. switch _alt {
  410. case 1:
  411. p.SetState(27)
  412. _la = p.GetTokenStream().LA(1)
  413. if !(_la == UrnParserColon || _la == UrnParserHyphen) {
  414. p.GetErrorHandler().RecoverInline(p)
  415. } else {
  416. p.GetErrorHandler().ReportMatch(p)
  417. p.Consume()
  418. }
  419. default:
  420. panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
  421. }
  422. p.SetState(30)
  423. p.GetErrorHandler().Sync(p)
  424. _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext())
  425. }
  426. p.SetState(33)
  427. p.GetErrorHandler().Sync(p)
  428. _la = p.GetTokenStream().LA(1)
  429. if (((_la) & -(0x1f+1)) == 0 && ((1 << uint(_la)) & ((1 << UrnParserUrn) | (1 << UrnParserPart) | (1 << UrnParserColon) | (1 << UrnParserHyphen))) != 0) {
  430. {
  431. p.SetState(32)
  432. p.SS()
  433. }
  434. }
  435. case 3:
  436. p.EnterOuterAlt(localctx, 3)
  437. {
  438. p.SetState(35)
  439. p.Match(UrnParserPart)
  440. }
  441. p.SetState(37)
  442. p.GetErrorHandler().Sync(p)
  443. _la = p.GetTokenStream().LA(1)
  444. if (((_la) & -(0x1f+1)) == 0 && ((1 << uint(_la)) & ((1 << UrnParserUrn) | (1 << UrnParserPart) | (1 << UrnParserColon) | (1 << UrnParserHyphen))) != 0) {
  445. {
  446. p.SetState(36)
  447. p.SS()
  448. }
  449. }
  450. case 4:
  451. p.EnterOuterAlt(localctx, 4)
  452. {
  453. p.SetState(39)
  454. p.Match(UrnParserUrn)
  455. }
  456. }
  457. return localctx
  458. }
  459. func (p *UrnParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {
  460. switch ruleIndex {
  461. case 1:
  462. var t *IDContext = nil
  463. if localctx != nil { t = localctx.(*IDContext) }
  464. return p.ID_Sempred(t, predIndex)
  465. default:
  466. panic("No predicate with index: " + fmt.Sprint(ruleIndex))
  467. }
  468. }
  469. func (p *UrnParser) ID_Sempred(localctx antlr.RuleContext, predIndex int) bool {
  470. switch predIndex {
  471. case 0:
  472. return len(localctx.(*IDContext).GetText()) <= 32
  473. case 1:
  474. return isIdentifier(localctx.(*IDContext).GetText())
  475. default:
  476. panic("No predicate with index: " + fmt.Sprint(predIndex))
  477. }
  478. }