Skip to content

Commit

Permalink
Merge pull request #209 from httpwg/reschke-i164
Browse files Browse the repository at this point in the history
simplify list rule mapping for consumers not to address cardinality
  • Loading branch information
royfielding committed Mar 28, 2019
2 parents dabb43e + 4fcefa3 commit e475f36
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -88,7 +88,7 @@ $(bd)/%.abnf: %.xml lib/extract-artwork.xslt
$(saxon) $< lib/xreffer.xslt | $(saxon) - lib/extract-artwork.xslt type="abnf7230" >$@

$(bd)/%.parsed-abnf: $(bd)/%.abnf
$(bap)/bap -i $(bap)/core.abnf -X rfc7405 < $< | LC_COLLATE=C sort | $(bap)/bap -k -i $(bap)/core.abnf -X rfc7405 -l 69 >$@
$(bap)/bap -i $(bap)/core.abnf -L1 -X rfc7405 < $< | LC_COLLATE=C sort | $(bap)/bap -k -i $(bap)/core.abnf -L1 -X rfc7405 -l 69 >$@

$(bd)/%.abnf-appendix: $(bd)/%.parsed-abnf
$(saxon) $*.xml lib/abnf2xml2rfc.xslt abnf="../$<" >$@
Expand Down
106 changes: 73 additions & 33 deletions bap/main.c
Expand Up @@ -114,6 +114,7 @@ int qflag = 0; /* quiet */
int canon = 1; /* canonify */
int asxml = 0; /* output XML */
int olenlimit = 0; /* 0 for unlimited, might be any other value */
int listrulex = 0; /* 0 for RFC 7320-style, 1 for 2019 experimental */

int yyparse(void);

