<div dir="ltr">Hello,<div><br></div><div><br></div><div>I'm not sure if you're reporting a bug (in which case it would help to file it on the bugtracker [0]) or asking for help. I'll suppose the latter.</div><div>
<br></div><div>Here is a lens that parses your example. I suppose there must still be an issue (which is linked to the restrictions I had to put in the comment regexp —no "[" allowed as first character— but your example doesn't expose it then:</div>
<div><br></div><div><br></div><div>===========================</div><div>(* foo.aug *)</div><div><div>module Foo =</div><div><br></div><div>let eol = del /[ \t]*\n/ "\n"</div><div><br></div><div>let empty = [ del /[ \t]*\n/ "\n" ]</div>
<div><br></div><div>let comment =</div><div>  let space_in = /[^[ \r\t\n].*[^ \r\t\n]|[^[ \t\n\r]/</div><div>  in [ Util.indent . label "#comment" . store space_in . eol ]</div><div><br></div><div>let entry =</div>
<div>   let value = [ seq "value" . Sep.colon . store /[^]:]+/ ]</div><div>   in [ Util.indent . Util.del_str "["</div><div>      . key /[A-Z_]+/ . counter "value" . value+</div><div>      . Util.del_str "]" . (comment|eol) ]</div>
<div><br></div><div>let lns = (empty|comment|entry)*</div><div><br></div><div><br></div><div>let conf = "Change this to turn sound off.</div><div><br></div><div>[SOUND:YES]</div><div>[FONT:curses_640x300.png]</div><div>
[RESIZABLE:YES]You may disable window resizing if you wish.</div><div><br></div><div>[PRINT_MODE:2D]</div><div>    Mode examples:</div><div>[SINGLE_BUFFER:NO]</div><div>[EMBARK_RECTANGLE:4:4]</div><div><br></div><div>Change these numbers to set the default weights for traffic designations.  If you make the last numbers too large, pathfinding might lag.</div>
<div>The format is (PATH_COST:<high>:<normal>:<low>:<restricted>).</div><div>[PATH_COST:1:2:5:25]\n"</div><div><br></div><div>test lns get conf = ?</div></div><div>=====================================</div>
<div>$ augparse foo.aug</div><div><div>Test result: foo.aug:35.0-.21:</div><div>  { "#comment" = "Change this to turn sound off." }</div><div>  {  }</div><div>  { "SOUND"</div><div>    { "1" = "YES" }</div>
<div>  }</div><div>  { "FONT"</div><div>    { "1" = "curses_640x300.png" }</div><div>  }</div><div>  { "RESIZABLE"</div><div>    { "1" = "YES" }</div><div>    { "#comment" = "You may disable window resizing if you wish." }</div>
<div>  }</div><div>  {  }</div><div>  { "PRINT_MODE"</div><div>    { "1" = "2D" }</div><div>  }</div><div>  { "#comment" = "Mode examples:" }</div><div>  { "SINGLE_BUFFER"</div>
<div>    { "1" = "NO" }</div><div>  }</div><div>  { "EMBARK_RECTANGLE"</div><div>    { "1" = "4" }</div><div>    { "2" = "4" }</div><div>  }</div><div>
  {  }</div><div>  { "#comment" = "Change these numbers to set the default weights for traffic designations.  If you make the last numbers too large, pathfinding might lag." }</div><div>  { "#comment" = "The format is (PATH_COST:<high>:<normal>:<low>:<restricted>)." }</div>
<div>  { "PATH_COST"</div><div>    { "1" = "1" }</div><div>    { "2" = "2" }</div><div>    { "3" = "5" }</div><div>    { "4" = "25" }</div>
<div>  }</div></div><div><br></div><div><br></div><div><br></div><div>Regards,</div><div><br></div><div>[0] <a href="https://github.com/hercules-team/augeas/issues">https://github.com/hercules-team/augeas/issues</a></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 26, 2014 at 6:50 AM, Yclept Nemo <span dir="ltr"><<a href="mailto:orbisvicis@gmail.com" target="_blank">orbisvicis@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>The following language ([1], example), as far as I can tell, is unable to be meaningfully represented within Augeas (pardon the possibly horrendous syntax, as I'm new to Augeaus):<br>
</div><div>
<br>    let br_l        = del /\[/ "["<br>    let br_r        = del /\]/ "]"<br>    let ws          = del /[ \t]*/ ""<br>    let sep         = del /:/ ":"<br>    let comment     = del /.*/ ""<br>

    let eol         = del /\n/ "\n"<br>    let option      = key /[A-Z]+/<br>    let value       = sep . ws . store /[[:alnum:]]/ . ws<br>    let values      = [ seq "value" . value ] +<br>    let setting     = [ br_l . option . values . br_r ]<br>

    let record      = setting . comment<br>    let lns         = ( record | comment ) . eol<br>    (*<br>    let lns         = ( setting?. comment . eol )<br>    *)<br><br></div>I posted an ambiguous grammar first because it is easier to comprehend - always use the leftmost rule/union of lns to generate the tree and backtrack if necessary. The following is an unambiguous grammar of the same language which is useless to Augeas:<br>

<br>    let lns     = del ( /[[]/ "[" ) . P1 | del ( /[^[]/ ) .  NP<br>    let P1      = key ( /[A-Z]+/ ) . P2 | del ( /[^A-Z]/ ) . NP<br>    let P2      = del ( /[:]/ ":" ) . P3 | del ( /[^:]/ "" ) . NP<br>

    let P3      = del ( /[ \t]*/ "" ) . P4<br>    let P4      = store /[[:alnum:]]+/ . P5 | del ( /[^[:alnum:]]/ "" ) . NP<br>    let P5      = del ( /[ \t]*/ "" ) . P2<br>    let NP      = del ( /[^\n]*/ . /\n/ ) ""<br>

<br></div><div>The shortcoming is the second rule of P2. While a valid tree, as a parser it is unable to differentiate and recall a valid closing brace from junk. The following grammar solves this:<br><br><br>    let lns     = del ( /[[]/ "[" ) . P1 | del ( /[^[]/ ) .  NP<br>

    let P1      = key ( /[A-Z]+/ ) . P2 | del ( /[^A-Z]/ ) . NP<br>    let P2      = del ( /[:]/ ":" ) . P3 | del ( /[^:]/ "" ) . NP<br>    let P3      = del ( /[ \t]*/ "" ) . P4<br>    let P4      = store /[[:alnum:]]+/ . P5 | del ( /[^[:alnum:]]/ "" ) . NP<br>

</div><div>    let P5      = del ( /[ \t]*/ "" ) . P6<br></div><div>    let P6      = del ( /[:]/ ":" ) . P3 | del ( /[]]/ "]" END | [^]:] NP<br></div><div>    let END      = [^\n]* \n<br></div>

<div>    let P7      = <big problem> END<br><br><br></div><div>Since the previous two grammars no longer backtrack, augeas will generate invalid key/value nodes, remembered values, and subtrees. The idea is to have these deleted in P7, which is clearly not possible. Furthermore since the language implemented by Augeas is relatively pure, it isn't possible to imperatively set flags in rules P1-P6 and generate all the necessary keys, values and subtrees in END. I've also experimented with the regex_match and lens_ctype builtin functions, and the regex subtraction operator (which is unintuitive) to no avail.<br>

</div><div><br></div><div>In other words, there is no meaningful or worthwhile expression of this configuration syntax in Augeas schema - at least not without repeating the patterns/regexes at least three(!) times, which is a maintainer's nightmare.<br>

<br></div><div>However, the operators proposed in [2] ("||", "..", "**") and my addition, "??" would nicely solve this dilemma.<br></div><div><br></div><div>Sincerely,<br></div><div>

<div><br><br><br><br>[1] "<br>Change this to turn sound off.<br><br>[SOUND:YES]<br>[FONT:curses_640x300.png]<br>[RESIZABLE:YES]You may disable window resizing if you wish.<br><br>[PRINT_MODE:2D]<br>    Mode examples:<br>

[SINGLE_BUFFER:NO]<br>[EMBARK_RECTANGLE:4:4]<br><br>Change these numbers to set the default weights for traffic designations.  If you make the last numbers too large, pathfinding might lag.<br>The format is (PATH_COST:<high>:<normal>:<low>:<restricted>).<br>

[PATH_COST:1:2:5:25]<br>"<br><br>[2] <a href="http://www.redhat.com/archives/augeas-devel/2010-September/msg00027.html" target="_blank">http://www.redhat.com/archives/augeas-devel/2010-September/msg00027.html</a><br>
</div></div></div>
<br>_______________________________________________<br>
augeas-devel mailing list<br>
<a href="mailto:augeas-devel@redhat.com">augeas-devel@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/augeas-devel" target="_blank">https://www.redhat.com/mailman/listinfo/augeas-devel</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Raphaël Pinson<div>
Infrastructure Developer & Trainer</div><div>+33 479 26 57 93<div>+33 781 90 00 79</div><div><br></div><div>Camptocamp France<br>
Savoie Technolac<br>
BP 352<br>
48, avenue du Lac du Bourget<br>
73372 Le Bourget du Lac, Cedex<br>
<a href="http://www.camptocamp.com" target="_blank">www.camptocamp.com</a><br>
</div></div></div>
</div>