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

Fix syscalls with lambda after them.

parent ed4a71fc
No related branches found
No related tags found
No related merge requests found
......@@ -384,6 +384,7 @@ class PuppetInvoke(Puppet):
func: Puppet
args: list[Puppet]
block: Optional[Puppet] = None
@dataclass
......@@ -677,6 +678,11 @@ def build_ast(form: Any) -> Puppet:
case ['unless', {'test': test}]:
return PuppetUnless(build_ast(test), [])
case ['invoke', {'functor': func, 'args': args, 'block': block}]:
return PuppetInvoke(build_ast(func),
[build_ast(x) for x in args],
build_ast(block))
case ['invoke', {'functor': func, 'args': args}]:
return PuppetInvoke(build_ast(func), [build_ast(x) for x in args])
......
......@@ -434,6 +434,7 @@ class ParserFormatter(Serializer[ParseDirective]):
for x in xs:
parser &= ws & ',' & ws & self.s(x)
parser &= optional(ws & ',') & optional(ws & ')')
parser &= optional(ws & self.s(it.block))
return tag('invoke', parser)
@override
......
......@@ -121,3 +121,33 @@ def test_invoke_inside_if():
print("parser:\n" + str(parser))
match_objects = ParserCombinator(s, "s").get(parser)
pprint(match_objects)
def test_funcall_with_block():
s = """
assert_type(A::B, $name) |$_expected, $actual | {
fail("msg")
}
"""
ast = build_ast(puppet_parser(s))
pprint(ast)
parser = ParserFormatter(s, "s").serialize(ast)
print("parser:\n" + str(parser))
match_objects = ParserCombinator(s, "s").get(parser)
pprint(match_objects)
def test_funcall_with_block_inner():
s = """
if $facts['package_provider'] == 'pkg' and $version =~ Undef {
assert_type(A::B, $name) |$_expected, $actual | {
fail("msg")
}
}
"""
ast = build_ast(puppet_parser(s))
pprint(ast)
parser = ParserFormatter(s, "s").serialize(ast)
print("parser:\n" + str(parser))
match_objects = ParserCombinator(s, "s").get(parser)
pprint(match_objects)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment