Changeset 2749 for abnfparser
- Timestamp:
- 03/01/16 13:28:50 (6 years ago)
- Location:
- abnfparser/bap
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
abnfparser/bap/main.c
r2747 r2749 110 110 int tflag = 0; /* print type info */ 111 111 int permissive = 1; /* Be permissive (e.g. accept '|') */ 112 int rfc7405 = 0; /* Support RFC 7405 (%s/%i) */ 112 113 int qflag = 0; /* quiet */ 113 114 int canon = 1; /* canonify */ … … 121 122 { 122 123 fprintf(stderr, "Bill's ABNF Parser version %s\n", versionstring); 123 fprintf(stderr, "usage: bap [-cknqtx][-i rules][-l num][-S name][file]\n"); 124 fprintf(stderr, " (with extensions from <https://svn.tools.ietf.org/svn/wg/httpbis/abnfparser/bap/>)\n", versionstring); 125 fprintf(stderr, "usage: bap [-cknqtx][-i rules][-l num][-S name][-X ext][file]\n"); 124 126 fprintf(stderr, " parse ABNF grammar from file or stdin\n"); 125 127 fprintf(stderr, " Input options:\n"); … … 127 129 fprintf(stderr, " -i file read predefined rules from \"file\"\n"); 128 130 fprintf(stderr, " -S name name rule as production start\n"); 131 fprintf(stderr, " -X ext comma-separated list of allowed extensions\n"); 132 fprintf(stderr, " (only value currently supported is rfc7405)\n"); 129 133 fprintf(stderr, " Output options:\n"); 130 134 fprintf(stderr, " -k add comments for printable characters specified as %%x\n"); … … 152 156 hcreate(MAXRULE); 153 157 154 while ((ch = getopt(argc, argv, "cdi:kntqS:xl: ")) != -1) {158 while ((ch = getopt(argc, argv, "cdi:kntqS:xl:X:")) != -1) { 155 159 switch (ch) { 156 160 case 'c': … … 198 202 break; 199 203 204 case 'X': { 205 char *x = strtok(optarg, ","); 206 while (x != NULL) { 207 if (0 == strcmp(x, "rfc7405")) { 208 rfc7405 = 1; 209 } 210 else { 211 fprintf(stderr, "unknown extension: %s\n", x); 212 exit(2); 213 } 214 x = strtok(NULL, ","); 215 } 216 } 217 break; 218 200 219 case 'x': 201 220 asxml = 1; -
abnfparser/bap/parser.y
r2747 r2749 71 71 } 72 72 73 %token <string> CHARVAL PROSEVAL BINVAL DECVAL HEXVAL RULENAME73 %token <string> CHARVAL CHARVALCS PROSEVAL BINVAL DECVAL HEXVAL RULENAME 74 74 %token <range> BINVALRANGE DECVALRANGE HEXVALRANGE REPEAT LIST 75 75 %token CWSP EQSLASH CRLF … … 322 322 $$->u.e.e.termstr.flags = 0; 323 323 } 324 | CHARVALCS { 325 char *p = $1; 326 if (*$1) 327 p += strlen($1) - 1; 328 if (*p == '\n' || *p == '\r') { 329 mywarn(MYERROR, "unterminated quoted-string"); 330 YYERROR; 331 } 332 $$ = newobj(T_TERMSTR); 333 $$->u.e.e.termstr.str = $1; 334 $$->u.e.e.termstr.flags = F_CASESENSITIVE; 335 } 324 336 | numval { 325 337 $$ = newobj(T_TERMSTR); -
abnfparser/bap/scanner.l
r2747 r2749 43 43 int yyerrors = 0; 44 44 extern int permissive; 45 extern int rfc7405; 45 46 int indent = -1; 46 47 … … 93 94 mywarn(MYWARNING, "zero-length char-val"); 94 95 return CHARVAL; 96 } 97 \%i\"{charval}["\r\n] { 98 if (!rfc7405) { 99 mywarn(MYERROR, "need to enable support for RFC 7405 using -Xrfc7405"); 100 badchar = yytext[0]; 101 BEGIN(SKIP); 102 } 103 char *p; 104 yycolumn += strlen(yytext); 105 yylval.string = strdup(yytext + 3); 106 p = &yylval.string[strlen(yylval.string) - 1]; 107 if (*p != '"') { 108 mywarn(MYERROR, "unterminated char-val"); 109 unput(*p); /* put the cr or lf back */ 110 } 111 *p = '\0'; 112 if (*yylval.string == '\0') 113 mywarn(MYWARNING, "zero-length char-val"); 114 return CHARVAL; 115 } 116 \%s\"{charval}["\r\n] { 117 if (!rfc7405) { 118 mywarn(MYERROR, "need to enable support for RFC 7405 using -Xrfc7405"); 119 badchar = yytext[0]; 120 BEGIN(SKIP); 121 } 122 char *p; 123 yycolumn += strlen(yytext); 124 yylval.string = strdup(yytext + 3); 125 p = &yylval.string[strlen(yylval.string) - 1]; 126 if (*p != '"') { 127 mywarn(MYERROR, "unterminated char-val"); 128 unput(*p); /* put the cr or lf back */ 129 } 130 *p = '\0'; 131 if (*yylval.string == '\0') 132 mywarn(MYWARNING, "zero-length char-val"); 133 return CHARVALCS; 95 134 } 96 135 \<{proseval}[>\r\n] {
Note: See TracChangeset
for help on using the changeset viewer.