#ifndef URILIB_GRAMMAR_H #define URILIB_GRAMMAR_H #include #include #include using namespace std; using namespace boost::spirit; namespace urilib { //////////////////////////////////////////////////////////////////////////// // // Semantic actions // //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // // Grammar // //////////////////////////////////////////////////////////////////////////// struct Grammar : public grammar { template struct definition { definition(Grammar const& self) { lowalpha = ch_p('a') | ch_p('b') | ch_p('c') | ch_p('d') | ch_p('e') | ch_p('f') | ch_p('g') | ch_p('h') | ch_p('i') | ch_p('j') | ch_p('k') | ch_p('l') | ch_p('m') | ch_p('n') | ch_p('o') | ch_p('p') | ch_p('q') | ch_p('r') | ch_p('s') | ch_p('t') | ch_p('u') | ch_p('v') | ch_p('w') | ch_p('x') | ch_p('y') | ch_p('z'); upalpha = ch_p('A') | ch_p('B') | ch_p('C') | ch_p('D') | ch_p('E') | ch_p('F') | ch_p('G') | ch_p('H') | ch_p('I') | ch_p('J') | ch_p('K') | ch_p('L') | ch_p('M') | ch_p('N') | ch_p('O') | ch_p('P') | ch_p('Q') | ch_p('R') | ch_p('S') | ch_p('T') | ch_p('U') | ch_p('V') | ch_p('W') | ch_p('X') | ch_p('Y') | ch_p('Z'); digit = ch_p('0') | ch_p('1') | ch_p('2') | ch_p('3') | ch_p('4') | ch_p('5') | ch_p('6') | ch_p('7') | ch_p('8') | ch_p('9'); alphanum = alpha | digit; alpha = lowalpha | upalpha; hex = digit | ch_p('A') | ch_p('B') | ch_p('C') | ch_p('D') | ch_p('E') | ch_p('F') | ch_p('a') | ch_p('b') | ch_p('c') | ch_p('d') | ch_p('e') | ch_p('f'); escaped = ch_p('%') >> hex >> hex; mark = ch_p('-') | ch_p('_') | ch_p('.') | ch_p('!') | ch_p('~') | ch_p('*') | ch_p('\'') | ch_p('(') | ch_p(')'); unreserved = alphanum | mark; reserved = ch_p(';') | ch_p('/') | ch_p('?') | ch_p(':') | ch_p('@') | ch_p('&') | ch_p('=') | ch_p('+') | ch_p('$') | ch_p(','); uric = reserved | unreserved | escaped; query = *uric; fragment = *uric; pchar = unreserved | escaped | ch_p(':') | ch_p('@') | ch_p('&') | ch_p('=') | ch_p('+') | ch_p('$') | ch_p(','); param = *pchar; segment = *pchar >> *( ch_p(';') >> param ); path_segments = segment >> *( ch_p('/') >> segment ); IPv4address = +digit >> ch_p('.') >> +digit >> ch_p('.') >> +digit >> ch_p('.') >> +digit; port = *digit; domainlabel = alphanum | alphanum >> *( alphanum | ch_p('-')) >> alphanum; toplabel = alpha | alpha >> *( alphanum | ch_p('-' )) >> alphanum; hostname = *( domainlabel >> '.' ) >> toplabel [ ch_p('.') ]; host = hostname | IPv4address; hostport = host [ ch_p(':') >> port ]; userinfo = *( unreserved | escaped | ch_p(';') | ch_p(':') | ch_p('&') | ch_p('=') | ch_p('+') | ch_p('$') | ch_p(',') ); server = userinfo >> ch_p('@') >> hostport ; reg_name = +( unreserved | escaped | ch_p('$') | ch_p(',') | ch_p(';') | ch_p(':') | ch_p('@') | ch_p('&') | ch_p('=') | ch_p('+') ); rel_segment = +( unreserved | escaped | ch_p(';') | ch_p('@') | ch_p('&') | ch_p('=') | ch_p('+') | ch_p('$') | ch_p(',') ); scheme = alpha >> *( alpha | digit | ch_p('+') | ch_p('-') | ch_p('.' )); authority = server | reg_name; abs_path = ch_p('/') >> path_segments; rel_path = rel_segment [ abs_path ]; net_path = ch_p('//') >> authority [ abs_path ]; uric_no_slash = unreserved | escaped | ch_p(';') | ch_p('?') | ch_p(':') | ch_p('@') | ch_p('&') | ch_p('=') | ch_p('+') | ch_p('$') | ch_p(','); opaque_part = uric_no_slash >> *uric; path = abs_path | opaque_part ; hier_part = ( net_path | abs_path ) [ ch_p('?') >> query ]; relativeURI = ( net_path | abs_path | rel_path ) [ ch_p('?') >> query ]; absoluteURI = scheme >> ch_p(':') >> ( hier_part | opaque_part ); URI_reference = ( absoluteURI | relativeURI ) [ '#' >> fragment ]; } rule lowalpha,upalpha,digit,alphanum,alpha,hex,mark ,unreserved ,reserved, uric,query,fragment,pchar, param,segment,path_segments,IPv4address,port,domainlabel,toplabel,hostname ,host ,hostport , userinfo, server,reg_name,rel_segment, scheme ,authority,abs_path, rel_path , net_path , uric_no_slash , opaque_part, path , hier_part, relativeURI, absoluteURI , URI_reference, escaped; rule const& start() const { return URI_reference; } }; }; }; #endif