From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] keyval: accept escaped commas in implied option
Date: Fri, 27 Nov 2020 15:39:43 +0100 [thread overview]
Message-ID: <87360urhhs.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <0a15b86b-9ab8-d378-7578-a8304b32870a@redhat.com> (Paolo Bonzini's message of "Fri, 27 Nov 2020 10:15:57 +0100")
Paolo Bonzini <pbonzini@redhat.com> writes:
> [huge snip]
>
> On 27/11/20 09:38, Markus Armbruster wrote:
>> The suboptimal error message is due to the way I coded the parser, not
>> due to the grammar.
>
> Small digression: a different grammar influences how the parser is
> written. You coded the parser like this because you thought of implied
> options as "key without ="; instead I thought of them as "value not
> preceded by key=".
Which requires relaxing the key syntax, as you did. Without that, we'd
need unbounded lookahead to decide how to reduce a comma.
>>
>> --nbd key=val,=,fob=
>>
>> master: Invalid parameter ''
>> your patch: Expected parameter before '='
>>
>> Improvement, but which '='? Possibly better:
>>
>> Expected parameter before '=,fob='
>
> Yup, easy.
>
>> --nbd .key=
>>
>> master: Invalid parameter '..key'
>> your patch: same
>>
>> Better, I think:
>>
>> Name expected before '..key'
>>
>> Odd: if I omit the '=', your patch's message often changes to
>>
>> Expected '=' after parameter ...
>>
>> This means the parser reports a non-first syntax error. Parsing
>> smell, I'm afraid :)
>
> Nah, just lazy cut-and-paste of the existing error message. I should
> rename that error to something "No implicit parameter name for '.key'"
> (again, different grammar -> different parser -> different error). That
> error message actually makes sense: "--object .key" would create an
> object of type ".key" both without or with these changes.
However, --object a=b,.key would not, because the sugar is available
for the leftmost value only.
"No implicit parameter name" assumes the user intended .key as a value,
and forgot to write the key. We could instead assume the user intended
.key as key, and messed it up (forgot a fragment, fat-fingered '.',
whatever). The absence of '=' makes the value assumption more
plausible, but that's already lookahead.
Error messages based on guesses what the user has in mind can be quite
confusing when we guess wrong. A strictly factual syntax error style
like "I expected FOO instead of BAR here" may not be great, but has a
relatively low risk of being confusing.
>> * Invalid key fragment
>>
>> --nbd key.1a.b=
>>
>> master: Invalid parameter 'key.1a.b'
>> your patch: same
>>
>> Slightly better, I think:
>>
>> 'key.1a' is not a valid parameter name
>
> Or just "Invalid parameter '1a'". I'm not going to do that in v2
> though, since parameter parsing is not being
Sentence not being finished?
>> I believe there are two, maybe three reasons for this series:
>>
>> 1. Support ',' in values with an implicit keys.
>>
>> 2. Improve error reporting.
>>
>> 3. Maybe nicer code.
>>
>> 1. is a feature without a known use.
>
> Breaking news: there is actually a use. I should have pointed out in
> the commit message, but I didn't realize at the time, that this patch
> fixes device-introspect-test once device_add is switched to keyval-based
> parsing. And why is that? Because even though SUNW,fdtwo is not
> user-creatable, you can still do "device_add SUNW,,fdtwo,help". It even
> works from the command line:
>
> $ qemu-system-sparc -device SUNW,,fdtwo,help
> SUNW,fdtwo options:
> drive=<str> - Node name or ID of a block device to use as
> a backend
> fallback=<FdcDriveType> - FDC drive type, 144/288/120/none/auto
> (default: "144")
> ...
Right. I actually had that knowledge filed in my brain, but it failed
to bubble up.
It fixes device-introspect-test only because you also fixed the test to
escape comma (commit e27bd498769, in rc1). Quoting myself: "Parameter
values with comma need special treatment before and after the patch."
> This invocation is useful (for some value of useful) to see which
> properties you can pass with -global. So there *is* a valid (for some
> value of valid) use of escaped commas in implied options. It can be
> fixed with deprecation etc. but that would be a more complicated
> endeavor than just adjusting keyval.
The question becomes whether CLI help syntax is subject to the
compatibility promise.
It's certainly not something we'd want programs to use. We provide QMP
commands for the purpose.
For human users, the usability goodness of keeping
-device SUNW,,fdtwo,help
working would in my opinion be dwarved several times over by renaming
the the offenders so that you don't need arcane knowledge "double the
comma" just to get help. We should do that regardless of this patch.
>> 2. can be had with much less churn
>> (I'm ready to back that up with a patch). Since I haven't looked at
>> PATCH 2, I'm reserving judgement on 3.
>
> FWIW I think this patch is already an improvement in code niceness,
> though I accept that it's in the eye of the beholder.
>
> Paolo
next prev parent reply other threads:[~2020-11-27 14:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-11 10:45 [PATCH 0/2] keyval: accept escaped commas in implied option Paolo Bonzini
2020-11-11 10:45 ` [PATCH 1/2] " Paolo Bonzini
2020-11-11 10:53 ` Daniel P. Berrangé
2020-11-11 11:05 ` Paolo Bonzini
2020-11-11 11:14 ` Mark Cave-Ayland
2020-11-27 8:38 ` Markus Armbruster
2020-11-27 9:15 ` Paolo Bonzini
2020-11-27 14:39 ` Markus Armbruster [this message]
2020-11-27 15:39 ` Paolo Bonzini
2020-11-11 10:45 ` [PATCH 2/2] keyval: simplify keyval_parse_one Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87360urhhs.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.