简体   繁体   中英

Is it possible to continue parsing with other rules after an exception is raised in semantics?

Is it possible to fallback to other rules after an exception is raised in a semantic action? Like the following (contrived) scenario:

var = /[a-zA-Z]+/;
keyword = 'for' | 'in';
a = var:var | keyword:keyword;

def a(ast):
    if (ast.var not in symbolTable):
        raise Exception()

and when the exception is raised, parsing continues with the 'keyword' rule. I am aware of the @@keyword feature, but I want to declare keywords at runtime (my parser is for a programming language with user-defined operators).

如果语义代码引发tatsu.exceptions.FailedSemantics ,则异常将被视为ParseException ,因此将恢复正常的解析控制流。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM