Skip to content

Commit

Permalink
feat: Adds actual usable @ actions to the go templates
Browse files Browse the repository at this point in the history
Signed-off-by: Jim.Idle <jimi@idle.ws>
  • Loading branch information
jimidle authored and parrt committed Apr 18, 2023
1 parent 518121f commit 3aff09a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ package parser // <file.grammarName>
import (
"fmt"
"strconv"
"sync"
"sync"

<if(namedActions.includes)>
// Grammar author supplied additional includes
<namedActions.includes>
<endif>
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
)

Expand Down Expand Up @@ -152,6 +156,10 @@ func (v *Base<file.grammarName>Visitor) Visit<lname; format="cap">(ctx *<lname;
Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
type <parser.name> struct {
<superClass; null="*antlr.BaseParser">
<if(namedActions.structmembers)>
// Grammar author supplied members of the instance struct
<namedActions.structmembers>
<endif>
}

var <parser.grammarName; format="lower">ParserStaticData struct {
Expand Down Expand Up @@ -219,7 +227,8 @@ func New<parser.name>(input antlr.TokenStream) *<parser.name> {
}

<if(namedActions.members)>

// Note that '@members' cannot be changed now, but this should have been 'globals'
// If you are looking to have variables for each instance, use '@structmembers'
<namedActions.members>
<endif>

Expand Down Expand Up @@ -1445,13 +1454,15 @@ package parser

import (
"fmt"
"sync"
"sync"
"unicode"

<if(namedActions.includes)>
// Grammar author supplied additional includes
<namedActions.includes>
<endif>
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
)
<if(namedActions.header)>

<namedActions.header>
<endif>

Expand All @@ -1472,6 +1483,10 @@ type <lexer.name> struct {
<if(superClass)><superClass><else>*antlr.BaseLexer<endif>
channelNames []string
modeNames []string
<if(namedActions.structmembers)>
// Grammar author supplied members of the instance struct
<namedActions.structmembers>
<endif>
// TODO: EOF string
}

Expand Down

0 comments on commit 3aff09a

Please sign in to comment.