隐藏令牌到默认通道 - AntlrV3
假设我在隐藏通道中有空白(WS)。和 仅对于特定规则,我希望也考虑空格,是 是否可以在解析器中单独将 WS 引入该特定规则的默认通道?
Suppose I'm having white spaces (WS) in the hidden channel. And
for a particular rule alone, I want white spaces also to be considered, is
it possible to bring WS to the default channel for that particular rule alone in the parser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看路径问题的答案,注意我如何将 '\n' 放入解析器规则中。您也应该能够输入“”。现在,隐藏通道上的 WS 的所有选项是否都需要包含在规则中将是唯一需要关注的问题。
例如,
请注意,规则名称以小写字母开头,它是解析器规则,而“Token#”以大写字母开头,是词法分析器规则。在这个例子中,规则在不同的标记之间需要一个空格,我想你可以放置类似 (' '|'\t'|'\r'|'\n')+ 的东西,但我还没有尝试过这个,并且会留给你去尝试。
Have look at the answer for your path question, notice how I put a '\n' into the parser rule. You should be able to put ' ' as well. Now, do all the options for your WS on the hidden channel need to be in the rule would be the only concern.
eg
Please note that the rule name starts with a lowercase letter and it is a parser rule while the "Token#" start with uppercase letter and are lexer rules. In between the different tokens the rule requires a space in this example, and I suppose you could put something like (' '|'\t'|'\r'|'\n')+ but I have not tried this and will leave that for you to attempt.
查询隐藏标记流
您始终可以在 C++ 中
ie语义谓词将在匹配词法标记
MYTOK
后检查是否存在空格标记You can always query the hidden token stream
ie in C++
The semantic predicate will check to see if there is a whitespace token after matching the lexical token
MYTOK
词法分析器规则按照它们在语法文件中列出的顺序进行评估。
这意味着你可以有这样的东西:
正如你所看到的,字符串文字中可以有空格或制表符。然而,独立的空格或制表符将被发送到隐藏通道。
Lexer rules are evaluated in the order they are listed in your grammar file.
This means you can have something like this:
As you can see a string literal can have space or tabs in it. However a stand alone space or tab will be sent to the HIDDEN channel.