All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.antlr.v4.tool.templates.codegen.Go.Go.stg Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
fileHeader(grammarFileName, ANTLRVersion) ::= <<
// Code generated from  by ANTLR . DO NOT EDIT.
>>

ParserFile(file, parser, namedActions, contextSuperClass) ::= <<



package  // 

package parser // 


import (
	"fmt"
	"reflect"
	"strconv"

	"github.com/antlr/antlr4/runtime/Go/antlr"
)






// Suppress unused import errors
var _ = fmt.Printf
var _ = reflect.Copy
var _ = strconv.Itoa






>>

ListenerFile(file, header, namedActions) ::= <<



package  // 

package parser // 


import "github.com/antlr/antlr4/runtime/Go/antlr"

// Listener is a complete listener for a parse tree produced by .
type Listener interface {
	antlr.ParseTreeListener

	 is called when entering the  production.
Enter(c *Context)}; separator="\n\n">

	 is called when exiting the  production.
Exit(c *Context)}; separator="\n\n">
}

>>

BaseListenerFile(file, header, namedActions) ::= <<



package  // 

package parser // 


import "github.com/antlr/antlr4/runtime/Go/antlr"

// BaseListener is a complete listener for a parse tree produced by .
type BaseListener struct{}

var _ Listener = &BaseListener{}

// VisitTerminal is called when a terminal node is visited.
func (s *BaseListener) VisitTerminal(node antlr.TerminalNode) {}

// VisitErrorNode is called when an error node is visited.
func (s *BaseListener) VisitErrorNode(node antlr.ErrorNode) {}

// EnterEveryRule is called when any rule is entered.
func (s *BaseListener) EnterEveryRule(ctx antlr.ParserRuleContext) {}

// ExitEveryRule is called when any rule is exited.
func (s *BaseListener) ExitEveryRule(ctx antlr.ParserRuleContext) {}

 is called when production  is entered.
func (s *BaseListener) Enter(ctx *Context) {\}

// Exit is called when production  is exited.
func (s *BaseListener) Exit(ctx *Context) {\}}; separator="\n\n">

>>

VisitorFile(file, header, namedActions) ::= <<



package  // 

package parser // 


import "github.com/antlr/antlr4/runtime/Go/antlr"


