From e3ee594fdfa0e7a6d9de26c4307e217de866f462 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sat, 18 Jul 2009 13:08:57 +0200 Subject: Fix #2422 & #2433 - make sure puppetdoc transform AST::Leaf boolean correctly AST nodes don't have a valid to_s that is producing a correct representation of said node. This patch adds some of the AST node to_s to produce correct values that can be used verbatim by puppetdoc to render the documentation. Signed-off-by: Brice Figureau --- lib/puppet/parser/ast/astarray.rb | 4 ++++ lib/puppet/parser/ast/function.rb | 5 +++++ lib/puppet/parser/ast/leaf.rb | 14 +++++++++++++- lib/puppet/parser/ast/resource_reference.rb | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb index 9b59d196a..dfd2bcd09 100644 --- a/lib/puppet/parser/ast/astarray.rb +++ b/lib/puppet/parser/ast/astarray.rb @@ -47,6 +47,10 @@ class Puppet::Parser::AST return self end + + def to_s + "[" + @children.collect { |c| c.to_s }.join(', ') + "]" + end end # A simple container class, containing the parameters for an object. diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb index 2f768ebdb..4c3a5dc05 100644 --- a/lib/puppet/parser/ast/function.rb +++ b/lib/puppet/parser/ast/function.rb @@ -51,5 +51,10 @@ class Puppet::Parser::AST @fname = Puppet::Parser::Functions.function(@name) # Lastly, check the parity end + + def to_s + args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments + "#{name}(#{args})" + end end end diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index dba9812a7..d08938011 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -11,7 +11,7 @@ class Puppet::Parser::AST end def to_s - return @value + return @value.to_s unless @value.nil? end end @@ -29,6 +29,10 @@ class Puppet::Parser::AST end @value end + + def to_s + @value ? "true" : "false" + end end # The base string class. @@ -38,6 +42,10 @@ class Puppet::Parser::AST def evaluate(scope) return scope.strinterp(@value, file, line) end + + def to_s + "\"#{@value}\"" + end end # An uninterpreted string. @@ -45,6 +53,10 @@ class Puppet::Parser::AST def evaluate(scope) return @value end + + def to_s + "\"#{@value}\"" + end end # The 'default' option on case statements and selectors. diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb index 6189ab8de..117bc88af 100644 --- a/lib/puppet/parser/ast/resource_reference.rb +++ b/lib/puppet/parser/ast/resource_reference.rb @@ -64,5 +64,13 @@ class Puppet::Parser::AST end return objtype end + + def to_s + if title.is_a?(ASTArray) + "#{type.to_s.capitalize}#{title}" + else + "#{type.to_s.capitalize}[#{title}]" + end + end end end -- cgit