为了账号安全,请及时绑定邮箱和手机立即绑定

Antlr4 Listener 子树检查条件

Antlr4 Listener 子树检查条件

Go
aluckdog 2022-07-11 15:01:42
我是 Antlr 的新手,请原谅我的基本问题,我正在尝试验证以下语句,例如if while_condition contains f_lastmove.. do somethingwhile_condition 也可以有其他条件。如何深入研究 while_condition?我正在使用带有 Golang 的侦听器模式。 
查看完整描述

1 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

我不知道 Go,但在 Java 中你可以这样做:


// In this example, the grammar is called `T.g4`

class WhileLastMoveListener extends TBaseListener {


    private boolean insideWhileCondition = false;

    

    @Override 

    public void enterWhile_condition(TParser.While_conditionContext ctx) { 

        this.insideWhileCondition = true;

    }


    @Override 

    public void exitWhile_condition(TParser.While_conditionContext ctx) {

        this.insideWhileCondition = false;

    }


    @Override 

    public void enterF_lastmove(TParser.F_lastmoveContext ctx) {

        if (this.insideWhileCondition) {

            // Found a `f_lastmove` rule inside a while `while_condition`

        }

    }

}


查看完整回答
反对 回复 2022-07-11
  • 1 回答
  • 0 关注
  • 86 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号