[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] Unable to resolve the ambiguity of a lens



Hi Lukas,

On Mon, 2009-12-07 at 01:16 +0100, Lukas Krejci wrote:
> using the lastest Augeas 0.6.0, I'm trying to develop a lens that would read 
> following format:
> 
> Command := command_name [separator parameter]*
> 
> where each command would be on a single line and placing a '\' as a last 
> character on the line would "escape" that newline and allow the command to 
> continue on the next line.
> 
> For that I wrote the following lens:
> 
> module Test =
> 
> let sep = del /([ \t]+(\\\\\n)?)+/ " "
> let eol = del /[ \t]*\n/ "\n"
> let word = /[^ \t\n]+/
> let alnum = /[a-zA-Z0-9_]+/
> 
> let command = [ del /[ \t]*/ "" . key alnum . [ sep . label "param" . store 
> word ]* . eol ]
> 
> let lns = command*
> 
> When I run "augparse -I . --nostdinc test.aug", the command rule is ambiguous 
> with the following message:
> 
> Syntax error in lens definition
> test.aug:10.0-.18:Failed to compile lns
> test.aug:10.10-.18:exception: ambiguous iteration
>       Iterated regexp: /([ \t]*)([a-zA-Z0-9_]+)(((([ \t]+(\\\\\n)?)+)([^ 
> \t\n]+))*)([ \t]*\n)/
>       'A \\\nA\n' can be split into
>       'A \\\n|=|A\n'
> 
>      and
>       'A \\\nA\n|=|'
> 
>     Iterated lens: test.aug:8.14-.91:
>  
> which I understand as that the parser cannot decide whether the second "A" 
> forms a new command or a new parameter of a previous command (alnum and word 
> regexes overlap).
> 
> Could you explain why is the parser not able to do that?

The second version of the parse, 'A \\\nA\n|=|' is what you had in mind:
a command_name and one parameter. The first version, 'A \\\n|=|A\n'
happens because 'A \\\n' can also be parsed as 'key alnum . sep . store
word . eol' since word matches '\\'.

The simplest way to avoid that is to exclude '\\' from word:
        let word = /[^ \t\n\\]+/ 
though I assume the correct solution is to remove trailing '\\' from
word:
        let word = /[^ \t\n]*[^ \t\n\\]/

David



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]