Regex 无法将URL分析器正则表达式转换为Ragel
我在RFC2396和RFC3986中找到了一个URL解析器正则表达式Regex 无法将URL分析器正则表达式转换为Ragel,regex,uri,ragel,Regex,Uri,Ragel,我在RFC2396和RFC3986中找到了一个URL解析器正则表达式 ^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? 我将其转换为Ragel: %%{ # RFC 3986 URI Generic Syntax (January 2005) machine url_parser; action pchar { printf("%c", fc); } action schem
^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
我将其转换为Ragel:
%%{
# RFC 3986 URI Generic Syntax (January 2005)
machine url_parser;
action pchar {
printf("%c", fc);
}
action scheme { printf("scheme\n"); }
action scheme_end { printf("\nscheme_end\n"); }
action authority { printf("authority\n"); }
action authority_end { printf("\nauthority_end\n"); }
action path { printf("path\n"); }
action path_end { printf("\npath_end\n"); }
action query { printf("query\n"); }
action query_end { printf("\nquery_end\n"); }
action fragment { printf("fragment\n"); }
action fragment_end { printf("\nfragment_end\n"); }
scheme = (any - [:/?#])+ >scheme $pchar %scheme_end ;
authority = (any - [/?#])* >authority $pchar %authority_end ;
path = (any - [?#])* >path $pchar %path_end ;
query = (any - [#])* >query $pchar %query_end ;
fragment = (any)* >fragment $pchar %fragment_end ;
main := (( scheme ":" )?) <: (( "//" authority )?) <: path ( "?" query )? ( "#" fragment )?;
}%%
#include <cstdio>
#include <cstdlib>
#include <string>
/** Data **/
%% write data;
int main(int argc, char **argv) {
std::string str(argv[1]);
char const* p = str.c_str();
char const* pe = p + str.size();
char const* eof = pe;
int cs = 0;
%% write init;
%% write exec;
return p - str.c_str();
}
当我输入权限和路径时,会成功:
liangxu@dev64:~$ ./uri_test "//www.ics.uci.edu/pub/ietf/uri/?c=www&rot=1&e=%20%20"
authority
www.ics.uci.edu
authority_end
path
/pub/ietf/uri/
path_end
query
c=www&rot=1&e=%20%20
query_end
但当我只输入路径时失败:
liangxu@dev64:~$ ./uri_test "/pub/ietf/uri"
怎么了?你使用了错误的监护人你使用了错误的监护人我最近做了同样的事情,你可以看看我的ragel语法我最近也做了同样的事情,你可以看看我的ragel语法问题似乎在权威部分,如果我删除它,它可以找到路径。至于为什么权威部分不起作用……问题似乎在权威部分,如果我去掉它,它可以找到路径。至于为什么管理部门不工作。。。
liangxu@dev64:~$ ./uri_test "/pub/ietf/uri"
expr $(unique_name,1) . expr >(unique_name,0)