123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634 |
- // Generated from /home/leodido/workspaces/go/src/github.com/leodido/go-urn/grammar/Urn.g4 by ANTLR 4.7.
- package grammar // Urn
- import (
- "fmt"
- "reflect"
- "strconv"
- "github.com/antlr/antlr4/runtime/Go/antlr"
- )
- // Suppress unused import errors
- var _ = fmt.Printf
- var _ = reflect.Copy
- var _ = strconv.Itoa
- var parserATN = []uint16{
- 3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 7, 45, 4,
- 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3,
- 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 7, 4, 22, 10, 4, 12, 4, 14, 4, 25,
- 11, 4, 3, 4, 5, 4, 28, 10, 4, 3, 4, 6, 4, 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, 32, 35, 39,
- 42,
- }
- var deserializer = antlr.NewATNDeserializer(nil)
- var deserializedATN = deserializer.DeserializeFromUInt16(parserATN)
- var literalNames = []string{
- "", "", "", "':'", "'-'", "' '",
- }
- var symbolicNames = []string{
- "", "Urn", "Part", "Colon", "Hyphen", "Whitespace",
- }
- var ruleNames = []string{
- "urn", "iD", "sS",
- }
- var decisionToDFA = make([]*antlr.DFA, len(deserializedATN.DecisionToState))
- func init() {
- for index, ds := range deserializedATN.DecisionToState {
- decisionToDFA[index] = antlr.NewDFA(ds, index)
- }
- }
- type UrnParser struct {
- *antlr.BaseParser
- }
- func NewUrnParser(input antlr.TokenStream) *UrnParser {
- this := new(UrnParser)
- this.BaseParser = antlr.NewBaseParser(input)
- this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, antlr.NewPredictionContextCache())
- this.RuleNames = ruleNames
- this.LiteralNames = literalNames
- this.SymbolicNames = symbolicNames
- this.GrammarFileName = "Urn.g4"
- return this
- }
- func isIdentifier(s string) bool {
- for i, r := range s {
- // !unicode.IsLetter(r) etc. when (if) we'll need unicode
- if (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && (r < '0' || r > '9') && (r != '-' || (i == 0 && r == '-')) {
- return false
- }
- }
- return true
- }
- // UrnParser tokens.
- const (
- UrnParserEOF = antlr.TokenEOF
- UrnParserUrn = 1
- UrnParserPart = 2
- UrnParserColon = 3
- UrnParserHyphen = 4
- UrnParserWhitespace = 5
- )
- // UrnParser rules.
- const (
- UrnParserRULE_urn = 0
- UrnParserRULE_iD = 1
- UrnParserRULE_sS = 2
- )
- // IUrnContext is an interface to support dynamic dispatch.
- type IUrnContext interface {
- antlr.ParserRuleContext
- // GetParser returns the parser.
- GetParser() antlr.Parser
- // IsUrnContext differentiates from other interfaces.
- IsUrnContext()
- }
- type UrnContext struct {
- *antlr.BaseParserRuleContext
- parser antlr.Parser
- }
- func NewEmptyUrnContext() *UrnContext {
- var p = new(UrnContext)
- p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
- p.RuleIndex = UrnParserRULE_urn
- return p
- }
- func (*UrnContext) IsUrnContext() {}
- func NewUrnContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *UrnContext {
- var p = new(UrnContext)
- p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
- p.parser = parser
- p.RuleIndex = UrnParserRULE_urn
- return p
- }
- func (s *UrnContext) GetParser() antlr.Parser { return s.parser }
- func (s *UrnContext) Urn() antlr.TerminalNode {
- return s.GetToken(UrnParserUrn, 0)
- }
- func (s *UrnContext) AllColon() []antlr.TerminalNode {
- return s.GetTokens(UrnParserColon)
- }
- func (s *UrnContext) Colon(i int) antlr.TerminalNode {
- return s.GetToken(UrnParserColon, i)
- }
- func (s *UrnContext) ID() IIDContext {
- var t = s.GetTypedRuleContext(reflect.TypeOf((*IIDContext)(nil)).Elem(), 0)
- if t == nil {
- return nil
- }
- return t.(IIDContext)
- }
- func (s *UrnContext) SS() ISSContext {
- var t = s.GetTypedRuleContext(reflect.TypeOf((*ISSContext)(nil)).Elem(), 0)
- if t == nil {
- return nil
- }
- return t.(ISSContext)
- }
- func (s *UrnContext) EOF() antlr.TerminalNode {
- return s.GetToken(UrnParserEOF, 0)
- }
- func (s *UrnContext) GetRuleContext() antlr.RuleContext {
- return s
- }
- func (s *UrnContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
- return antlr.TreesStringTree(s, ruleNames, recog)
- }
- func (s *UrnContext) EnterRule(listener antlr.ParseTreeListener) {
- if listenerT, ok := listener.(UrnListener); ok {
- listenerT.EnterUrn(s)
- }
- }
- func (s *UrnContext) ExitRule(listener antlr.ParseTreeListener) {
- if listenerT, ok := listener.(UrnListener); ok {
- listenerT.ExitUrn(s)
- }
- }
- func (p *UrnParser) Urn() (localctx IUrnContext) {
- localctx = NewUrnContext(p, p.GetParserRuleContext(), p.GetState())
- p.EnterRule(localctx, 0, UrnParserRULE_urn)
- defer func() {
- p.ExitRule()
- }()
- defer func() {
- if err := recover(); err != nil {
- if v, ok := err.(antlr.RecognitionException); ok {
- localctx.SetException(v)
- p.GetErrorHandler().ReportError(p, v)
- p.GetErrorHandler().Recover(p, v)
- } else {
- panic(err)
- }
- }
- }()
- p.EnterOuterAlt(localctx, 1)
- {
- p.SetState(6)
- p.Match(UrnParserUrn)
- }
- {
- p.SetState(7)
- p.Match(UrnParserColon)
- }
- {
- p.SetState(8)
- p.ID()
- }
- {
- p.SetState(9)
- p.Match(UrnParserColon)
- }
- {
- p.SetState(10)
- p.SS()
- }
- {
- p.SetState(11)
- p.Match(UrnParserEOF)
- }
- return localctx
- }
- // IIDContext is an interface to support dynamic dispatch.
- type IIDContext interface {
- antlr.ParserRuleContext
- // GetParser returns the parser.
- GetParser() antlr.Parser
- // IsIDContext differentiates from other interfaces.
- IsIDContext()
- }
- type IDContext struct {
- *antlr.BaseParserRuleContext
- parser antlr.Parser
- }
- func NewEmptyIDContext() *IDContext {
- var p = new(IDContext)
- p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
- p.RuleIndex = UrnParserRULE_iD
- return p
- }
- func (*IDContext) IsIDContext() {}
- func NewIDContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *IDContext {
- var p = new(IDContext)
- p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
- p.parser = parser
- p.RuleIndex = UrnParserRULE_iD
- return p
- }
- func (s *IDContext) GetParser() antlr.Parser { return s.parser }
- func (s *IDContext) Part() antlr.TerminalNode {
- return s.GetToken(UrnParserPart, 0)
- }
- func (s *IDContext) GetRuleContext() antlr.RuleContext {
- return s
- }
- func (s *IDContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
- return antlr.TreesStringTree(s, ruleNames, recog)
- }
- func (s *IDContext) EnterRule(listener antlr.ParseTreeListener) {
- if listenerT, ok := listener.(UrnListener); ok {
- listenerT.EnterID(s)
- }
- }
- func (s *IDContext) ExitRule(listener antlr.ParseTreeListener) {
- if listenerT, ok := listener.(UrnListener); ok {
- listenerT.ExitID(s)
- }
- }
- func (p *UrnParser) ID() (localctx IIDContext) {
- localctx = NewIDContext(p, p.GetParserRuleContext(), p.GetState())
- p.EnterRule(localctx, 2, UrnParserRULE_iD)
- defer func() {
- p.ExitRule()
- }()
- defer func() {
- if err := recover(); err != nil {
- if v, ok := err.(antlr.RecognitionException); ok {
- localctx.SetException(v)
- p.GetErrorHandler().ReportError(p, v)
- p.GetErrorHandler().Recover(p, v)
- } else {
- panic(err)
- }
- }
- }()
- p.EnterOuterAlt(localctx, 1)
- {
- p.SetState(13)
- p.Match(UrnParserPart)
- }
- p.SetState(14)
- if !(len(localctx.(*IDContext).GetText()) <= 32) {
- panic(antlr.NewFailedPredicateException(p, "len($ctx.GetText()) <= 32", "exceed max (32) number of characters"))
- }
- p.SetState(15)
- if !(isIdentifier(localctx.(*IDContext).GetText())) {
- panic(antlr.NewFailedPredicateException(p, "isIdentifier($ctx.GetText())", "is not a valid identifier"))
- }
- return localctx
- }
- // ISSContext is an interface to support dynamic dispatch.
- type ISSContext interface {
- antlr.ParserRuleContext
- // GetParser returns the parser.
- GetParser() antlr.Parser
- // IsSSContext differentiates from other interfaces.
- IsSSContext()
- }
- type SSContext struct {
- *antlr.BaseParserRuleContext
- parser antlr.Parser
- }
- func NewEmptySSContext() *SSContext {
- var p = new(SSContext)
- p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
- p.RuleIndex = UrnParserRULE_sS
- return p
- }
- func (*SSContext) IsSSContext() {}
- func NewSSContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *SSContext {
- var p = new(SSContext)
- p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
- p.parser = parser
- p.RuleIndex = UrnParserRULE_sS
- return p
- }
- func (s *SSContext) GetParser() antlr.Parser { return s.parser }
- func (s *SSContext) Part() antlr.TerminalNode {
- return s.GetToken(UrnParserPart, 0)
- }
- func (s *SSContext) SS() ISSContext {
- var t = s.GetTypedRuleContext(reflect.TypeOf((*ISSContext)(nil)).Elem(), 0)
- if t == nil {
- return nil
- }
- return t.(ISSContext)
- }
- func (s *SSContext) AllColon() []antlr.TerminalNode {
- return s.GetTokens(UrnParserColon)
- }
- func (s *SSContext) Colon(i int) antlr.TerminalNode {
- return s.GetToken(UrnParserColon, i)
- }
- func (s *SSContext) AllHyphen() []antlr.TerminalNode {
- return s.GetTokens(UrnParserHyphen)
- }
- func (s *SSContext) Hyphen(i int) antlr.TerminalNode {
- return s.GetToken(UrnParserHyphen, i)
- }
- func (s *SSContext) Urn() antlr.TerminalNode {
- return s.GetToken(UrnParserUrn, 0)
- }
- func (s *SSContext) GetRuleContext() antlr.RuleContext {
- return s
- }
- func (s *SSContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
- return antlr.TreesStringTree(s, ruleNames, recog)
- }
- func (s *SSContext) EnterRule(listener antlr.ParseTreeListener) {
- if listenerT, ok := listener.(UrnListener); ok {
- listenerT.EnterSS(s)
- }
- }
- func (s *SSContext) ExitRule(listener antlr.ParseTreeListener) {
- if listenerT, ok := listener.(UrnListener); ok {
- listenerT.ExitSS(s)
- }
- }
- func (p *UrnParser) SS() (localctx ISSContext) {
- localctx = NewSSContext(p, p.GetParserRuleContext(), p.GetState())
- p.EnterRule(localctx, 4, UrnParserRULE_sS)
- var _la int
- defer func() {
- p.ExitRule()
- }()
- defer func() {
- if err := recover(); err != nil {
- if v, ok := err.(antlr.RecognitionException); ok {
- localctx.SetException(v)
- p.GetErrorHandler().ReportError(p, v)
- p.GetErrorHandler().Recover(p, v)
- } else {
- panic(err)
- }
- }
- }()
- var _alt int
- p.SetState(40)
- p.GetErrorHandler().Sync(p)
- switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 5, p.GetParserRuleContext()) {
- case 1:
- p.EnterOuterAlt(localctx, 1)
- {
- p.SetState(17)
- p.Match(UrnParserPart)
- }
- p.SetState(21)
- p.GetErrorHandler().Sync(p)
- _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 0, p.GetParserRuleContext())
- for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
- if _alt == 1 {
- p.SetState(18)
- _la = p.GetTokenStream().LA(1)
- if !(_la == UrnParserColon || _la == UrnParserHyphen) {
- p.GetErrorHandler().RecoverInline(p)
- } else {
- p.GetErrorHandler().ReportMatch(p)
- p.Consume()
- }
- }
- p.SetState(23)
- p.GetErrorHandler().Sync(p)
- _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 0, p.GetParserRuleContext())
- }
- p.SetState(25)
- p.GetErrorHandler().Sync(p)
- _la = p.GetTokenStream().LA(1)
- if (((_la) & -(0x1f+1)) == 0 && ((1 << uint(_la)) & ((1 << UrnParserUrn) | (1 << UrnParserPart) | (1 << UrnParserColon) | (1 << UrnParserHyphen))) != 0) {
- {
- p.SetState(24)
- p.SS()
- }
- }
- case 2:
- p.EnterOuterAlt(localctx, 2)
- p.SetState(28)
- p.GetErrorHandler().Sync(p)
- _alt = 1
- for ok := true; ok; ok = _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
- switch _alt {
- case 1:
- p.SetState(27)
- _la = p.GetTokenStream().LA(1)
- if !(_la == UrnParserColon || _la == UrnParserHyphen) {
- p.GetErrorHandler().RecoverInline(p)
- } else {
- p.GetErrorHandler().ReportMatch(p)
- p.Consume()
- }
- default:
- panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
- }
- p.SetState(30)
- p.GetErrorHandler().Sync(p)
- _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext())
- }
- p.SetState(33)
- p.GetErrorHandler().Sync(p)
- _la = p.GetTokenStream().LA(1)
- if (((_la) & -(0x1f+1)) == 0 && ((1 << uint(_la)) & ((1 << UrnParserUrn) | (1 << UrnParserPart) | (1 << UrnParserColon) | (1 << UrnParserHyphen))) != 0) {
- {
- p.SetState(32)
- p.SS()
- }
- }
- case 3:
- p.EnterOuterAlt(localctx, 3)
- {
- p.SetState(35)
- p.Match(UrnParserPart)
- }
- p.SetState(37)
- p.GetErrorHandler().Sync(p)
- _la = p.GetTokenStream().LA(1)
- if (((_la) & -(0x1f+1)) == 0 && ((1 << uint(_la)) & ((1 << UrnParserUrn) | (1 << UrnParserPart) | (1 << UrnParserColon) | (1 << UrnParserHyphen))) != 0) {
- {
- p.SetState(36)
- p.SS()
- }
- }
- case 4:
- p.EnterOuterAlt(localctx, 4)
- {
- p.SetState(39)
- p.Match(UrnParserUrn)
- }
- }
- return localctx
- }
- func (p *UrnParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {
- switch ruleIndex {
- case 1:
- var t *IDContext = nil
- if localctx != nil { t = localctx.(*IDContext) }
- return p.ID_Sempred(t, predIndex)
- default:
- panic("No predicate with index: " + fmt.Sprint(ruleIndex))
- }
- }
- func (p *UrnParser) ID_Sempred(localctx antlr.RuleContext, predIndex int) bool {
- switch predIndex {
- case 0:
- return len(localctx.(*IDContext).GetText()) <= 32
- case 1:
- return isIdentifier(localctx.(*IDContext).GetText())
- default:
- panic("No predicate with index: " + fmt.Sprint(predIndex))
- }
- }
|