Expand All @@ -122,7 +123,7 @@ usage(void)
{
fprintf(stderr, "Bill's ABNF Parser version %s\n", versionstring);
fprintf(stderr, " (with extensions from <https://svn.tools.ietf.org/svn/wg/httpbis/abnfparser/bap/>)\n", versionstring);
fprintf(stderr, "usage: bap [-cknqtx][-i rules][-l num][-S name][-X ext][file]\n");
fprintf(stderr, "usage: bap [-cknqtx][-i rules][-l num][-L rtyp][-S name][-X ext][file]\n");
fprintf(stderr, " parse ABNF grammar from file or stdin\n");
fprintf(stderr, " Input options:\n");
fprintf(stderr, " -c include rule definition line # in comment\n");
Expand All @@ -133,6 +134,7 @@ usage(void)
fprintf(stderr, " Output options:\n");
fprintf(stderr, " -k add comments for printable characters specified as %%x\n");
fprintf(stderr, " -l num limit the length of each line to \"num\" characters\n");
fprintf(stderr, " -L rtyp how to expand #list production (0 == 2014, 1 == 2019)\n");
fprintf(stderr, " -n don't \"canonify\" result\n");
fprintf(stderr, " -q don't print parsed grammar\n");
fprintf(stderr, " -t include type info in result\n");
Expand All @@ -155,7 +157,7 @@ main(int argc, char **argv)
#endif
hcreate(MAXRULE);

while ((ch = getopt(argc, argv, "cdi:kntqS:xl:X:")) != -1) {
while ((ch = getopt(argc, argv, "cdi:kntqS:xl:L:X:")) != -1) {
switch (ch) {
case 'c':
cflag++;
Expand Down Expand Up @@ -224,6 +226,14 @@ main(int argc, char **argv)
olenlimit = atoi(optarg);
break;

case 'L':
listrulex = atoi(optarg);
if (listrulex != 0 && listrulex != 1) {
fprintf(stderr, "-L: illegal argument %d\n", listrulex);
exit(2);
}
break;

default:
usage();
}
Expand Down Expand Up @@ -416,6 +426,61 @@ printobjasxml(object *o, int indent)
*/
#define NOBRACKET(o) ((o->next == NULL) && (o->u.e.repetition.lo == 0))

// code to emit #rule (RFC 7230)
static void
p_listrule_rfc7230(object *o)
{
if (o->u.e.repetition.lo == 0) {
local_printf("[ ( \",\" / ");
if (o->u.e.e.rule.rule) {
local_printf("%s", o->u.e.e.rule.rule->name);
o->u.e.e.rule.rule->used = 1;
} else {
local_printf("%s", o->u.e.e.rule.name);
}
local_printf(" ) *( OWS \",\" [ OWS ");
local_printf("%s", (o->u.e.e.rule.rule) ?
o->u.e.e.rule.rule->name :
o->u.e.e.rule.name);
local_printf(" ] ) ]");
} else if (o->u.e.repetition.lo == 1) {
local_printf(" *( \",\" OWS ) ");
if (o->u.e.e.rule.rule) {
local_printf("%s", o->u.e.e.rule.rule->name);
o->u.e.e.rule.rule->used = 1;
} else {
local_printf("%s", o->u.e.e.rule.name);
}
local_printf(" *( OWS \",\" [ OWS ");
local_printf("%s", (o->u.e.e.rule.rule) ?
o->u.e.e.rule.rule->name :
o->u.e.e.rule.name);
local_printf(" ] )");
}
else {
local_printf("TODO: something is wrong");
}
}

// code to emit #rule (2019)
// #element =&gt; *( OWS "," ) *( [ OWS element ] OWS "," )
static void
p_listrule_2019(object *o)
{
local_printf("[ ");
if (o->u.e.e.rule.rule) {
local_printf("%s", o->u.e.e.rule.rule->name);
o->u.e.e.rule.rule->used = 1;
} else {
local_printf("%s", o->u.e.e.rule.name);
}
local_printf(" ] *( OWS \",\" OWS [ ");
local_printf("%s", (o->u.e.e.rule.rule) ?
o->u.e.e.rule.rule->name :
o->u.e.e.rule.name);
local_printf(" ] )");
}

static void
printobj_r(object *o, int parenttype, int tflag)
{
Expand All @@ -441,38 +506,13 @@ printobj_r(object *o, int parenttype, int tflag)
break;
case T_RULE: /* identation to delimit the code change */
if (tflag)
local_printf("{RULE}");
local_printf("{RULE}");
if (o->u.e.islist) {
if (o->u.e.repetition.lo == 0) {
local_printf("[ ( \",\" / ");
if (o->u.e.e.rule.rule) {
local_printf("%s", o->u.e.e.rule.rule->name);
o->u.e.e.rule.rule->used = 1;
} else {
local_printf("%s", o->u.e.e.rule.name);
}
local_printf(" ) *( OWS \",\" [ OWS ");
local_printf("%s", (o->u.e.e.rule.rule) ?
o->u.e.e.rule.rule->name :
o->u.e.e.rule.name);
local_printf(" ] ) ]");
} else if (o->u.e.repetition.lo == 1) {
local_printf(" *( \",\" OWS ) ");
if (o->u.e.e.rule.rule) {
local_printf("%s", o->u.e.e.rule.rule->name);
o->u.e.e.rule.rule->used = 1;
} else {
local_printf("%s", o->u.e.e.rule.name);
}
local_printf(" *( OWS \",\" [ OWS ");
local_printf("%s", (o->u.e.e.rule.rule) ?
o->u.e.e.rule.rule->name :
o->u.e.e.rule.name);
local_printf(" ] )");
}
else {
local_printf("TODO: something is wrong");
}
if (listrulex == 0) {
p_listrule_rfc7230(o);
} else {
p_listrule_2019(o);
}
} else {
printrep(&o->u.e.repetition);
if (o->u.e.e.rule.rule) {
Expand Down
4 changes: 2 additions & 2 deletions draft-ietf-httpbis-cache-latest.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions draft-ietf-httpbis-cache-latest.xml
Expand Up @@ -2199,8 +2199,8 @@
<section xmlns:x="http://purl.org/net/xml2rfc/ext" title="Collected ABNF" anchor="collected.abnf"><t>In the collected ABNF below, list rules are expanded as per <xref target="Semantics" x:rel="#abnf.extension"/>.</t><sourcecode type="abnf" name="draft-ietf-httpbis-cache-latest.parsed-abnf">
<x:ref>Age</x:ref> = delta-seconds

<x:ref>Cache-Control</x:ref> = *( "," OWS ) cache-directive *( OWS "," [ OWS
cache-directive ] )
<x:ref>Cache-Control</x:ref> = [ cache-directive ] *( OWS "," OWS [ cache-directive
] )

<x:ref>Expires</x:ref> = HTTP-date

Expand Down
10 changes: 5 additions & 5 deletions draft-ietf-httpbis-messaging-latest.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions draft-ietf-httpbis-messaging-latest.xml
Expand Up @@ -3007,8 +3007,8 @@ Upgrade: HTTP/2.0
<section xmlns:x="http://purl.org/net/xml2rfc/ext" title="Collected ABNF" anchor="collected.abnf"><t>In the collected ABNF below, list rules are expanded as per <xref target="Semantics" x:rel="#abnf.extension"/>.</t><sourcecode type="abnf" name="draft-ietf-httpbis-messaging-latest.parsed-abnf">
<x:ref>BWS</x:ref> = &lt;BWS, see <xref target="Semantics" x:fmt="," x:sec="4.3"/>&gt;

<x:ref>Connection</x:ref> = *( "," OWS ) connection-option *( OWS "," [ OWS
connection-option ] )
<x:ref>Connection</x:ref> = [ connection-option ] *( OWS "," OWS [ connection-option
] )

<x:ref>HTTP-message</x:ref> = start-line *( header-field CRLF ) CRLF [ message-body
]
Expand All @@ -3019,11 +3019,11 @@ Upgrade: HTTP/2.0

<x:ref>RWS</x:ref> = &lt;RWS, see <xref target="Semantics" x:fmt="," x:sec="4.3"/>&gt;

<x:ref>TE</x:ref> = [ ( "," / t-codings ) *( OWS "," [ OWS t-codings ] ) ]
<x:ref>Transfer-Encoding</x:ref> = *( "," OWS ) transfer-coding *( OWS "," [ OWS
<x:ref>TE</x:ref> = [ t-codings ] *( OWS "," OWS [ t-codings ] )
<x:ref>Transfer-Encoding</x:ref> = [ transfer-coding ] *( OWS "," OWS [
transfer-coding ] )

<x:ref>Upgrade</x:ref> = *( "," OWS ) protocol *( OWS "," [ OWS protocol ] )
<x:ref>Upgrade</x:ref> = [ protocol ] *( OWS "," OWS [ protocol ] )

<x:ref>absolute-URI</x:ref> = &lt;absolute-URI, see <xref target="RFC3986" x:fmt="," x:sec="4.3"/>&gt;
<x:ref>absolute-form</x:ref> = absolute-URI
Expand Down

0 comments on commit e475f36

Please sign in to comment.