[augeas-devel] [PATCH] Generic square lens

Francis Giraldeau francis.giraldeau at gmail.com
Wed Aug 8 23:18:50 UTC 2012


Le 2012-08-07 23:16, David Lutterkort a écrit :
> On Mon, 2012-08-06 at 21:42 +0200, Francis Giraldeau wrote:
>> Lens square now takes lenses instead of regular expressions as arguments, as follow:
>>
>>   square left body right
> 
> This is very cool. If it does indeed let us put all those quote problems
> to rest, it's a huge step forward.
> 
> I get these errors when I try to build with this patch:
> 
> lens.c:403:14: error: no previous prototype for 'lns_copy_prim' [-Werror=missing-prototypes]
> lens.c: In function 'lns_make_square':
> lens.c:426:19: error: unused variable 'val' [-Werror=unused-variable]
> 
> I suspect you don't have --enable-compile-warnings=error turned on; have
> a look at the autogen target in Makefile.maint for how you should set up
> your environment. The attached patch fixes the trivial issues; just fold
> into yours.
> 
>> diff --git a/src/get.c b/src/get.c
>> index c1e206c..b8e5195 100644
>> --- a/src/get.c
>> +++ b/src/get.c
>> @@ -50,7 +50,8 @@ struct state {
>>      struct seq       *seqs;
>>      char             *key;
>>      char             *value;     /* GET_STORE leaves a value here */
>> -    char             *square;    /* last L_DEL from L_SQUARE */
>> +    char             *square_left;
>> +    char             *square_right;
> 
> Do we really need to store that in the state ? Wouldn't it be possible
> to figure out square_left and square_right in get_square by looking at
> the match for the first and last child of the square lens ?

No, we can use regs instead. I do have a prototype of this, but it only
works in the case of regular lenses. Recursive lens must be handle
separately.

I tried to build some kind of abstract syntax tree after the parse. The
node (may) looks like this:

struct ast {
    struct ast         *parent;
    struct ast        **children;
    uint                nchildren;
    uint                capacity;
    uint                start;
    uint                end;
};

Then, for each node in the tree, the start and end indexes that the lens
matches will be recorded. To get the token for square left at visit_exit
time of the square lens will be easy:

struct ast *ast_of_concat = ast->children[0];
struct ast *ast_left = ast_of_concat->children[0];
struct ast *ast_right = ast_of_concat->children[ast_of_concat->nchildren
-1];

To reduce memory usage, we can build the ast only for the square
subtree, since it is not used elsewhere.

Cheers,

Francis

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4489 bytes
Desc: Signature cryptographique S/MIME
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20120809/53457657/attachment.p7s>


More information about the augeas-devel mailing list