bartavelle / language-puppet

A library to work with Puppet manifests, test them and eventually replace everything ruby.
BSD 3-Clause "New" or "Revised" License
51 stars 8 forks source link

Add support for calling Functions in Strings [Puppet 4] #199

Closed PierreR closed 7 years ago

PierreR commented 7 years ago
notify { 'need_coffee':
  message => "I need a cup of coffee. Remind me in ${fqdn_rand(10)} minutes.",
}
bartavelle commented 7 years ago

This is a large feature, and I will certainly not have time to implement it in the foreseeable future ...

bartavelle commented 7 years ago

This is tricky because there are two use cases:

Perhaps the simplest solution would be to add the full expression parser after try simpleIndexing and try rvariable on lines 204-207 of the parser.

bartavelle commented 7 years ago

This is really horrible:

"${::interfaces.split(',')[3]}"
bartavelle commented 7 years ago

This does't handle the case where you do arbitrary stuff to a variable, but should parse most expressions. To be toroughly tested!

PierreR commented 7 years ago

The commit broke this kind of code:

class test {
  exec {
    "test":
      command     => "test",
      onlyif      => "grep '^${sanitised_title}$'",
  }
}
puppetresources --parse test.pp
puppetresources: parse error:ParseError {errorPos = SourcePos {sourceName = "test.pp", sourceLine = Pos 5, sourceColumn = Pos 49} :| [], errorUnexpected = fromList [Tokens ('\'' :| "")], errorExpected = fromList [Tokens (':' :| ":"),Tokens ('{' :| "")], errorCustom = fromList []}
CallStack (from HasCallStack):
  error, called at progs/PuppetResources.hs:374:24 in main:Main
bartavelle commented 7 years ago

Just pushed a change that should fix that.

PierreR commented 7 years ago

Doesn't break anymore in any obvious way. Thanks.