[augeas-devel] Inexpressible Language
Raphaël Pinson
raphael.pinson at camptocamp.com
Thu Jun 26 06:46:09 UTC 2014
Hello,
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.
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:
===========================
(* foo.aug *)
module Foo =
let eol = del /[ \t]*\n/ "\n"
let empty = [ del /[ \t]*\n/ "\n" ]
let comment =
let space_in = /[^[ \r\t\n].*[^ \r\t\n]|[^[ \t\n\r]/
in [ Util.indent . label "#comment" . store space_in . eol ]
let entry =
let value = [ seq "value" . Sep.colon . store /[^]:]+/ ]
in [ Util.indent . Util.del_str "["
. key /[A-Z_]+/ . counter "value" . value+
. Util.del_str "]" . (comment|eol) ]
let lns = (empty|comment|entry)*
let conf = "Change this to turn sound off.
[SOUND:YES]
[FONT:curses_640x300.png]
[RESIZABLE:YES]You may disable window resizing if you wish.
[PRINT_MODE:2D]
Mode examples:
[SINGLE_BUFFER:NO]
[EMBARK_RECTANGLE:4:4]
Change these numbers to set the default weights for traffic designations.
If you make the last numbers too large, pathfinding might lag.
The format is (PATH_COST:<high>:<normal>:<low>:<restricted>).
[PATH_COST:1:2:5:25]\n"
test lns get conf = ?
=====================================
$ augparse foo.aug
Test result: foo.aug:35.0-.21:
{ "#comment" = "Change this to turn sound off." }
{ }
{ "SOUND"
{ "1" = "YES" }
}
{ "FONT"
{ "1" = "curses_640x300.png" }
}
{ "RESIZABLE"
{ "1" = "YES" }
{ "#comment" = "You may disable window resizing if you wish." }
}
{ }
{ "PRINT_MODE"
{ "1" = "2D" }
}
{ "#comment" = "Mode examples:" }
{ "SINGLE_BUFFER"
{ "1" = "NO" }
}
{ "EMBARK_RECTANGLE"
{ "1" = "4" }
{ "2" = "4" }
}
{ }
{ "#comment" = "Change these numbers to set the default weights for
traffic designations. If you make the last numbers too large, pathfinding
might lag." }
{ "#comment" = "The format is
(PATH_COST:<high>:<normal>:<low>:<restricted>)." }
{ "PATH_COST"
{ "1" = "1" }
{ "2" = "2" }
{ "3" = "5" }
{ "4" = "25" }
}
Regards,
[0] https://github.com/hercules-team/augeas/issues
On Thu, Jun 26, 2014 at 6:50 AM, Yclept Nemo <orbisvicis at gmail.com> wrote:
> 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):
>
> let br_l = del /\[/ "["
> let br_r = del /\]/ "]"
> let ws = del /[ \t]*/ ""
> let sep = del /:/ ":"
> let comment = del /.*/ ""
> let eol = del /\n/ "\n"
> let option = key /[A-Z]+/
> let value = sep . ws . store /[[:alnum:]]/ . ws
> let values = [ seq "value" . value ] +
> let setting = [ br_l . option . values . br_r ]
> let record = setting . comment
> let lns = ( record | comment ) . eol
> (*
> let lns = ( setting?. comment . eol )
> *)
>
> 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:
>
> let lns = del ( /[[]/ "[" ) . P1 | del ( /[^[]/ ) . NP
> let P1 = key ( /[A-Z]+/ ) . P2 | del ( /[^A-Z]/ ) . NP
> let P2 = del ( /[:]/ ":" ) . P3 | del ( /[^:]/ "" ) . NP
> let P3 = del ( /[ \t]*/ "" ) . P4
> let P4 = store /[[:alnum:]]+/ . P5 | del ( /[^[:alnum:]]/ "" ) .
> NP
> let P5 = del ( /[ \t]*/ "" ) . P2
> let NP = del ( /[^\n]*/ . /\n/ ) ""
>
> 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:
>
>
> let lns = del ( /[[]/ "[" ) . P1 | del ( /[^[]/ ) . NP
> let P1 = key ( /[A-Z]+/ ) . P2 | del ( /[^A-Z]/ ) . NP
> let P2 = del ( /[:]/ ":" ) . P3 | del ( /[^:]/ "" ) . NP
> let P3 = del ( /[ \t]*/ "" ) . P4
> let P4 = store /[[:alnum:]]+/ . P5 | del ( /[^[:alnum:]]/ "" ) .
> NP
> let P5 = del ( /[ \t]*/ "" ) . P6
> let P6 = del ( /[:]/ ":" ) . P3 | del ( /[]]/ "]" END | [^]:] NP
> let END = [^\n]* \n
> let P7 = <big problem> END
>
>
> 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.
>
> 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.
>
> However, the operators proposed in [2] ("||", "..", "**") and my addition,
> "??" would nicely solve this dilemma.
>
> Sincerely,
>
>
>
>
> [1] "
> Change this to turn sound off.
>
> [SOUND:YES]
> [FONT:curses_640x300.png]
> [RESIZABLE:YES]You may disable window resizing if you wish.
>
> [PRINT_MODE:2D]
> Mode examples:
> [SINGLE_BUFFER:NO]
> [EMBARK_RECTANGLE:4:4]
>
> Change these numbers to set the default weights for traffic designations.
> If you make the last numbers too large, pathfinding might lag.
> The format is (PATH_COST:<high>:<normal>:<low>:<restricted>).
> [PATH_COST:1:2:5:25]
> "
>
> [2]
> http://www.redhat.com/archives/augeas-devel/2010-September/msg00027.html
>
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel
>
--
Raphaël Pinson
Infrastructure Developer & Trainer
+33 479 26 57 93
+33 781 90 00 79
Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20140626/4cd9c761/attachment.htm>
More information about the augeas-devel
mailing list