diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index 8c95caea0..8f5464623 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -12,11 +12,11 @@ package parser // import ( - "reflect" - "fmt" - "strconv" + "reflect" + "fmt" + "strconv" - "github.com/pboyer/antlr4/runtime/Go/antlr" + "github.com/pboyer/antlr4/runtime/Go/antlr" ) // Stopgap to suppress unused import error. We aren't certain @@ -45,11 +45,11 @@ import "github.com/pboyer/antlr4/runtime/Go/antlr" // A complete listener for a parse tree produced by type Listener interface { - antlr.ParseTreeListener + antlr.ParseTreeListener (*Context) - Exit(*Context) + Enter(*Context) + Exit(*Context) }; separator="\n"> } @@ -102,11 +102,11 @@ import "github.com/pboyer/antlr4/runtime/Go/antlr" // A complete Visitor for a parse tree produced by . type Visitor interface { - antlr.ParseTreeVisitor + antlr.ParseTreeVisitor #. - Visit(ctx *Context) interface{\} + // Visit a parse tree produced by #. + Visit(ctx *Context) interface{\} }; separator="\n"> } >> @@ -122,12 +122,12 @@ package parser // import "github.com/pboyer/antlr4/runtime/Go/antlr" type BaseVisitor struct { - *antlr.BaseParseTreeVisitor + *antlr.BaseParseTreeVisitor } Visitor) Visit(ctx *Context) interface{\} { - return v.VisitChildren(ctx) + return v.VisitChildren(ctx) \}}; separator="\n"> >> @@ -146,42 +146,42 @@ var symbolicNames = []string{ }; null="\"\"", sepa var ruleNames = []string{ "}; separator=", ", wrap, anchor> } type struct { - + } func New(input antlr.TokenStream) * { - var decisionToDFA = make([]*antlr.DFA,len(deserializedATN.DecisionToState)) - var sharedContextCache = antlr.NewPredictionContextCache() + var decisionToDFA = make([]*antlr.DFA,len(deserializedATN.DecisionToState)) + var sharedContextCache = antlr.NewPredictionContextCache() - for index, ds := range deserializedATN.DecisionToState { - decisionToDFA[index] = antlr.NewDFA(ds, index) - } + for index, ds := range deserializedATN.DecisionToState { + decisionToDFA[index] = antlr.NewDFA(ds, index) + } - this := new() + this := new() - this.BaseParser = antlr.NewBaseParser(input) + this.BaseParser = antlr.NewBaseParser(input) - this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, sharedContextCache) - this.RuleNames = ruleNames - this.LiteralNames = literalNames - this.SymbolicNames = symbolicNames - this.GrammarFileName = "" + this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, sharedContextCache) + this.RuleNames = ruleNames + this.LiteralNames = literalNames + this.SymbolicNames = symbolicNames + this.GrammarFileName = "" - return this + return this } const( - EOF = antlr.TokenEOF - - = }; separator="\n", wrap, anchor> - + EOF = antlr.TokenEOF + + = }; separator="\n", wrap, anchor> + ) const ( - RULE_ = }; separator="\n", wrap, anchor> + RULE_ = }; separator="\n", wrap, anchor> ) @@ -190,11 +190,11 @@ const ( func (p *) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { : - var t *Context = nil - if localctx != nil { t = localctx.(*Context) \} + var t *Context = nil + if localctx != nil { t = localctx.(*Context) \} return p._Sempred(t, predIndex)}; separator="\n"> - default: - panic("No predicate with index:" + fmt.Sprint(ruleIndex)) + default: + panic("No predicate with index:" + fmt.Sprint(ruleIndex)) } } @@ -207,15 +207,15 @@ dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= << func (l *) Action(localctx antlr.RuleContext, ruleIndex, actionIndex int) { switch ruleIndex { - : - - var t *Context = nil - if localctx != nil { t = localctx.(*) \} - l._Action(t, actionIndex) - - l._Action(localctx, actionIndex) - - break}; separator="\n"> + : + + var t *Context = nil + if localctx != nil { t = localctx.(*) \} + l._Action(t, actionIndex) + + l._Action(localctx, actionIndex) + + break}; separator="\n"> default: panic("No registered action for:" + fmt.Sprint(ruleIndex)) } @@ -226,17 +226,17 @@ func (l *) Action(localctx antlr.RuleContext, ruleIndex, actionIndex func (l *) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { - : - - var t *Context = nil - if localctx != nil { t = localctx.(*) \} - return l._Sempred(t, predIndex); - - return l._Sempred(localctx, predIndex); - }; separator="\n"> - default: - panic("No registered predicate for:" + fmt.Sprint(ruleIndex)) - } + : + + var t *Context = nil + if localctx != nil { t = localctx.(*) \} + return l._Sempred(t, predIndex) + + return l._Sempred(localctx, predIndex) + }; separator="\n"> + default: + panic("No registered predicate for:" + fmt.Sprint(ruleIndex)) + } } @@ -251,7 +251,7 @@ RuleActionFunction(r, actions) ::= << func (l *) _Action(localctx antlr.RuleContext*, actionIndex int) { switch actionIndex { - : break}; separator="\n"> @@ -267,7 +267,7 @@ case : RuleSempredFunction(r, actions) ::= << func (p *) _Sempred(localctx antlr.RuleContext, predIndex int) bool { switch predIndex { - : + : return ;}; separator="\n"> default: panic("No predicate with index:" + fmt.Sprint(predIndex)) @@ -275,7 +275,7 @@ func (p *) ( }; separator=", ">) (localctx I) { - localctx = New(p, p.GetParserRuleContext(), p.GetState()}>) - p.EnterRule(localctx, , RULE_) - - var + localctx = New(p, p.GetParserRuleContext(), p.GetState()}>) + p.EnterRule(localctx, , RULE_) + + var - defer func(){ - - p.ExitRule() - }() + 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) - } - - } - }() + 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) + } + + } + }() - - - + + + - return localctx + return localctx } >> -LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs, - namedActions,finallyAction,postamble) ::= -<< +LeftRecursiveRuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs, namedActions, finallyAction, postamble) ::= << }; separator="\n"> func (p *) (_p int, }>) (localctx I) { - var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext() - _parentState := p.GetState() - localctx = New(p, p.GetParserRuleContext(), _parentState}>) - var _prevctx I = localctx - var _ antlr.ParserRuleContext = _prevctx // to prevent unused variable warning - _startState := - p.EnterRecursionRule(localctx, , RULE_, _p) - - var + var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext() + _parentState := p.GetState() + localctx = New(p, p.GetParserRuleContext(), _parentState}>) + var _prevctx I = localctx + var _ antlr.ParserRuleContext = _prevctx // to prevent unused variable warning + _startState := + p.EnterRecursionRule(localctx, , RULE_, _p) + + var - defer func(){ - - p.UnrollRecursionContexts(_parentctx) - }() + defer func(){ + + p.UnrollRecursionContexts(_parentctx) + }() - 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) - } - } - }() + 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) + } + } + }() - - - + + + - return localctx + return localctx } >> @@ -380,18 +378,18 @@ p.SetState() = p.GetTokenStream().LT(1) switch p.GetTokenStream().LA(1) { - - - break }; separator="\n"> + + + break }; separator="\n"> default: - + } >> LL1OptionalBlock(choice, alts, error) ::= << p.SetState() switch p.GetTokenStream().LA(1) { - + break }; separator="\n"> default: @@ -403,7 +401,7 @@ LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= < p.SetState() if { - + } ) ) !> >> @@ -413,10 +411,10 @@ p.SetState() p.GetErrorHandler().Sync(p) for { - - p.SetState() - p.GetErrorHandler().Sync(p) - + + p.SetState() + p.GetErrorHandler().Sync(p) + } >> @@ -425,10 +423,10 @@ p.SetState() p.GetErrorHandler().Sync(p) for ok := true; ok; ok = { - - p.SetState(); - p.GetErrorHandler().Sync(p) - + + p.SetState(); + p.GetErrorHandler().Sync(p) + } >> @@ -443,8 +441,8 @@ la_ := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),,p switch la_ { : - - break + + break }; separator="\n"> } >> @@ -454,8 +452,8 @@ p.SetState() p.GetErrorHandler().Sync(p) la_ := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),,p.GetParserRuleContext()) +1 { - +if la_ == +1 { + }; separator="} else "> } >> @@ -464,14 +462,14 @@ StarBlock(choice, alts, Sync, iteration) ::= << p.SetState() p.GetErrorHandler().Sync(p) _alt := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),,p.GetParserRuleContext()) -for _alt!= && _alt!= antlr.ATNInvalidAltNumber { - if(_alt==1+1) { - - - } - p.SetState() - p.GetErrorHandler().Sync(p) - _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),,p.GetParserRuleContext()) +for _alt != && _alt != antlr.ATNInvalidAltNumber { + if(_alt == 1+1) { + + + } + p.SetState() + p.GetErrorHandler().Sync(p) + _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),,p.GetParserRuleContext()) } >> @@ -480,9 +478,9 @@ PlusBlock(choice, alts, error) ::= << p.SetState() p.GetErrorHandler().Sync(p) _alt := 1+1 -for ok := true; ok; ok = _alt!= && _alt!= antlr.ATNInvalidAltNumber { +for ok := true; ok; ok = _alt != && _alt != antlr.ATNInvalidAltNumber { switch _alt { - +1: break }; separator="\n"> @@ -528,7 +526,7 @@ offsetShiftType(shiftAmount, offset) ::= <% // produces more efficient bytecode when bits.ttypes contains at most two items bitsetInlineComparison(s, bits) ::= <% -==}; separator=" || "> + == }; separator=" || "> %> cases(ttypes) ::= << @@ -554,9 +552,9 @@ p.SetState() = }>p.GetTokenStream().LT(1); if \<=0 || if !() { - = }>p.GetErrorHandler().RecoverInline(p) + = }>p.GetErrorHandler().RecoverInline(p) } else { - p.Consume() + p.Consume() } >> @@ -574,7 +572,7 @@ ArgAction(a, chunks) ::= "" SemPred(p, chunks, failChunks) ::= << p.SetState() if !( ) { - panic( antlr.NewFailedPredicateException(p, , , , "")) + panic( antlr.NewFailedPredicateException(p, , , , "")) } >> @@ -586,13 +584,13 @@ catch () { // lexer actions are not associated with model objects -LexerSkipCommand() ::= "p.Skip()" -LexerMoreCommand() ::= "p.More()" +LexerSkipCommand() ::="p.Skip()" +LexerMoreCommand() ::="p.More()" LexerPopModeCommand() ::= "p.PopMode()" -LexerTypeCommand(arg) ::= "p.SetType()" -LexerChannelCommand(arg) ::= "p.SetChannel()" -LexerModeCommand(arg) ::= "p.SetMode()" -LexerPushModeCommand(arg) ::= "p.PushMode()" +LexerTypeCommand(arg) ::="p.SetType()" +LexerChannelCommand(arg) ::="p.SetChannel()" +LexerModeCommand(arg) ::="p.SetMode()" +LexerPushModeCommand(arg) ::="p.PushMode()" ActionText(t) ::= "" ActionTemplate(t) ::= "" @@ -607,13 +605,13 @@ TokenRef(t) ::= ".Get()" LabelRef(t) ::= ".Get()" ListLabelRef(t) ::= ".Get" -SetAttr(s,rhsChunks) ::= ".Set()" +SetAttr(s, rhsChunks) ::= ".Set()" TokenLabelType() ::= "" InputSymbolType() ::= "" TokenPropertyRef_text(t) ::= "(func() string { if .Get() == nil { return \"\" } else { return .Get().GetText() }}())" -TokenPropertyRef_type(t) ::= "(func() int { if .Get() == nil { return 0 } else { return .Get().GetTokenType() }}())" +TokenPropertyRef_type(t) ::= "(func() int { if .Get() == nil { return 0 } else { return .Get().GetTokenType() }}())" TokenPropertyRef_line(t) ::= "(func() int { if .Get() == nil { return 0 } else { return .Get().GetLine() }}())" TokenPropertyRef_pos(t) ::= "(func() int { if .Get() == nil { return 0 } else { return .Get().GetColumn() }}())" TokenPropertyRef_channel(t) ::= "(func() int { if .Get() == nil { return 0 } else { return .Get().GetChannel() }}())" @@ -621,19 +619,19 @@ TokenPropertyRef_index(t) ::= "(func() int { if .Get.Get().GetStart(),..GetStop()) }}())" -RulePropertyRef_ctx(r) ::= ".Get()" -RulePropertyRef_parser(r) ::= "p" +RulePropertyRef_stop(r) ::="(func() antlr.Token { if .Get() == nil { return nil } else { return .Get().GetStop() }}())" +RulePropertyRef_text(r) ::="(func() string { if .Get() == nil { return \"\" } else { return p.GetTokenStream().GetTextFromTokens( .Get().GetStart(),..GetStop()) }}())" +RulePropertyRef_ctx(r) ::=".Get()" +RulePropertyRef_parser(r) ::="p" ThisRulePropertyRef_start(r) ::= "localctx.GetStart()" -ThisRulePropertyRef_stop(r) ::= "localctx.GetStop()" -ThisRulePropertyRef_text(r) ::= "p.GetTokenStream().GetTextFromTokens(localctx.GetStart(), p.GetTokenStream().LT(-1))" -ThisRulePropertyRef_ctx(r) ::= "" -ThisRulePropertyRef_parser(r) ::= "p" +ThisRulePropertyRef_stop(r) ::="localctx.GetStop()" +ThisRulePropertyRef_text(r) ::="p.GetTokenStream().GetTextFromTokens(localctx.GetStart(), p.GetTokenStream().LT(-1))" +ThisRulePropertyRef_ctx(r) ::="" +ThisRulePropertyRef_parser(r) ::="p" -NonLocalAttrRef(s) ::= "GetInvokingContext()." -SetNonLocalAttr(s, rhsChunks) ::= "GetInvokingContext(). = " +NonLocalAttrRef(s) ::="GetInvokingContext()." +SetNonLocalAttr(s, rhsChunks) ::="GetInvokingContext(). = " AddToLabelList(a) ::= ". = append(., )" @@ -646,64 +644,64 @@ RuleContextListDecl(rdecl) ::= " []I" AttributeDecl(d) ::= " // TODO = " -ContextTokenGetterDecl(t) ::= << +ContextTokenGetterDecl(t) ::=<< () antlr.TerminalNode { - return s.GetToken(, 0) + return s.GetToken(, 0) } >> // should never be called -ContextTokenListGetterDecl(t) ::= << +ContextTokenListGetterDecl(t) ::=<< fail: ContextTokenListGetterDecl should never be called! >> -ContextTokenListIndexedGetterDecl(t) ::= << +ContextTokenListIndexedGetterDecl(t) ::=<< (i int) []antlr.TerminalNode { - if i \< 0 { - return s.GetTokens() - } else { - return []antlr.TerminalNode{ s.GetToken(, i) } - } + if i \< 0 { + return s.GetTokens() + } else { + return []antlr.TerminalNode{ s.GetToken(, i) } + } } >> -ContextRuleGetterDecl(r) ::= << +ContextRuleGetterDecl(r) ::=<< () I { - v := s.GetTypedRuleContext( reflect.TypeOf((*I)(nil)).Elem(),0); + v := s.GetTypedRuleContext( reflect.TypeOf((*I)(nil)).Elem(),0) - if v == nil { - return nil - } + if v == nil { + return nil + } - return v.(I) + return v.(I) } >> // should never be called -ContextRuleListGetterDecl(r) ::= << +ContextRuleListGetterDecl(r) ::=<< fail: ContextRuleListGetterDecl should never be called! >> -ContextRuleListIndexedGetterDecl(r) ::= << +ContextRuleListIndexedGetterDecl(r) ::=<< (i int) []I { - var ts []antlr.RuleContext; + var ts []antlr.RuleContext - if i \< 0 { - ts = s.GetTypedRuleContexts( reflect.TypeOf((*I)(nil)).Elem()) - } else { - ts = []antlr.RuleContext { s.GetTypedRuleContext( reflect.TypeOf((*I)(nil)).Elem(),i) } - } + if i \< 0 { + ts = s.GetTypedRuleContexts( reflect.TypeOf((*I)(nil)).Elem()) + } else { + ts = []antlr.RuleContext { s.GetTypedRuleContext( reflect.TypeOf((*I)(nil)).Elem(),i) } + } - var tst []I = make([]I, len(ts)) - for i, t := range ts { - if t == nil { - tst[i] = nil - } else { - tst[i] = t.(I) - } - } + var tst []I = make([]I, len(ts)) + for i, t := range ts { + if t == nil { + tst[i] = nil + } else { + tst[i] = t.(I) + } + } - return tst + return tst } >> @@ -715,65 +713,64 @@ LexerRuleContext() ::= "RuleContext" RuleContextNameSuffix() ::= "Context" ImplicitTokenLabel(tokenName) ::= "_" -ImplicitRuleLabel(ruleName) ::= "_" -ImplicitSetLabel(id) ::= "_tset" -ListLabelName(label) ::= "