Gem 哪个 GEM 具备语法解析的功能?

suupic · May 14, 2012 · Last by hxgdzyuyi replied at May 14, 2012 · 2447 hits

举例来说,有这样一段 nginx 的配置

upstream pool_siteA_fastcgi {                                                                                                                                
    ip_hash;
    server 172.16.0.1:9999 max_fails=2 fail_timeout=30s weight=1;
    server 172.16.0.2:9999 max_fails=2 fail_timeout=30s weight=1;
    server 172.16.0.2:9999 max_fails=2 fail_timeout=30s weight=1;
}

除了用正则挨个匹配,有没有什么 gem 可以配置语法解析,从中提取出类似这样的信息

upstream #{pool_name} {
    #{route_type}
    server #{ip1}:#{port1} #{options}
    server #{ip2}:#{port2} #{options}
    server #{ip3}:#{port3} #{options}
}

使用 ruby 的正则表达式实现不了吗?

没找到 parser,找到了一个 generator:https://github.com/defunkt/nginx_config_generator 不过有人说这是 JSON 语法:http://helloworld.group.iteye.com/group/topic/17450?page=2 貌似 json 库解析不了,楼主可以试试

有一个 rex 是 ruby 版的 lex ~

You need to Sign in before reply, if you don't have an account, please Sign up first.