[augeas-devel] Robust lens parsing
David Lutterkort
lutter at redhat.com
Tue Jun 28 14:26:24 UTC 2011
On Mon, 2011-06-27 at 16:43 +0100, Matthew Booth wrote:
> The above could be parsed as:
>
> * terminal
> * #error = -timeout=5
> * serial
> * console
> * default = 0
> * #error = frobnicate --foobaz
> * hiddenmenu
>
> This is, of course, dependent on implementing this behaviour in each
> lens. The advantage of this is that arbitrary errors which don't cause
> failure can be ignored if desired, or highlighted otherwise.
> Specifically for virt-v2v, a misconfigured grub serial console won't
> prevent me from working out which kernel is supposed to be booted.
Yes, I absolutely agree that doing more than just throwing your hands up
in the air and saying "there's something wrong with this file" is
desirable.
I don't see a good way to do this automatically though; error recovery
in parsers is a thorny subject that I know very little about. The basic
issue is that creating the #error nodes has to happen in a way that
makes the typechecker happy. In particular, there are two ways in which
lenses are combined: union (l1|l2) and concatenation (l1 . l2)
To do error recovery automatically, we'd introduce a new lens combinator
'error: LENS -> LENS'; the semantics are that 'error l' produces a new
lens that behaves like l wherever l matches and like '[ label "#error" .
store some_re ]' whenever it does not match. As a consequence, 'error l'
is a lens that matches everything - and that makes it impossible to form
unions (error l1 | error l2) and concatenations (error l1 . error l2)
since these lenses won't typecheck.
That really only leaves some sort of manual intervention; that can
become quite tedious. But I'd love to be proven wrong ;)
David
More information about the augeas-devel
mailing list