// A complete Visitor for a parse tree produced by . type Visitor interface { antlr.ParseTreeVisitor #. Visit(ctx *Context) interface{\} }; separator="\n"> } >> BaseVisitorFile(file, header, namedActions) ::= << package // package parser // import "github.com/antlr/antlr4/runtime/Go/antlr" type BaseVisitor struct { *antlr.BaseParseTreeVisitor } Visitor) Visit(ctx *Context) interface{\} { return v.VisitChildren(ctx) \}}; separator="\n\n"> >> Parser(parser, funcs, atn, sempredFuncs, superClass) ::= << var parserATN = var parserATN []uint16 var deserializer = antlr.NewATNDeserializer(nil) var deserializedATN = deserializer.DeserializeFromUInt16(parserATN) var literalNames = []string{ , } var literalNames []string var symbolicNames = []string{ , } var symbolicNames []string var ruleNames = []string{ "}; separator=", ", wrap>, } var ruleNames []string var decisionToDFA = make([]*antlr.DFA, len(deserializedATN.DecisionToState)) func init() { for index, ds := range deserializedATN.DecisionToState { decisionToDFA[index] = antlr.NewDFA(ds, index) } } type struct { } func New(input antlr.TokenStream) * { this := new() 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 = "" return this } // tokens. const ( EOF = antlr.TokenEOF = }; separator="\n"> ) // EOF is the token. const EOF = antlr.TokenEOF // rules. const ( RULE_ = }; separator="\n"> ) // RULE_ is the rule. const RULE_ = func (p *) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { : var t *Context = nil if localctx != nil { t = localctx.(*Context) \} return p._Sempred(t, predIndex)}; separator="\n\n"> default: panic("No predicate with index: " + fmt.Sprint(ruleIndex)) } } >> dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= << func (l *) Action(localctx antlr.RuleContext, ruleIndex, actionIndex int) { switch ruleIndex { : l._Action(localctx, actionIndex) var t *Context = nil if localctx != nil { t = localctx.(*) \} l._Action(t, actionIndex) }; separator="\n\n"> default: panic("No registered action for: " + fmt.Sprint(ruleIndex)) } } func (l *) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { : return l._Sempred(localctx, predIndex) var t *Context = nil if localctx != nil { t = localctx.(*) \} return l._Sempred(t, predIndex) }; separator="\n\n"> default: panic("No registered predicate for: " + fmt.Sprint(ruleIndex)) } } >> /* This generates a private method since the actionIndex is generated, making an * overriding implementation impossible to maintain. */ RuleActionFunction(r, actions) ::= << func (l *) _Action(localctx antlr.RuleContext*, actionIndex int) { switch actionIndex { : }; separator="\n\n"> default: panic("No registered action for: " + fmt.Sprint(actionIndex)) } } >> /* This generates a private method since the predIndex is generated, making an * overriding implementation impossible to maintain. */ RuleSempredFunction(r, actions) ::= << func (p *) _Sempred(localctx antlr.RuleContext, predIndex int) bool { switch predIndex { : return }; separator="\n\n"> default: panic("No predicate with index: " + fmt.Sprint(predIndex)) } } >> RuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs, namedActions, finallyAction, postamble, exceptions) ::= << }; separator="\n\n"> func (p *) ( }; separator=", ">) (localctx I) { localctx = New(p, p.GetParserRuleContext(), p.GetState()}>) p.EnterRule(localctx, , RULE_) }; separator="\n"> 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 return localctx } >> LeftRecursiveRuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs, namedActions, finallyAction, postamble) ::= << }; separator="\n\n"> func (p *) ( }; separator=", ">) (localctx I) { return p.(0}>) } 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 // TODO: To prevent unused variable warning. _startState := p.EnterRecursionRule(localctx, , RULE_, _p) }; separator="\n"> 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) } } }() var _alt int return localctx } >> CodeBlockForOuterMostAlt(currentOuterMostAltCodeBlock, locals, preamble, ops) ::= << localctx = NewContext(p, localctx) p.EnterOuterAlt(localctx, ) >> CodeBlockForAlt(currentAltCodeBlock, locals, preamble, ops) ::= << }; separator="\n"> >> LL1AltBlock(choice, preamble, alts, error) ::= << p.SetState() p.GetErrorHandler().Sync(p) = p.GetTokenStream().LT(1) switch p.GetTokenStream().LA(1) { }; separator=", ">: }; separator="\n\n"> default: } >> LL1OptionalBlock(choice, alts, error) ::= << p.SetState() p.GetErrorHandler().Sync(p) switch p.GetTokenStream().LA(1) { }; separator=", ">: }; separator="\n\n"> default: } >> LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= << p.SetState() p.GetErrorHandler().Sync(p) if { }) { }!> >> LL1StarBlockSingleAlt(choice, loopExpr, alts, preamble, iteration) ::= << p.SetState() p.GetErrorHandler().Sync(p) for { p.SetState() p.GetErrorHandler().Sync(p) } >> LL1PlusBlockSingleAlt(choice, loopExpr, alts, preamble, iteration) ::= << p.SetState() p.GetErrorHandler().Sync(p) for ok := true; ok; ok = { p.SetState() p.GetErrorHandler().Sync(p) } >> // LL(*) stuff AltBlock(choice, preamble, alts, error) ::= << p.SetState() p.GetErrorHandler().Sync(p) = _input.LT(1) switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), , p.GetParserRuleContext()) { : }; separator="\n\n"> } >> OptionalBlock(choice, alts, error) ::= << p.SetState() p.GetErrorHandler().Sync(p) , p.GetParserRuleContext()) == +1 { }; separator="} else "> } >> 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()) } >> PlusBlock(choice, alts, error) ::= << p.SetState() p.GetErrorHandler().Sync(p) _alt = 1+1 for ok := true; ok; ok = _alt != && _alt != antlr.ATNInvalidAltNumber { switch _alt { +1: }; separator="\n\n"> default: } p.SetState() p.GetErrorHandler().Sync(p) _alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), , p.GetParserRuleContext()) } >> Sync(s) ::= "Sync()" ThrowNoViableAlt(t) ::= "panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))" TestSetInline(s) ::= << }; separator=" || "> >> // Javascript language spec - shift operators are 32 bits long max testShiftInRange(shiftAmount) ::= << (() & -(0x1f+1)) == 0 >> // produces smaller bytecode only when bits.ttypes contains more than two items bitsetBitfieldComparison(s, bits) ::= <% (})> && ((1 \<\< uint()) & ()}; separator=" | ">)) != 0) %> isZero ::= [ "0":true, default:false ] offsetShiftVar(shiftAmount, offset) ::= <% ( - ) %> offsetShiftType(shiftAmount, offset) ::= <% ( - ) %> // produces more efficient bytecode when bits.ttypes contains at most two items bitsetInlineComparison(s, bits) ::= <% == }; separator=" || "> %> InvokeRule(r, argExprsChunks) ::= << { p.SetState() var _x = p.(, ) var _x = p.() = _x}; separator="\n"> p.(, ) p.() } >> MatchToken(m) ::= << { p.SetState() var _m = p.Match() = _m}; separator="\n"> p.Match() } >> MatchSet(m, expr, capture) ::= "" MatchNotSet(m, expr, capture) ::= "" CommonSetStuff(m, expr, capture, invert) ::= << { p.SetState() var _lt = p.GetTokenStream().LT(1) = _lt}; separator="\n"> if \<= 0 || if !() { var _ri = p.GetErrorHandler().RecoverInline(p) = _ri}; separator="\n"> p.GetErrorHandler().RecoverInline(p) } else { p.GetErrorHandler().ReportMatch(p) p.Consume() } } >> Wildcard(w) ::= << p.SetState() var _mwc = p.MatchWildcard() = _mwc}; separator="\n"> p.MatchWildcard() >> // ACTION STUFF Action(a, foo, chunks) ::= "" ArgAction(a, chunks) ::= "" SemPred(p, chunks, failChunks) ::= << p.SetState() if !() { panic(antlr.NewFailedPredicateException(p, , , , "")) } >> ExceptionClause(e, catchArg, catchAction) ::= << catch () { } >> // lexer actions are not associated with model objects LexerSkipCommand() ::= "p.Skip()" LexerMoreCommand() ::= "p.More()" LexerPopModeCommand() ::= "p.PopMode()" LexerTypeCommand(arg, grammar) ::= "p.SetType()" LexerChannelCommand(arg, grammar) ::= "p.SetChannel()" LexerModeCommand(arg, grammar) ::= "p.SetMode()" LexerPushModeCommand(arg, grammar) ::= "p.PushMode()" ActionText(t) ::= "" ActionTemplate(t) ::= "" ArgRef(a) ::= "." LocalRef(a) ::= "." RetValueRef(a) ::= "." QRetValueRef(a) ::= ".Get().Get()" /** How to translate $tokenLabel */ TokenRef(t) ::= ".Get()" LabelRef(t) ::= ".Get()" ListLabelRef(t) ::= ".Get" 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_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() }}())" TokenPropertyRef_index(t) ::= "(func() int { if .Get() == nil { return 0 } else { return .Get().GetTokenIndex() }}())" TokenPropertyRef_int(t) ::= "(func() int { if .Get() == nil { return 0 } else { i, _ := strconv.Atoi(.Get().GetText()); return i }}())" RulePropertyRef_start(r) ::= "(func() antlr.Token { if .Get() == nil { return nil } else { return .Get().GetStart() }}())" 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" NonLocalAttrRef(s) ::= "GetInvokingContext()." SetNonLocalAttr(s, rhsChunks) ::= "GetInvokingContext(). = " AddToLabelList(a) ::= ". = append(., )" TokenDecl(t) ::= " " TokenTypeDecl(t) ::= " int" TokenListDecl(t) ::= " []antlr.Token" RuleContextDecl(r) ::= " I " RuleContextListDecl(rdecl) ::= " []I" AttributeDecl(d) ::= " // TODO = " ContextTokenGetterDecl(t) ::= << () antlr.TerminalNode { return s.GetToken(, 0) } >> ContextTokenListGetterDecl(t) ::= << All() []antlr.TerminalNode { return s.GetTokens() } >> ContextTokenListIndexedGetterDecl(t) ::= << (i int) antlr.TerminalNode { return s.GetToken(, i) } >> ContextRuleGetterDecl(r) ::= << () I { var t = s.GetTypedRuleContext(reflect.TypeOf((*I)(nil)).Elem(), 0) if t == nil { return nil } return t.(I) } >> ContextRuleListGetterDecl(r) ::= << All() []I { var ts = s.GetTypedRuleContexts(reflect.TypeOf((*I)(nil)).Elem()) var tst = make([]I, len(ts)) for i, t := range ts { if t != nil { tst[i] = t.(I) } } return tst } >> ContextRuleListIndexedGetterDecl(r) ::= << (i int) I { var t = s.GetTypedRuleContext(reflect.TypeOf((*I)(nil)).Elem(), i) if t == nil { return nil } return t.(I) } >> LexerRuleContext() ::= "RuleContext" /** The rule context name is the rule followed by a suffix; e.g., * r becomes rContext. */ RuleContextNameSuffix() ::= "Context" ImplicitTokenLabel(tokenName) ::= "_" ImplicitRuleLabel(ruleName) ::= "_" ImplicitSetLabel(id) ::= "_tset" ListLabelName(label) ::= "