Skip to content
Snippets Groups Projects
Commit 02723e1f authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Support blocks for collect statements.

parent 32bb95b6
Branches
No related tags found
No related merge requests found
......@@ -179,6 +179,7 @@ class PuppetCollect(Puppet):
type: Puppet
query: Puppet
ops: list[PuppetInstanciationParameter] = field(default_factory=list)
@dataclass
......@@ -625,6 +626,11 @@ def build_ast(form: Any) -> Puppet:
case ['concat', *parts]:
return PuppetConcat([build_ast(p) for p in parts])
case ['collect', {'type': t, 'query': q, 'ops': ops}]:
return PuppetCollect(build_ast(t),
build_ast(q),
[parse_puppet_instanciation_param(x) for x in ops])
case ['collect', {'type': t, 'query': q}]:
return PuppetCollect(build_ast(t),
build_ast(q))
......
......@@ -372,7 +372,15 @@ class ParserFormatter(Serializer[ParseDirective]):
@override
def _puppet_collect(self, it: PuppetCollect) -> ParseDirective:
return ws & self.s(it.type) & ws & self.s(it.query)
parser = ws & self.s(it.type) & ws & self.s(it.query)
sub = ws & "{"
for param in it.ops:
sub &= self.instanciation_parameter(param)
sub &= ws & '}'
parser &= optional(sub)
return parser
@override
def _puppet_concat(self, it: PuppetConcat) -> ParseDirective:
......
......@@ -179,3 +179,21 @@ def test_string_interpolation_deep_access():
parse_string("""
"${x['y']['z']}"
""")
def test_collect():
parse_string("""
Exec <| title=='apt_update' |> {
refreshonly => false,
}
""")
def test_collect_nested():
parse_string("""
if $_update['frequency'] == 'always' {
Exec <| title=='apt_update' |> {
refreshonly => false,
}
}
""")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment