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 b015c0b5b..0370321e1 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 @@ -1,34 +1,3 @@ -/* - * [The "BSD license"] - * Copyright (c) 2012 Terence Parr - * Copyright (c) 2012 Sam Harwell - * Copyright (c) 2014 Eric Vergnaud - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - /** ANTLR tool checks output templates are compatible with tool code generation. * For now, a simple string match used on x.y of x.y.z scheme. * Must match Tool.VERSION during load to templates. @@ -44,14 +13,23 @@ pythonTypeInitMap ::= [ default:"None" // anything other than a primitive type is an object ] + + + // args must be , + + + ParserFile(file, parser, namedActions) ::= << + -var antlr4 = require('antlr4/index'); +import ("antlr") + var Listener = require('./Listener').Listener; + var Visitor = require('./Visitor').Visitor; @@ -60,65 +38,72 @@ var Visitor = require('./Visitor'). >> + + ListenerFile(file, header) ::= << -var antlr4 = require('antlr4/index'); +package + +import( + "antlr4" +) // This class defines a complete listener for a parse tree produced by . -function Listener() { - antlr4.tree.ParseTreeListener.call(this); - return this; -} -Listener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype); -Listener.prototype.constructor = Listener; +type Listener struct { + ParseTreeListener +} #. -Listener.prototype.enter = function(ctx) { -\}; +func (l Listener) enter(ctx) { +\} // Exit a parse tree produced by #. -Listener.prototype.exit = function(ctx) { -\}; +func (l Listener) exit(ctx) { +\} }; separator="\n"> -exports.Listener = Listener; >> + + + VisitorFile(file, header) ::= << -var antlr4 = require('antlr4/index'); +import("antlr4") +
// This class defines a complete generic visitor for a parse tree produced by . -function Visitor() { - antlr4.tree.ParseTreeVisitor.call(this); - return this; +type Visitor struct { + ParseTreeVisitor } -Visitor.prototype = Object.create(antlr4.tree.ParseTreeVisitor.prototype); -Visitor.prototype.constructor = Visitor; - #. -Visitor.prototype.visit = function(ctx) { -\}; +func (l Visitor) visit(ctx) { +\} }; separator="\n"> -exports.Visitor = Visitor; >> + fileHeader(grammarFileName, ANTLRVersion) ::= << // Generated from by ANTLR -// jshint ignore: start >> + + + + + + Parser(parser, funcs, atn, sempredFuncs, superClass) ::= << var = require('./').; @@ -247,6 +232,10 @@ RuleSempredFunction(r, actions) ::= << >> + + + + RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,finallyAction,postamble,exceptions) ::= << @@ -326,18 +315,27 @@ LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs, >> + + + CodeBlockForOuterMostAlt(currentOuterMostAltCodeBlock, locals, preamble, ops) ::= << localctx = new Context(this, localctx); this.enterOuterAlt(localctx, ); >> + + + CodeBlockForAlt(currentAltCodeBlock, locals, preamble, ops) ::= << >> + + + LL1AltBlock(choice, preamble, alts, error) ::= << this.state = ; = this._input.LT(1); @@ -351,6 +349,9 @@ default: } >> + + + LL1OptionalBlock(choice, alts, error) ::= << this.state = ; switch (this._input.LA(1)) { @@ -362,6 +363,9 @@ default: } >> + + + LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= << this.state = ; @@ -732,6 +736,8 @@ ListenerDispatchMethod(method) ::= << >> + + VisitorDispatchMethod(method) ::= << .prototype.accept = function(visitor) { if ( visitor instanceof Visitor ) { @@ -743,6 +749,9 @@ VisitorDispatchMethod(method) ::= << >> + + + AttributeDecl(d) ::= "this. = null" /** If we don't know location of label def x, use this template */ @@ -798,15 +807,18 @@ var antlr4 = require('antlr4/index'); >> + + + Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= << -var atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN); +// TODO var atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN); -var decisionsToDFA = atn.decisionToState.map( function(ds, index) { return new antlr4.dfa.DFA(ds, index); }); +// TODO var decisionsToDFA = atn.decisionToState.map( function(ds, index) { return new antlr4.dfa.DFA(ds, index); }); -function (input) { +// TODO function (input) { antlr4.Lexer.call(this, input); this._interp = new antlr4.atn.LexerATNSimulator(this, atn, decisionsToDFA, new antlr4.PredictionContextCache()); return this; @@ -852,4 +864,4 @@ initValue(typeName) ::= << >> -codeFileExtension() ::= ".js" +codeFileExtension() ::= ".go"