我在 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 响应/帮助。 :)
从这里重新格式化代码;
至此修复错误;
关于go - 在 Ragel 中使用带有扫描仪 block 的堆栈的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48517257/