Skip to content
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

Merged

Conversation

thallgren
Copy link
Contributor

This PR adds the Puppet Extended S-Expression Notation (PN) to Puppet and makes it available to puppet parser dump and puppet epp dump commands though the option --format <old|pn|json>.

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@puppetcla
Copy link

CLA signed by all contributors.

'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'.
Copy link
Contributor

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'`

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.
Copy link
Contributor

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 ?

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.
Copy link
Contributor

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...

'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'.
Copy link
Contributor

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'
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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' ?

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"passed expression" => "given expression"

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"passed" => "given"

end

context "using 'json' format" do
it "prints the AST of the passed expression in JSON based on the PN format" do
Copy link
Contributor

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
@thallgren thallgren force-pushed the issue/pup-8482/pn-representation branch from d388b39 to fb9f8e6 Compare March 1, 2018 22:29
@hlindberg hlindberg merged commit 9441bc8 into puppetlabs:master Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants