Re: ABNF switch: list rules

Zed A. Shaw wrote:
> That's actually a common production in programming languages that have
> a ; to separate expressions.  They would always have a production that
> says something like "a program is a list of expressions separated by ;
> and a ; on its own is an empty expression".
> 
> The only thing is most parsers and lexers have a way to ignore
> whitespace during operation, so they wouldn't need to include the LWS.
> 
> Based on that, you could rewrite it like this to be a bit clearer and
> potentially reusable for other similar lists:
> 
> AC-QValue = ";" "q" "=" qvalue
> AC-Type = (charset | "*")
> AC-Expression = AC-Type AC-QValue?

AC-Expression = AC-Type [AC-QValue]

> AC-Element = *LWS [AC-Expression] [","]
> Accept-Charset = "Accept-Charset" ":" *(AC-Element)
> 
> Assuming I got the syntax right (didn't refresh my memory about ABNF),
> it's effectively saying:
> 
> "AC is 'Accept-Charset:' followed by any number of elements.  Elements
> have any amount of leading white-space, an optional expression, and an
> optional comma.  Expressions have a type and optional q-value."

Right, but RFC2616 requires that the list includes at least one 
none-empty element :-)

> You should then be able to sprinkle LWS production where they belong.

BR, Julian

Received on Saturday, 24 May 2008 08:15:32 UTC