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

Handle virtual and exported resources.

parent 245f44b2
No related branches found
No related tags found
No related merge requests found
......@@ -336,6 +336,9 @@ class PuppetResource(PuppetAST):
type: PuppetAST
bodies: list[tuple[PuppetAST, list[PuppetInstanciationParameter]]]
# Marks if the resource is virtual or exported.
# A single '@' means virtual, two '@' ('@@') means exported.
form: Optional[str] = None
@dataclass
......@@ -717,6 +720,15 @@ def build_ast(form: Any) -> PuppetAST:
case ['regexp', s]: return PuppetRegex(s)
case ['resource', {'type': t, 'bodies': bodies, 'form': form}]:
assert form in {'exported', 'virtual'}
return PuppetResource(
build_ast(t),
[(build_ast(body['title']),
[parse_puppet_instanciation_param(x) for x in body['ops']])
for body in bodies],
form)
case ['resource', {'type': t, 'bodies': bodies}]:
return PuppetResource(
build_ast(t),
......
......@@ -616,7 +616,14 @@ class ParserFormatter(Serializer[ParseDirective]):
@override
def _puppet_resource(self, it: PuppetResource) -> ParseDirective:
parser = ws & self.s(it.type) & ws & '{'
parser: ParseDirective = ws
match it.form:
case 'virtual':
parser &= '@'
case 'exported':
parser &= '@@'
parser &= ws & self.s(it.type) & ws & '{'
for key, params in it.bodies:
parser &= ws & self.s(key) & ws & ':'
for param in params:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment