Skip to content

Commit

Permalink
Merge pull request #3174 from mitar/go-compatibility
Browse files Browse the repository at this point in the history
Making compatibility with actions and predicates in Go better
  • Loading branch information
parrt authored May 21, 2021
2 parents f0d4d12 + b915242 commit c5ad59b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ YYYY/MM/DD, github id, Full name, email
2021/04/24, bigerl, Alexander Bigerl, alexander [äät] bigerl [pkt] eu
2021/05/02, michalharakal, Michal Harakal, [email protected]
2021/05/03, redexp, Sergii Kliuchnyk, [email protected]
2021/05/03, mitar, Mi Tar, [email protected]
2021/05/04, joakker, Joaquín León, [email protected]
2021/05/06, renancaraujo, Renan C. Araújo, [email protected]
2021/05/06, canastro, Ricardo Canastro, [email protected]
12 changes: 12 additions & 0 deletions tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func (l *<lexer.name>) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex
*/
RuleActionFunction(r, actions) ::= <<
func (l *<lexer.name>) <r.name; format="cap">_Action(localctx <if(r.factory.grammar.lexer)>antlr.RuleContext<else>*<r.ctxType><endif>, actionIndex int) {
this := l
_ = this

switch actionIndex {
<if(actions)>
<actions:{index | case <index>:
Expand All @@ -343,6 +346,9 @@ func (l *<lexer.name>) <r.name; format="cap">_Action(localctx <if(r.factory.gram
*/
RuleSempredFunction(r, actions) ::= <<
func (p *<r.factory.grammar.recognizerName>) <r.name; format="cap">_Sempred(localctx antlr.RuleContext, predIndex int) bool {
this := p
_ = this

switch predIndex {
<if(actions)>
<actions:{index | case <index>:
Expand All @@ -367,6 +373,9 @@ RuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs, namedAction

<endif>
func (p *<parser.name>) <currentRule.name; format="cap">(<currentRule.args:{a | <a.name> <a.type>}; separator=", ">) (localctx I<currentRule.ctxType>) {
this := p
_ = this

localctx = New<currentRule.ctxType>(p, p.GetParserRuleContext(), p.GetState()<currentRule.args:{a | , <a.name>}>)
p.EnterRule(localctx, <currentRule.startState>, <parser.name>RULE_<currentRule.name>)
<if(namedActions.init)>
Expand Down Expand Up @@ -440,6 +449,9 @@ func (p *<parser.name>) <currentRule.name; format="cap">(<args:{a | <a.name> <a.
}

func (p *<parser.name>) <currentRule.name>(_p int<args:{a | , <a.name> <a.type>}>) (localctx I<currentRule.ctxType>) {
this := p
_ = this

var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext()
_parentState := p.GetState()
localctx = New<currentRule.ctxType>(p, p.GetParserRuleContext(), _parentState<args:{a | , <a.name>}>)
Expand Down

0 comments on commit c5ad59b

Please sign in to comment.