New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PUP-8482) Add Puppet Extended S-Expression Notation #6673
(PUP-8482) Add Puppet Extended S-Expression Notation #6673
Conversation
This commit adds the Puppet Extended S-Expression Notation (PN) model to Puppet.
This commit adds a parser that can parse a string in PN format into a PN model.
This commit adds a transformer capable of transforming a puppet AST into a PN model. Only a limited set of unit tests are provided because the full set (70+ transformations) is expected to be tested by a pspec test (to be provided in a separate ticket regarding pspec evaluator).
This commit adds the ability to create formatted output from a PN tree by passing an `PN::Indent` instance to the `#format` method of the elements.
This commit adds the ability to generated PN output in native or JSON form from the commands `puppet parser dump` and `puppet epp dump`. Two opions are added: --format <old|pn|json> --pretty The 'old' format is the default and outputs using the old dump format. 'pn' will output the PN tree using it's native representation. 'json' will output the PN tree using JSON representation.
end | ||
|
||
# All methods below belong to the PN lexer | ||
def self.char_types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the class method is meant to be private, you'll want to mark it private using private_class_method :char_types
after the method definition, since def self.foo
methods aren't affected by being after private
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, there's no reason for char_types be public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Turns out it cannot be private. An instance is not allowed to call a private method on the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mainly going off of guessing at the intent, since it appears in the file after private
on line 51.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. It's a trade-off I guess. I want everything belonging to the lexer to be grouped below the comment at line 130 but it's cumbersome to mark each an every instance method private.
CLA signed by all contributors. |
lib/puppet/face/epp.rb
Outdated
'pn' is the Puppet Extended S-Expression Notation. | ||
'json' outputs the same graph as 'pn' but with JSON syntax. | ||
|
||
The output will be "pretty printed" when the option --pretty is given together with --format 'pn' or'json'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space between or
and ´'json'`
lib/puppet/face/epp.rb
Outdated
The output format can be controlled using the --format <old|pn|json> | ||
'old' is the default, but now deprecated format which is not API. | ||
'pn' is the Puppet Extended S-Expression Notation. | ||
'json' outputs the same graph as 'pn' but with JSON syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe line 113 should end with where:
and each of the three formats starts with a *
bullet ?
lib/puppet/face/parser.rb
Outdated
The output format can be controlled using the --format <old|pn|json> | ||
'old' is the default, but now deprecated format which is not API. | ||
'pn' is the Puppet Extended S-Expression Notation. | ||
'json' outputs the same graph as 'pn' but with JSON syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as earlier comment for the explanations...
lib/puppet/face/parser.rb
Outdated
'pn' is the Puppet Extended S-Expression Notation. | ||
'json' outputs the same graph as 'pn' but with JSON syntax. | ||
|
||
The output will be "pretty printed" when the option --pretty is given together with --format 'pn' or'json'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as earlier comment for or'json'
end | ||
|
||
require_relative 'model/pn_transformer' | ||
require_relative 'parser/pn_parser' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing newline on last line
spec/unit/face/epp_face_spec.rb
Outdated
@@ -174,6 +174,59 @@ | |||
expect(@logs[0].message).to match(/Syntax error at 'b'/) | |||
expect(@logs[0].level).to eq(:err) | |||
end | |||
|
|||
context "using 'pp' format" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'pn'
format? instead of 'pp'
?
spec/unit/face/epp_face_spec.rb
Outdated
@@ -174,6 +174,59 @@ | |||
expect(@logs[0].message).to match(/Syntax error at 'b'/) | |||
expect(@logs[0].level).to eq(:err) | |||
end | |||
|
|||
context "using 'pp' format" do | |||
it "prints the AST of the passed expression in PN format" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"passed expression" => "given expression"
spec/unit/face/parser_spec.rb
Outdated
@@ -145,6 +145,84 @@ | |||
parser.dump(manifest) | |||
}.to_not raise_error | |||
end | |||
|
|||
context "using 'pn' format" do | |||
it "prints the AST of the passed expression in PN format" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"passed" => "given"
spec/unit/face/parser_spec.rb
Outdated
end | ||
|
||
context "using 'json' format" do | ||
it "prints the AST of the passed expression in JSON based on the PN format" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passed / given
- Insert missing space before 'json' in dump docs for epp and parser - Use * bullet in docs in dump docs for epp and parser - Add missing newline - Fix typo 'pp' should be 'pn' - Use word 'given' instead of 'passed' in several test titles
d388b39
to
fb9f8e6
Compare
This PR adds the Puppet Extended S-Expression Notation (PN) to Puppet and makes it available to
puppet parser dump
andpuppet epp dump
commands though the option--format <old|pn|json>
.