Re: [abnf-discuss] constrained-01 - advantage?

Julian Reschke <julian.reschke@gmx.de> Mon, 14 November 2016 03:39 UTC

Return-Path: <julian.reschke@gmx.de>
X-Original-To: abnf-discuss@ietfa.amsl.com
Delivered-To: abnf-discuss@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 7D222129594 for <abnf-discuss@ietfa.amsl.com>; Sun, 13 Nov 2016 19:39:53 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.601
X-Spam-Level:
X-Spam-Status: No, score=-2.601 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 38mOrNu8Wg8w for <abnf-discuss@ietfa.amsl.com>; Sun, 13 Nov 2016 19:39:48 -0800 (PST)
Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 5665C129565 for <abnf-discuss@ietf.org>; Sun, 13 Nov 2016 19:39:47 -0800 (PST)
Received: from [31.133.147.187] ([31.133.147.187]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0MT60g-1cGcTp3A9e-00S7cD; Mon, 14 Nov 2016 04:39:36 +0100
To: Sean Leonard <dev+ietf@seantek.com>, Doug Royer <douglasroyer@gmail.com>
References: <5828DD42.8010009@gmail.com> <36FC0A35-2ADA-4710-ABFB-08E8B916718E@seantek.com>
From: Julian Reschke <julian.reschke@gmx.de>
Message-ID: <a5d764a8-c560-bed3-095f-f1a1a5e35688@gmx.de>
Date: Mon, 14 Nov 2016 04:39:32 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0
MIME-Version: 1.0
In-Reply-To: <36FC0A35-2ADA-4710-ABFB-08E8B916718E@seantek.com>
Content-Type: text/plain; charset="utf-8"; format="flowed"
Content-Transfer-Encoding: 8bit
X-Provags-ID: V03:K0:NvVVH/892beL9EybGqtKQqYIFjz5bCOfIRJFBJZAY2i0RQehrtn DCJbsItWs+DV5QL8B+Jx9yj9oN2a3luw3ooIrR6Liyfn1T3pkahtEaM4eZ9udFVc3XluQbd OI8WvkjDlkI2qkDB76G3CeblBTqiAnxO12OfA2jaPr7FJgJzH5iV93Z8bhPTJAqXx5sKvB+ 8naOMK+M+9weVwqfQmDnA==
X-UI-Out-Filterresults: notjunk:1;V01:K0:95nOWXz+F0Y=:FP8fUASBYvIB7XuFaEOXW1 TP/WrkoFKubs+TUlSaMvvte6TtwB6GhidFdMOyuq+fKDOzarBsRwuafl8P9cL2vLX+7PftoQb l/UBJRV5d7cXj13mQPLuhetQYoyJV8TVMNL6+r245ZtsFYyIM6KzF4PaFQtGjpA76U9+85ExG 90D+1JExDGn8vYNBtFsz7pRqM1x/Fx5uy5XttU9T/4E5smN+Z8wQ8z+1S3IJjEgGk1snHn5M0 Uq8i1xFda/HbW7lRgmj8Cnl8oq5S/reAE0eT7fDqOkfmj47QsZJ0HbnbAFi0L0moWIpt8R63V dL6nSN8klgZBbNcnOQAm1AB7S8HTwzgQ0YLrd1irZB60jn4rtSDk4Kw7QULsIal24KJSCdrZS broGWkpw0nD68rOZacpEdp8HJjhNFz7pBK9PS0fV6xAUxft776sX7d3NTTpEsHp2CIWQVEp36 dy3224Z1FeasuOSdWLsNYiosU2Mk3pFoYbCfer0imc2LY6rng3m9ZRR3qkaZ/kl030oqj9I0l QTHyIQqqjBYc8jeTU50DWPWllbNNnDPR5xIXAjuaGn4NuYxGqcgkzH5FLNlS3dM/Bb90CeIJQ CV2typTVcD1HC+O3WK65q5ux5QGlrBF9tg1jYw7uYHZWo+Gdalh+PweD3CqBWr/e1KgnRqt4r 0KJVSaGSRNQ+0OGp4yxA6HyNTFl2A8EB8+3zw8Li57m/i7DR4ZKvIhCLokQH1fm+GoMWtFI6R 4BcrQEKqpwdsmFrhRKWw74BTvo3Qy6LgO6enFPWh7mQkRqDvCuXrTkW7X4HHrXv3zqCOgYSwE 6q15I8+
Archived-At: <https://mailarchive.ietf.org/arch/msg/abnf-discuss/mBodFBae_AujkWnh8mumPpILaVM>
Cc: abnf-discuss@ietf.org
Subject: Re: [abnf-discuss] constrained-01 - advantage?
X-BeenThere: abnf-discuss@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: "General discussion about tools, activities and capabilities involving the ABNF meta-language" <abnf-discuss.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/abnf-discuss>, <mailto:abnf-discuss-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/abnf-discuss/>
List-Post: <mailto:abnf-discuss@ietf.org>
List-Help: <mailto:abnf-discuss-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/abnf-discuss>, <mailto:abnf-discuss-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 14 Nov 2016 03:39:53 -0000

On 2016-11-14 00:21, Sean Leonard wrote:
> ...
> Well:
>
>> resent-field    = "Resent-" field-name ":" unstructured CRLF
>
>
> Is simpler than:
>
>> resent-field  = resent-unstructured / resent-date / resent-from / resent-sender / ...
>
>
> First of all, it looks simpler, because it is.
>
> Second of all, <resent-date>, <resent-from>, <resent-sender> etc. are all “subsumed” in <resent-unstructured>, leading to an intentionally ambiguous grammar. The problem with the existing way of writing things out, is that the former are all superfluous when the latter is present. Another way to write it tends to be:
>
>  field = date / from / sender / … / extension-field
>
>  extension-field = field-name ":" unstructured CRLF
>
> Well it makes perfect sense when you read it, of course, but when a computer / parser parses productions, every <date> is going to match with <extension-field> as well. The point being <extension-field> is not really doing what you think it’s doing in ABNF: it’s really <any-and-every-field>.
>
> There is nothing “wrong” with creating an ambiguous grammar, but it can lead to subtle parsing errors if you are not careful. Usually ambiguous grammars are undesirable because you want your code to go down one, and only one, path. An automated ABNF validator should be able to detect ambiguous grammars and inform you about that.
>
>
> When you actually go to program what the ABNF represents, most people are not going to program:
>
> if (chars[0] = ‘d’ && chars[1] = ‘a’ & chars[2] = ’t’ & chars[3] = ‘e’ & chars[4] = ‘:’) {
>   // parse as date
> } else if (chars[0] = ‘f’ …) {
>   // parse as from
> } else if (…) {
>   // ...
> } else {
>   field-name = everything before ‘:’;
>   unstructured = everything between ‘:’ and CRLF;
> }
> ...

If this is the only use case (is it?), then I'd say that you're dealing 
with a problem you could avoid in the first place.

See how RFC 7230 distinguishes between parsing the HTTP message info 
fields and field values, and then has completely *separate* ABNFs for 
each field value.

Best regards, Julian