go - 在 Ragel 中使用带有扫描仪 block 的堆栈的正确方法是什么?

标签 go fsm ragel

我在 Go 中使用 Ragel 6.10。我确定这可能是我的代码有问题,但是当我尝试将堆栈与扫描仪 block 一起使用时,我遇到了一些奇怪的错误。我正在尝试设置括号匹配,我的代码大致如下所示;

ObjectValues := |*
 # other stuff
 '}' => { fret; };
 *|

main := ('{' @{fcall ObjectValues;})*;

查看指南中的第 46 页,看起来这应该是可能的。当我运行 Ragel ragel -G2 -Z main.rl 时。当我尝试编译时出现以下错误(它只发生在 -G2 FSM 生成时);

graphql_collections.rl:47[/Users/nathanfisher/workspace/go/src/github.com/nfisher/gir/graphql_collections.go:325:2]: syntax error: unexpected goto at end of statement
graphql_collections.go:60[/Users/nathanfisher/workspace/go/src/github.com/nfisher/gir/graphql_collections.go:60:1]: label _again defined and not used

注释掉 fret 行会消除错误并警告 postpop 和 prepush 不可访问。

完整代码在这里;

https://github.com/nfisher/gir/blob/broken/graphql_collections.rl#L47

这里是一个工作的最小测试用例;

https://gist.github.com/nfisher/649ca816f82bb3ccd7164331ac2324ac

测试用例错误;

main.rl:13[/Users/nathanfisher/workspace/go/src/github.com/nfisher/gir/command/runner/main.go:119:2]: syntax error: unexpected goto at end of statement
main.go:59[/Users/nathanfisher/workspace/go/src/github.com/nfisher/gir/command/runner/main.go:59:1]: label _again defined and not used

最佳答案

看起来这是一个与 Ragel 在 v 6.10 中生成的代码有关的问题。使用 ragel-6 分支的 HEAD 解决了这个问题。感谢 Adrian Thurston 通过 Twitter 提供 super 响应/帮助。 :)

从这里重新格式化代码;

compilation error

至此修复错误;

compiles

关于go - 在 Ragel 中使用带有扫描仪 block 的堆栈的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48517257/

相关文章:

postgresql - Postgres 中的 Go 和 IN 子句

Go 错误处理技术

java - 如何用 Java 创建有限状态机

verilog - 使用 Yosys 导出 FSM

java - 哪个面向 Java 的词法分析器用于简单项目(ANTLR、DIY 等)

http - 来自 golang 的经过身份验证的 http 客户端请求

string - 我如何转换并附加到 Golang 中的一段字符串,一个来自 go-ping 存储库的网络类型变量?

algorithm - 使用有限状态机是否是一般文本解析的良好设计?

c - Ragel 中的字符串插值

ragel - 匹配文件的开头或换行符 (Ragel)