speced / bikeshed

:bike: A preprocessor for anyone writing specifications that converts source files into actual specs.
https://speced.github.io/bikeshed
Creative Commons Zero v1.0 Universal
1.11k stars 200 forks source link

Better support for ABNF. #459

Open mikewest opened 9 years ago

mikewest commented 9 years ago

Right now, I'm marking up ABNF grammar as something like:

<pre dfn-type="grammar" link-type="grammar">
    <dfn>policy-token</dfn> = <a>directive-token</a> *( <a>OWS</a> ";" [ <a>OWS</a> <a>directive-token</a> ] )
    <dfn>directive-token</dfn> = <a>directive-name</a> [ <a>RWS</a> <a>directive-value</a> ]
    <dfn>directive-name</dfn> = 1*( <a>ALPHA</a> / <a>DIGIT</a> / "-" )
    <dfn>directive-value</dfn> = *( <a>WSP</a> / &lt;<a>VCHAR</a> except ";" and ","&gt; )
</pre>

I'd like to mark it up as the following, and have the <a> and <dfn>s added magically:

<pre class="abnf">
    policy-token = directive-token *( OWS ";" [ OWS directive-token ] )
    directive-token = directive-name [ RWS directive-value ]
    directive-name = 1*( ALPHA / DIGIT / "-" )
    directive-value = *( WSP / &lt;VCHAR except ";" and ","&gt; )
</pre>

This seems like it will be a lot of work (though I think we could get away with much less rigor than the WebIDL parser), so before I start poking at it in my copious free time, is it a patch you'd accept in the first place, @tabatkins?

tabatkins commented 9 years ago

It is absolutely a patch I'd accept.

The way to do it is in the datablocks.py file. Write a transformABNF() function, add it to the blockTypes dict at the top of transformDataBlocks with the class that should trigger it (abnf, looks like).

Please put the actual parser into a fresh file and just invoke it in datablocks, like transformRailroad and friends do.

mikewest commented 7 years ago

(It would also be nice to validate ABNF, if only so that @reschke won't be upset with me (https://lists.w3.org/Archives/Public/ietf-http-wg/2017AprJun/0216.html). :) )

tabatkins commented 7 years ago

Do you have a preferred abnf reference? I know the W3C maintains one.

reschke commented 7 years ago

There are different kinds of ABNF. @mikewest likely refers to https://www.greenbytes.de/tech/webdav/rfc5234.html (but beware, has optional extensions)

tabatkins commented 7 years ago

The W3C one I was referring to is https://www.w3.org/Notation.html, which is RFC 822 plus some changes and additions.

reschke commented 7 years ago

Well, when ABNF is used to define HTTP header fields, it's IMHO strictly better to use some version of IETF ABNF.