[augeas-devel] Inexpressible Language

Raphaël Pinson raphael.pinson at camptocamp.com
Thu Jun 26 17:38:10 UTC 2014


I see. How about:

=============================
(* foo.aug *)
module Foo =

let eol = del /[ \t]*\n/ "\n"

let empty = [ del /[ \t]*\n/ "\n" ]

let comment =
     let entry_rx = /\[[A-Z_]+:[ \t]*[^]\n \t]+\].*/
  in let space_in = /[^ \r\t\n].*[^ \r\t\n]|[^ \t\n\r]/
  in [ Util.indent . label "#comment" . store (space_in - entry_rx) . eol ]

let entry =
   let value = [ seq "value" . Sep.colon . store /[^] \t\n:]+/ ]
   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][SOME_COMMENT: ]

[A_COMMENT:]\n"

test lns get conf = ?
=============================
Test result: foo.aug:38.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" }
    { "#comment" = "[SOME_COMMENT: ]" }
  }
  {  }
  { "#comment" = "[A_COMMENT:]" }
=============================



On Thu, Jun 26, 2014 at 5:59 PM, Yclept Nemo <orbisvicis at gmail.com> wrote:

> On Thu, Jun 26, 2014 at 2:46 AM, Raphaël Pinson <
> raphael.pinson at camptocamp.com> wrote:
>
>> 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:
>>
>
> Hi,
>
> You're right - there are additional restrictions which I failed to
> demonstrate in the unit test, though I expressed them in the lenses (which
> compared from you examples had other shortcomings, ie not resetting the
> counter).
>
> let comments="
> [A_COMMENT:   ] <-- this is a comment
> [NOT_A_COMMENT: 5 : 6 ][A_COMMENT:  ] <--- only the last [] is a comment
> "
>
> Since this is my first lens (just started using Augeas) I was seeking
> confirmation that this particular grammar is very difficult to express in
> Augeas, and if so hoping to prompt further development by some suggestions.
> I had just opened a github issue (#138, [1]) after posting this thread,
> with alternative solutions in addition to the original proposal of greedy
> operators.
>
> For the record, I believe this is a common problem parsers face,
> (dangling-else, [2]), something parsing expression grammars [3] do not
> suffer, which can be solved, among other strategies, by "maximal munch"
> (greedy) [4].
>
>
>
> [1] https://github.com/hercules-team/augeas/issues/138
>
> [2] http://en.wikipedia.org/wiki/Ambiguous_grammar#Dangling_else
> [3]
> http://stackoverflow.com/questions/1044600/difference-between-an-ll-and-recursive-descent-parser
> [4] http://en.wikipedia.org/wiki/Maximal_munch
>
>


-- 
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/612465ed/attachment.htm>


More information about the augeas-devel mailing list