在 ruby ripper 解析期间检测错误
有谁知道当向 Ruby 的 ripper 库提供格式错误的输入时如何检测错误?
ruby-1.9.2-p180 :002 > Ripper.sexp("array[1 2]")
=> [:program, [:@int, "2", [1, 8]]]
ruby-1.9.2-p180 :003 >
我稍微研究了一下源代码,发现了 #compile_error、#warning、#warn 和 #yydebug,但尚不清楚如何让这些方法发挥作用。毫无疑问,这里有一些简单的答案。
Has anyone figured out how to detect errors when malformed input is given to Ruby's ripper library?
ruby-1.9.2-p180 :002 > Ripper.sexp("array[1 2]")
=> [:program, [:@int, "2", [1, 8]]]
ruby-1.9.2-p180 :003 >
I've poked around the sources a little and discovered #compile_error, #warning, #warn, and #yydebug, but it's not yet clear how to get any of these methods to work. No doubt there's some simple answer here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我在某处读到,ruby ripper 扩展仍在
活跃开发中,所以如果没有人抽出时间来连接 #compile_error、#warning 或 #warn,我不会感到惊讶。Ripper#yydebug 在 Ruby 1.9.3 中工作,它可能在 1.9.2 中工作,我只是做错了什么。但它打印出调试信息,其中只有一小部分与错误相关。
这是检测错误的一种直接方法:
有几个事件的名称中包含“error”:on_alias_error、on_assign_error、on_class_name_error、on_param_error 和 on_parse_error。
I think I read somewhere that the ruby ripper extension is still under
activedevelopment, so I wouldn't be surprised if no one has gotten around to wiring up #compile_error, #warning or #warn yet.Ripper#yydebug works in Ruby 1.9.3, and it might work in 1.9.2 and I was just doing something wrong. But it prints out debugging information, only a little of which will be related to an error.
This is one straightforward way to detect errors:
There are several events that contain "error" in the name: on_alias_error, on_assign_error, on_class_name_error, on_param_error and on_parse_error.