[augeas-devel] Having trouble differentiating quoted vs unquoted string

David Lutterkort lutter at redhat.com
Wed Aug 19 15:43:40 UTC 2009


On Fri, 2009-08-14 at 18:18 +1000, Matthew Palmer wrote:
> > That's again the issue that Augeas only looks at labels, not values in
> > the tree -> file direction;
> 
> It seems that if you say this often enough, eventually it'll sink in -- for
> some reason, every time you've said this in the past I've read it as "looks
> at values" and assumed that it'll match how I "think" it'll match (based on
> the value).  Sorry 'bout that.
> 
> Now that things are clearer in my head, I realise I'm far, far more screwed
> than I previously realised.  I *have* to be able to distinguish between
> quoted and unquoted strings, because the list of what "terminates" the
> string is different if it's an unquoted string (comma, whitespace) or a
> quoted string (quotes).
> 
> Any suggestions on how to proceed?  Right at the moment, I'm not even sure
> how to parse a comma-separated list of options without making a mess of it. 

Incidentally, I got the attached tests to work last night, though the
patches still have bugs (i.e. the strip-quotes test passes, but some of
the existing tests fail). Hopefully I'll get that fixed in the next few
days.

With those patches, Augeas looks at both the labels and values of tree
nodes in the tree -> file direction.

> I guess I should go back to looking at how to do case-insensitive regexes
> (damn my flex/bison skills are rusty).

The flex/bison part is the easy bit. The harder bits are (1) invent a
syntax in the language for case-insensitive regexps ( /nocase/i seems
like an obvious choice, but also ugly as hell),(2) add a flag to struct
regexp and setting that from the parser (3) pass REG_ICASE to re_compile
when the regex is case insensitive (4) adjust the typechecker, which
involves teaching libfa how to make an automaton case-insensitive.

David

-------------- next part --------------
(* Demonstrate how quotes can be stripped from values.            *)
(* Values can be enclosed in single or double quotes, if they     *)
(* contain spaces they _have_ to be enclosed in quotes. Since     *)
(* everything's regular, we can't actually match a closing quote  *)
(* to the opening quote, so "hello' will be accepted, too.        *)

module Pass_strip_quotes =

  let nuttin = del /(""|'')?/ "''"
  let bare = del /["']?/ "" . store /[a-zA-Z0-9]+/ . del /["']?/ ""
  let quoted = del /["']/ "'" . store /.*[ \t].*/ . del /["']/ "'"

  let lns = [ label "foo" . bare ]
    | [ label "foo" . quoted ]
    | [ label "foo" . nuttin ]

  test lns get "'hello'" = { "foo" = "hello" }
  test lns get "'hello world'" = { "foo" = "hello world" }

  let hw = "'hello world'"
  let set_hw = set "/foo" "hello world"
  test lns put "hello" after set_hw = hw
  test lns put "'hello world'" after set "/foo" "hello" = "'hello'"

  test lns put "" after set_hw = hw
  test lns put "\"\"" after set_hw = hw


More information about the augeas-devel mailing list