Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
muppet-strings
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
muppet-strings
Commits
02723e1f
Commit
02723e1f
authored
Sep 19, 2023
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Support blocks for collect statements.
parent
32bb95b6
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
muppet/puppet/ast.py
+6
-0
6 additions, 0 deletions
muppet/puppet/ast.py
muppet/puppet/format/parser.py
+9
-1
9 additions, 1 deletion
muppet/puppet/format/parser.py
tests/test_parse_elsif.py
+18
-0
18 additions, 0 deletions
tests/test_parse_elsif.py
with
33 additions
and
1 deletion
muppet/puppet/ast.py
+
6
−
0
View file @
02723e1f
...
...
@@ -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
))
...
...
This diff is collapsed.
Click to expand it.
muppet/puppet/format/parser.py
+
9
−
1
View file @
02723e1f
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_parse_elsif.py
+
18
−
0
View file @
02723e1f
...
...
@@ -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,
}
}
"""
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment