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

Re: [augeas-devel] NASL lens entry



Hello,

Le 9 janv. 2014 22:51, "Tim Brigham" <timbrigham gmail com> a écrit :
>
> I wanted to ask about how I'm handling one point in writing the lens for parsing my NASL files. 
>
> I'm using two cases for my end of line, those that end with a semicolon only and those that end with a closing parenthesis. e.g.
>
> let cparen      = del /\)/ ")"

This is actually Util.del_str ")"

> let semic       = Util.del_str ";"
> let dquote      = Util.del_str "\""

It is better now to rely on the Quote module for safe/ automatic quote management.

> let comma       = del /,/ ","
> let colon       = del /:[ \t]*/ ": "
> let eol         = del /[ \t]*\n/ "\n"

It's good practice tous Util.eol here

> let del_opt_ws = del /[ \t]*/ ""
> let equal       = del /[ \t]*=[ \t]*/ "="

this is Sep.space_equal

> let oparen      = del /\(/ "("
>
> let cparen_entry (kw:string) = [ del_opt_ws .  key kw . oparen . value_to_cparen . cparen . semic . eol   ]

From your example below, it seems like you'd rather want a value_to_dquote.

> let semic_entry (kw:string) = [  del_opt_ws . key kw  . equal .  value_to_semic .  semic . eol ]
>
> This works perfectly until I run into something where I have an embedded closing parenthesis in a given line, e.g
>
>
>  script_copyright("This script is Copyright (C) 2004 Michel Arboi");
>
>
> My thought is something like this should work to generalize it but I'm not sure how to define value_to_something. 
>
> let refined_entry (kw:string) = [ del_opt_ws . key kw . ( oparen | equal ) . value_to_something . cparen{0,1} . semic . eol  ]
>
> The (oparen|equal) comes back with 
> exception: overlapping lenses in tree union.put
>     Example matched by both:
>     First lens: lens/nasl.aug:24.14-.26:
>     Second lens: lens/nasl.aug:23.13-.36:

see my comment above on value_to_dquote. Again, the Quote module can help you here.

cheers,

Raphaël


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