代码之家  ›  专栏  ›  技术社区  ›  Nathan

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

  •  1
  • Nathan  · 技术社区  · 8 年前

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

    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行将删除错误,并警告无法访问POSTOP和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
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Nathan    8 年前

    看起来这是一个与Ragel在6.10版中生成的代码有关的问题。使用ragel-6分支的负责人解决了这个问题。感谢阿德里安·瑟斯顿在推特上的出色响应/帮助。:)

    从此处重新格式化代码;

    compilation error

    以此修复错误;

    compiles