diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:04 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:04 -0700 |
commit | 9ee56f2e67be973da49b1d3f21de1bf87de35e6f (patch) | |
tree | ddab8c01509f47664c52c8a6b165bb5a974f138f /lib/puppet/parser | |
parent | 051bd98751d9d4bc97f93f66723d9b7a00c0cfb4 (diff) | |
download | puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.gz puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.tar.xz puppet-9ee56f2e67be973da49b1d3f21de1bf87de35e6f.zip |
Code smell: Inconsistent indentation and related formatting issues
* Replaced 163 occurances of
defined\? +([@a-zA-Z_.0-9?=]+)
with
defined?(\1)
This makes detecting subsequent patterns easier.
3 Examples:
The code:
if ! defined? @parse_config
becomes:
if ! defined?(@parse_config)
The code:
return @option_parser if defined? @option_parser
becomes:
return @option_parser if defined?(@option_parser)
The code:
if defined? @local and @local
becomes:
if defined?(@local) and @local
* Eliminate trailing spaces.
Replaced 428 occurances of ^(.*?) +$ with \1
1 file was skipped.
test/ral/providers/host/parsed.rb because 0
* Replace leading tabs with an appropriate number of spaces.
Replaced 306 occurances of ^(\t+)(.*) with
Tabs are not consistently expanded in all environments.
* Don't arbitrarily wrap on sprintf (%) operator.
Replaced 143 occurances of
(.*['"] *%)
+(.*)
with
Splitting the line does nothing to aid clarity and hinders further refactorings.
3 Examples:
The code:
raise Puppet::Error, "Cannot create %s: basedir %s is a file" %
[dir, File.join(path)]
becomes:
raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
The code:
Puppet.err "Will not start without authorization file %s" %
Puppet[:authconfig]
becomes:
Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
The code:
$stderr.puts "Could not find host for PID %s with status %s" %
[pid, $?.exitstatus]
becomes:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus]
* Don't break short arrays/parameter list in two.
Replaced 228 occurances of
(.*)
+(.*)
with
3 Examples:
The code:
puts @format.wrap(type.provider(prov).doc,
:indent => 4, :scrub => true)
becomes:
puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true)
The code:
assert(FileTest.exists?(daily),
"Did not make daily graph for %s" % type)
becomes:
assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type)
The code:
assert(prov.target_object(:first).read !~ /^notdisk/,
"Did not remove thing from disk")
becomes:
assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk")
* If arguments must wrap, treat them all equally
Replaced 510 occurances of
lines ending in things like ...(foo, or ...(bar(1,3),
with
\1
\2
3 Examples:
The code:
midscope.to_hash(false),
becomes:
assert_equal(
The code:
botscope.to_hash(true),
becomes:
# bottomscope, then checking that we see the right stuff.
The code:
:path => link,
becomes:
* Replaced 4516 occurances of ^( *)(.*) with
The present code base is supposed to use four-space indentation. In some places we failed
to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question.
15 Examples:
The code:
def run_comp(cmd)
puts cmd
results = []
old_sync = $stdout.sync
$stdout.sync = true
line = []
begin
open("| #{cmd}", "r") do |f|
until f.eof? do
c = f.getc
becomes:
def run_comp(cmd)
puts cmd
results = []
old_sync = $stdout.sync
$stdout.sync = true
line = []
begin
open("| #{cmd}", "r") do |f|
until f.eof? do
c = f.getc
The code:
s.gsub!(/.{4}/n, '\\\\u\&')
}
string.force_encoding(Encoding::UTF_8)
string
rescue Iconv::Failure => e
raise GeneratorError, "Caught #{e.class}: #{e}"
end
else
def utf8_to_pson(string) # :nodoc:
string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
string.gsub!(/(
becomes:
s.gsub!(/.{4}/n, '\\\\u\&')
}
string.force_encoding(Encoding::UTF_8)
string
rescue Iconv::Failure => e
raise GeneratorError, "Caught #{e.class}: #{e}"
end
else
def utf8_to_pson(string) # :nodoc:
string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] }
string.gsub!(/(
The code:
end
}
rvalues: rvalue
| rvalues comma rvalue {
if val[0].instance_of?(AST::ASTArray)
result = val[0].push(val[2])
else
result = ast AST::ASTArray, :children => [val[0],val[2]]
end
}
becomes:
end
}
rvalues: rvalue
| rvalues comma rvalue {
if val[0].instance_of?(AST::ASTArray)
result = val[0].push(val[2])
else
result = ast AST::ASTArray, :children => [val[0],val[2]]
end
}
The code:
#passwdproc = proc { @password }
keytext = @key.export(
OpenSSL::Cipher::DES.new(:EDE3, :CBC),
@password
)
File.open(@keyfile, "w", 0400) { |f|
f << keytext
}
becomes:
# passwdproc = proc { @password }
keytext = @key.export(
OpenSSL::Cipher::DES.new(:EDE3, :CBC),
@password
)
File.open(@keyfile, "w", 0400) { |f|
f << keytext
}
The code:
end
def to_manifest
"%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
@params.collect { |p, v|
if v.is_a? Array
" #{p} => [\'#{v.join("','")}\']"
else
" #{p} => \'#{v}\'"
end
}.join(",\n")
becomes:
end
def to_manifest
"%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
@params.collect { |p, v|
if v.is_a? Array
" #{p} => [\'#{v.join("','")}\']"
else
" #{p} => \'#{v}\'"
end
}.join(",\n")
The code:
via the augeas tool.
Requires:
- augeas to be installed (http://www.augeas.net)
- ruby-augeas bindings
Sample usage with a string::
augeas{\"test1\" :
context => \"/files/etc/sysconfig/firstboot\",
changes => \"set RUN_FIRSTBOOT YES\",
becomes:
via the augeas tool.
Requires:
- augeas to be installed (http://www.augeas.net)
- ruby-augeas bindings
Sample usage with a string::
augeas{\"test1\" :
context => \"/files/etc/sysconfig/firstboot\",
changes => \"set RUN_FIRSTBOOT YES\",
The code:
names.should_not be_include("root")
end
describe "when generating a purgeable resource" do
it "should be included in the generated resources" do
Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
@resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
end
end
describe "when the instance's do not have an ensure property" do
becomes:
names.should_not be_include("root")
end
describe "when generating a purgeable resource" do
it "should be included in the generated resources" do
Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
@resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
end
end
describe "when the instance's do not have an ensure property" do
The code:
describe "when the instance's do not have an ensure property" do
it "should not be included in the generated resources" do
@no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo')
Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
@resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
end
end
describe "when the instance's ensure property does not accept absent" do
it "should not be included in the generated resources" do
@no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar')
becomes:
describe "when the instance's do not have an ensure property" do
it "should not be included in the generated resources" do
@no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo')
Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
@resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
end
end
describe "when the instance's ensure property does not accept absent" do
it "should not be included in the generated resources" do
@no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar')
The code:
func = nil
assert_nothing_raised do
func = Puppet::Parser::AST::Function.new(
:name => "template",
:ftype => :rvalue,
:arguments => AST::ASTArray.new(
:children => [stringobj(template)]
)
becomes:
func = nil
assert_nothing_raised do
func = Puppet::Parser::AST::Function.new(
:name => "template",
:ftype => :rvalue,
:arguments => AST::ASTArray.new(
:children => [stringobj(template)]
)
The code:
assert(
@store.allowed?("hostname.madstop.com", "192.168.1.50"),
"hostname not allowed")
assert(
! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),
"subname name allowed")
becomes:
assert(
@store.allowed?("hostname.madstop.com", "192.168.1.50"),
"hostname not allowed")
assert(
! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),
"subname name allowed")
The code:
assert_nothing_raised {
server = Puppet::Network::Handler.fileserver.new(
:Local => true,
:Config => false
)
}
becomes:
assert_nothing_raised {
server = Puppet::Network::Handler.fileserver.new(
:Local => true,
:Config => false
)
}
The code:
'yay',
{ :failonfail => false,
:uid => @user.uid,
:gid => @user.gid }
).returns('output')
output = Puppet::Util::SUIDManager.run_and_capture 'yay',
@user.uid,
@user.gid
becomes:
'yay',
{ :failonfail => false,
:uid => @user.uid,
:gid => @user.gid }
).returns('output')
output = Puppet::Util::SUIDManager.run_and_capture 'yay',
@user.uid,
@user.gid
The code:
).times(1)
pkg.provider.expects(
:aptget
).with(
'-y',
'-q',
'remove',
'faff'
becomes:
).times(1)
pkg.provider.expects(
:aptget
).with(
'-y',
'-q',
'remove',
'faff'
The code:
johnny one two
billy three four\n"
# Just parse and generate, to make sure it's isomorphic.
assert_nothing_raised do
assert_equal(text, @parser.to_file(@parser.parse(text)),
"parsing was not isomorphic")
end
end
def test_valid_attrs
becomes:
johnny one two
billy three four\n"
# Just parse and generate, to make sure it's isomorphic.
assert_nothing_raised do
assert_equal(text, @parser.to_file(@parser.parse(text)),
"parsing was not isomorphic")
end
end
def test_valid_attrs
The code:
"testing",
:onboolean => [true, "An on bool"],
:string => ["a string", "A string arg"]
)
result = []
should = []
assert_nothing_raised("Add args failed") do
@config.addargs(result)
end
@config.each do |name, element|
becomes:
"testing",
:onboolean => [true, "An on bool"],
:string => ["a string", "A string arg"]
)
result = []
should = []
assert_nothing_raised("Add args failed") do
@config.addargs(result)
end
@config.each do |name, element|
Diffstat (limited to 'lib/puppet/parser')
28 files changed, 455 insertions, 400 deletions
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 5a8f7be41..f407c78d6 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -26,15 +26,15 @@ class Puppet::Parser::AST # allow our subclass to specify they want documentation class << self - attr_accessor :use_docs - def associates_doc - self.use_docs = true - end + attr_accessor :use_docs + def associates_doc + self.use_docs = true + end end # Does this ast object set something? If so, it gets evaluated first. def self.settor? - if defined? @settor + if defined?(@settor) @settor else false diff --git a/lib/puppet/parser/ast/branch.rb b/lib/puppet/parser/ast/branch.rb index dcd09baa3..0c481ffe6 100644 --- a/lib/puppet/parser/ast/branch.rb +++ b/lib/puppet/parser/ast/branch.rb @@ -23,7 +23,7 @@ class Puppet::Parser::AST super(arghash) # Create the hash, if it was not set at initialization time. - unless defined? @children + unless defined?(@children) @children = [] end diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb index 47f32e2ee..51a82c5c0 100644 --- a/lib/puppet/parser/ast/caseopt.rb +++ b/lib/puppet/parser/ast/caseopt.rb @@ -16,7 +16,7 @@ class Puppet::Parser::AST # Are we the default option? def default? # Cache the @default value. - if defined? @default + if defined?(@default) return @default end @@ -33,7 +33,7 @@ class Puppet::Parser::AST end end - unless defined? @default + unless defined?(@default) @default = false end diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb index f3690c146..44f3b330c 100644 --- a/lib/puppet/parser/ast/collection.rb +++ b/lib/puppet/parser/ast/collection.rb @@ -30,11 +30,14 @@ class Collection < AST::Branch param.safeevaluate(scope) end - newcoll.add_override( + + newcoll.add_override( + :parameters => params, :file => @file, :line => @line, :source => scope.source, + :scope => scope ) end @@ -47,9 +50,12 @@ class Collection < AST::Branch if override.is_a?(AST::ASTArray) @override = override else - @override = AST::ASTArray.new( + + @override = AST::ASTArray.new( + :line => override.line, :file => override.file, + :children => [override] ) end diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb index 0984ed8ce..98204b14a 100644 --- a/lib/puppet/parser/ast/function.rb +++ b/lib/puppet/parser/ast/function.rb @@ -21,14 +21,12 @@ class Puppet::Parser::AST case @ftype when :rvalue unless Puppet::Parser::Functions.rvalue?(@name) - raise Puppet::ParseError, "Function '%s' does not return a value" % - @name + raise Puppet::ParseError, "Function '%s' does not return a value" % @name end when :statement if Puppet::Parser::Functions.rvalue?(@name) raise Puppet::ParseError, - "Function '%s' must be the value of a statement" % - @name + "Function '%s' must be the value of a statement" % @name end else raise Puppet::DevError, "Invalid function type %s" % @ftype.inspect diff --git a/lib/puppet/parser/ast/ifstatement.rb b/lib/puppet/parser/ast/ifstatement.rb index d84445bbd..36da50c7a 100644 --- a/lib/puppet/parser/ast/ifstatement.rb +++ b/lib/puppet/parser/ast/ifstatement.rb @@ -24,7 +24,7 @@ class Puppet::Parser::AST if Puppet::Parser::Scope.true?(value) return @statements.safeevaluate(scope) else - if defined? @else + if defined?(@else) return @else.safeevaluate(scope) else return nil diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb index 5488724c8..5aa11129a 100644 --- a/lib/puppet/parser/ast/resource.rb +++ b/lib/puppet/parser/ast/resource.rb @@ -37,7 +37,9 @@ class Resource < AST::ResourceReference # many times. resource_titles.flatten.collect { |resource_title| exceptwrap :type => Puppet::ParseError do - resource = Puppet::Parser::Resource.new(type, resource_title, + + resource = Puppet::Parser::Resource.new( + type, resource_title, :parameters => paramobjects, :file => self.file, :line => self.line, @@ -45,6 +47,7 @@ class Resource < AST::ResourceReference :virtual => virt, :source => scope.source, :scope => scope, + :strict => true ) @@ -62,9 +65,12 @@ class Resource < AST::ResourceReference if params.is_a?(AST::ASTArray) @parameters = params else - @parameters = AST::ASTArray.new( + + @parameters = AST::ASTArray.new( + :line => params.line, :file => params.file, + :children => [params] ) end diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index 93ddf4dbe..f667ed23a 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -36,11 +36,14 @@ class Puppet::Parser::AST resource = [resource] unless resource.is_a?(Array) resource = resource.collect do |r| - res = Puppet::Parser::Resource.new(r.type, r.title, + + res = Puppet::Parser::Resource.new( + r.type, r.title, :parameters => params, :file => file, :line => line, :source => scope.source, + :scope => scope ) diff --git a/lib/puppet/parser/ast/resourceparam.rb b/lib/puppet/parser/ast/resourceparam.rb index e6d9df17f..bf0a2258b 100644 --- a/lib/puppet/parser/ast/resourceparam.rb +++ b/lib/puppet/parser/ast/resourceparam.rb @@ -11,9 +11,12 @@ class Puppet::Parser::AST # Return the parameter and the value. def evaluate(scope) - return Puppet::Parser::Resource::Param.new( + + return Puppet::Parser::Resource::Param.new( + :name => @param, :value => @value.safeevaluate(scope), + :source => scope.source, :line => self.line, :file => self.file, :add => self.add ) diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index 9126cb2f8..9283d06ae 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -41,11 +41,14 @@ class Puppet::Parser::Collector # overrided those resources objects.each do |res| unless @collected.include?(res.ref) - newres = Puppet::Parser::Resource.new(res.type, res.title, + + newres = Puppet::Parser::Resource.new( + res.type, res.title, :parameters => overrides[:parameters], :file => overrides[:file], :line => overrides[:line], :source => overrides[:source], + :scope => overrides[:scope] ) @@ -111,7 +114,7 @@ class Puppet::Parser::Collector # We used to eagerly include param_names/values but the way # the search filter is built ruined those efforts and we # were eagerly loading only the searched parameter and not - # the other ones. + # the other ones. query = {} case search when /puppet_tags/ @@ -151,8 +154,7 @@ class Puppet::Parser::Collector end end - scope.debug("Collected %s %s resource%s in %.2f seconds" % - [count, @type, count == 1 ? "" : "s", time]) + scope.debug("Collected %s %s resource%s in %.2f seconds" % [count, @type, count == 1 ? "" : "s", time]) return resources end diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 0a9d0804f..e64ec4ba3 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -121,7 +121,7 @@ class Puppet::Parser::Compiler # Return the node's environment. def environment - unless defined? @environment + unless defined?(@environment) if node.environment and node.environment != "" @environment = node.environment else @@ -189,7 +189,7 @@ class Puppet::Parser::Compiler end # Create a new scope, with either a specified parent scope or - # using the top scope. + # using the top scope. def newscope(parent, options = {}) parent ||= topscope options[:compiler] = self @@ -355,8 +355,7 @@ class Puppet::Parser::Compiler end unless remaining.empty? - raise Puppet::ParseError, "Failed to realize virtual resources %s" % - remaining.join(', ') + raise Puppet::ParseError, "Failed to realize virtual resources %s" % remaining.join(', ') end end diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 201121cb9..a99e8dc95 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -15,9 +15,12 @@ module Puppet::Parser::Functions end def self.autoloader - unless defined? @autoloader - @autoloader = Puppet::Util::Autoload.new(self, + unless defined?(@autoloader) + + @autoloader = Puppet::Util::Autoload.new( + self, "puppet/parser/functions", + :wrap => false ) end @@ -28,8 +31,8 @@ module Puppet::Parser::Functions Environment = Puppet::Node::Environment def self.environment_module(env = nil) - @modules.synchronize { - @modules[ env || Environment.current || Environment.root ] ||= Module.new + @modules.synchronize { + @modules[ env || Environment.current || Environment.root ] ||= Module.new } end @@ -104,8 +107,8 @@ module Puppet::Parser::Functions end def self.functions(env = nil) - @functions.synchronize { - @functions[ env || Environment.current || Environment.root ] + @functions.synchronize { + @functions[ env || Environment.current || Environment.root ] } end diff --git a/lib/puppet/parser/functions/file.rb b/lib/puppet/parser/functions/file.rb index 47b3f96e0..f78823d3a 100644 --- a/lib/puppet/parser/functions/file.rb +++ b/lib/puppet/parser/functions/file.rb @@ -1,5 +1,8 @@ # Returns the contents of a file -Puppet::Parser::Functions::newfunction(:file, :type => :rvalue, + + Puppet::Parser::Functions::newfunction( + :file, :type => :rvalue, + :doc => "Return the contents of a file. Multiple files can be passed, and the first file that exists will be read in.") do |vals| ret = nil @@ -15,7 +18,6 @@ Puppet::Parser::Functions::newfunction(:file, :type => :rvalue, if ret ret else - raise Puppet::ParseError, "Could not find any files from %s" % - vals.join(", ") + raise Puppet::ParseError, "Could not find any files from %s" % vals.join(", ") end end diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb index 9297539e3..27af2d7ca 100644 --- a/lib/puppet/parser/functions/fqdn_rand.rb +++ b/lib/puppet/parser/functions/fqdn_rand.rb @@ -1,6 +1,6 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc => "Generates random numbers based on the node's fqdn. The first argument - sets the range. Additional (optional) arguments may be used to further + sets the range. Additional (optional) arguments may be used to further distinguish the seed.") do |args| require 'md5' max = args.shift diff --git a/lib/puppet/parser/functions/inline_template.rb b/lib/puppet/parser/functions/inline_template.rb index b9547cac7..fde8006b4 100644 --- a/lib/puppet/parser/functions/inline_template.rb +++ b/lib/puppet/parser/functions/inline_template.rb @@ -14,8 +14,7 @@ Puppet::Parser::Functions::newfunction(:inline_template, :type => :rvalue, :doc wrapper.result(string) rescue => detail raise Puppet::ParseError, - "Failed to parse inline template: %s" % - [detail] + "Failed to parse inline template: %s" % [detail] end end.join("") end diff --git a/lib/puppet/parser/functions/regsubst.rb b/lib/puppet/parser/functions/regsubst.rb index d02680862..c47c1654e 100644 --- a/lib/puppet/parser/functions/regsubst.rb +++ b/lib/puppet/parser/functions/regsubst.rb @@ -1,7 +1,10 @@ module Puppet::Parser::Functions - newfunction(:regsubst, :type => :rvalue, - :doc => " - Perform regexp replacement on a string or array of strings. + + newfunction( + :regsubst, :type => :rvalue, + + :doc => " + Perform regexp replacement on a string or array of strings. - **Parameters** (in order): @@ -20,10 +23,10 @@ module Puppet::Parser::Functions :lang: Optional. How to handle multibyte characters. A single-character string with the following values: - - **N** None - - **E** EUC - - **S** SJIS - - **U** UTF-8 + - **N** None + - **E** EUC + - **S** SJIS + - **U** UTF-8 - **Examples** @@ -37,8 +40,11 @@ Put angle brackets around each octet in the node's IP address:: ") \ do |args| unless args.length.between?(3, 5) - raise(Puppet::ParseError, - "regsubst(): got #{args.length} arguments, expected 3 to 5") + + raise( + Puppet::ParseError, + + "regsubst(): got #{args.length} arguments, expected 3 to 5") end target, regexp, replacement, flags, lang = args reflags = 0 @@ -48,8 +54,11 @@ Put angle brackets around each octet in the node's IP address:: elsif flags.respond_to?(:split) flags = flags.split('') else - raise(Puppet::ParseError, - "regsubst(): bad flags parameter #{flags.class}:`#{flags}'") + + raise( + Puppet::ParseError, + + "regsubst(): bad flags parameter #{flags.class}:`#{flags}'") end flags.each do |f| case f @@ -63,22 +72,28 @@ Put angle brackets around each octet in the node's IP address:: begin re = Regexp.compile(regexp, reflags, lang) rescue RegexpError, TypeError - raise(Puppet::ParseError, - "regsubst(): Bad regular expression `#{regexp}'") + + raise( + Puppet::ParseError, + + "regsubst(): Bad regular expression `#{regexp}'") end if target.respond_to?(operation) # String parameter -> string result result = target.send(operation, re, replacement) elsif target.respond_to?(:collect) and - target.respond_to?(:all?) and - target.all? { |e| e.respond_to?(operation) } + target.respond_to?(:all?) and + target.all? { |e| e.respond_to?(operation) } # Array parameter -> array result result = target.collect { |e| e.send(operation, re, replacement) } else - raise(Puppet::ParseError, - "regsubst(): bad target #{target.class}:`#{target}'") + + raise( + Puppet::ParseError, + + "regsubst(): bad target #{target.class}:`#{target}'") end return result end diff --git a/lib/puppet/parser/functions/require.rb b/lib/puppet/parser/functions/require.rb index a46999f05..45b89c77a 100644 --- a/lib/puppet/parser/functions/require.rb +++ b/lib/puppet/parser/functions/require.rb @@ -1,5 +1,8 @@ # Requires the specified classes -Puppet::Parser::Functions::newfunction(:require, + + Puppet::Parser::Functions::newfunction( + :require, + :doc =>"Evaluate one or more classes, adding the required class as a dependency. The relationship metaparameters work well for specifying relationships @@ -9,18 +12,18 @@ relationships between classes. This function is a superset of the class depends on the required class. Warning: using require in place of include can lead to unwanted dependency cycles. - For instance the following manifest, with 'require' instead of 'include' - would produce a nasty dependence cycle, because notify imposes a before - between File[/foo] and Service[foo]:: - - class myservice { - service { foo: ensure => running } - } - - class otherstuff { - include myservice - file { '/foo': notify => Service[foo] } - } + For instance the following manifest, with 'require' instead of 'include' + would produce a nasty dependence cycle, because notify imposes a before + between File[/foo] and Service[foo]:: + + class myservice { + service { foo: ensure => running } + } + + class otherstuff { + include myservice + file { '/foo': notify => Service[foo] } + } Note that this function only works with clients 0.25 and later, and it will fail if used with earlier clients. diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb index 09386a604..432825ee9 100644 --- a/lib/puppet/parser/functions/sha1.rb +++ b/lib/puppet/parser/functions/sha1.rb @@ -1,5 +1,4 @@ -Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue, - :doc => "Returns a SHA1 hash value from a provided string.") do |args| +Puppet::Parser::Functions::newfunction(:sha1, :type => :rvalue, :doc => "Returns a SHA1 hash value from a provided string.") do |args| require 'sha1' Digest::SHA1.hexdigest(args[0]) diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb index 36dba7e68..405a5bc9a 100644 --- a/lib/puppet/parser/functions/split.rb +++ b/lib/puppet/parser/functions/split.rb @@ -1,14 +1,17 @@ module Puppet::Parser::Functions - newfunction(:split, :type => :rvalue, - :doc => "\ + + newfunction( + :split, :type => :rvalue, + + :doc => "\ Split a string variable into an array using the specified split regexp. - Usage:: + Usage:: - $string = 'v1.v2:v3.v4' - $array_var1 = split($string, ':') - $array_var2 = split($string, '[.]') - $array_var3 = split($string, '[.:]') + $string = 'v1.v2:v3.v4' + $array_var1 = split($string, ':') + $array_var2 = split($string, '[.]') + $array_var3 = split($string, '[.:]') $array_var1 now holds the result ['v1.v2', 'v3.v4'], while $array_var2 holds ['v1', 'v2:v3', 'v4'], and @@ -19,11 +22,10 @@ a regexp meta-character (.), and that needs protection. A simple way to do that for a single character is to enclose it in square brackets.") do |args| - if args.length != 2 - raise Puppet::ParseError, ("split(): wrong number of arguments" + - " (#{args.length}; must be 2)") - end + if args.length != 2 + raise Puppet::ParseError, ("split(): wrong number of arguments" + " (#{args.length}; must be 2)") + end - return args[0].split(Regexp.compile(args[1])) + return args[0].split(Regexp.compile(args[1])) end end diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb index d84b1866a..4a53a9736 100644 --- a/lib/puppet/parser/functions/sprintf.rb +++ b/lib/puppet/parser/functions/sprintf.rb @@ -1,8 +1,11 @@ module Puppet::Parser::Functions - newfunction(:sprintf, :type => :rvalue, + + newfunction( + :sprintf, :type => :rvalue, + :doc => "Perform printf-style formatting of text. - The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the ``Kernel::sprintf()`` function in Ruby for all the details.") do |args| + The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the ``Kernel::sprintf()`` function in Ruby for all the details.") do |args| if args.length < 1 raise Puppet::ParseError, 'sprintf() needs at least one argument' end diff --git a/lib/puppet/parser/functions/template.rb b/lib/puppet/parser/functions/template.rb index 34524e388..35c54c66a 100644 --- a/lib/puppet/parser/functions/template.rb +++ b/lib/puppet/parser/functions/template.rb @@ -1,7 +1,7 @@ Puppet::Parser::Functions::newfunction(:template, :type => :rvalue, :doc => "Evaluate a template and return its value. See `the templating docs - <http://docs.puppetlabs.com/guides/templating.html>`_ for more information. - Note that if multiple templates are specified, their output is all + <http://docs.puppetlabs.com/guides/templating.html>`_ for more information. + Note that if multiple templates are specified, their output is all concatenated and returned as the output of the function.") do |vals| require 'erb' @@ -16,8 +16,7 @@ Puppet::Parser::Functions::newfunction(:template, :type => :rvalue, :doc => wrapper.result rescue => detail raise Puppet::ParseError, - "Failed to parse template %s: %s" % - [file, detail] + "Failed to parse template %s: %s" % [file, detail] end end.join("") end diff --git a/lib/puppet/parser/functions/versioncmp.rb b/lib/puppet/parser/functions/versioncmp.rb index 9435655a7..b8d39af96 100644 --- a/lib/puppet/parser/functions/versioncmp.rb +++ b/lib/puppet/parser/functions/versioncmp.rb @@ -1,6 +1,9 @@ require 'puppet/util/package' -Puppet::Parser::Functions::newfunction(:versioncmp, :type => :rvalue, + + Puppet::Parser::Functions::newfunction( + :versioncmp, :type => :rvalue, + :doc => "Compares two versions Prototype:: diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index a6e64a38f..c08b1a31a 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -44,11 +44,11 @@ program: statements { result = nil end } - | nil + | nil statements: statement - | statements statement { - if val[0] and val[1] + | statements statement { + if val[0] and val[1] if val[0].instance_of?(AST::ASTArray) val[0].push(val[1]) result = val[0] @@ -63,25 +63,25 @@ statements: statement # The main list of valid statements statement: resource - | virtualresource - | collection - | assignment - | casestatement - | ifstatement_begin - | import - | fstatement - | definition - | hostclass - | nodedef - | resourceoverride - | append - | relationship + | virtualresource + | collection + | assignment + | casestatement + | ifstatement_begin + | import + | fstatement + | definition + | hostclass + | nodedef + | resourceoverride + | append + | relationship relationship: relationship_side edge relationship_side { result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) } - | relationship edge relationship_side { - result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) + | relationship edge relationship_side { + result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) } relationship_side: resource | resourceref | collection @@ -96,7 +96,7 @@ fstatement: NAME LPAREN funcvalues RPAREN { :arguments => args, :ftype => :statement } - | NAME LPAREN funcvalues COMMA RPAREN { +| NAME LPAREN funcvalues COMMA RPAREN { args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], @@ -110,9 +110,9 @@ fstatement: NAME LPAREN funcvalues RPAREN { :arguments => AST::ASTArray.new({}), :ftype => :statement } - | NAME funcvalues { - args = aryfy(val[1]) - result = ast AST::Function, + | NAME funcvalues { + args = aryfy(val[1]) + result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => args, @@ -120,14 +120,14 @@ fstatement: NAME LPAREN funcvalues RPAREN { } funcvalues: namestring - | resourceref - | funcvalues COMMA namestring { - result = aryfy(val[0], val[2]) - result.line = @lexer.line - result.file = @lexer.file -} - | funcvalues COMMA resourceref { - unless val[0].is_a?(AST::ASTArray) + | resourceref + | funcvalues COMMA namestring { + result = aryfy(val[0], val[2]) + result.line = @lexer.line + result.file = @lexer.file +} + | funcvalues COMMA resourceref { + unless val[0].is_a?(AST::ASTArray) val[0] = aryfy(val[0]) end @@ -139,16 +139,16 @@ funcvalues: namestring # This is *almost* an rvalue, but I couldn't get a full # rvalue to work without scads of shift/reduce conflicts. namestring: name - | variable - | type - | boolean - | funcrvalue - | selector - | quotedtext - | hasharrayaccesses - | CLASSNAME { - result = ast AST::Name, :value => val[0][:value] - } + | variable + | type + | boolean + | funcrvalue + | selector + | quotedtext + | hasharrayaccesses + | CLASSNAME { + result = ast AST::Name, :value => val[0][:value] + } resource: classname LBRACE resourceinstances endsemi RBRACE { @lexer.commentpop @@ -165,9 +165,12 @@ resource: classname LBRACE resourceinstances endsemi RBRACE { end # now, i need to somehow differentiate between those things with # arrays in their names, and normal things - result.push ast(AST::Resource, + + result.push ast( + AST::Resource, :type => val[0], :title => instance[0], + :parameters => instance[1]) } } | classname LBRACE params endcomma RBRACE { @@ -238,8 +241,8 @@ collection: classref collectrhand LBRACE anyparams endcomma RBRACE { args[:override] = val[3] result = ast AST::Collection, args } - | classref collectrhand { - if val[0] =~ /^[a-z]/ + | classref collectrhand { + if val[0] =~ /^[a-z]/ Puppet.warning addcontext("Collection names must now be capitalized") end type = val[0].downcase @@ -267,8 +270,8 @@ collectrhand: LCOLLECT collstatements RCOLLECT { result = :virtual end } - | LLCOLLECT collstatements RRCOLLECT { - if val[1] + | LLCOLLECT collstatements RRCOLLECT { + if val[1] result = val[1] result.form = :exported else @@ -279,41 +282,41 @@ collectrhand: LCOLLECT collstatements RCOLLECT { # A mini-language for handling collection comparisons. This is organized # to avoid the need for precedence indications. collstatements: nil - | collstatement - | collstatements colljoin collstatement { - result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] + | collstatement + | collstatements colljoin collstatement { + result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] } collstatement: collexpr - | LPAREN collstatements RPAREN { - result = val[1] - result.parens = true + | LPAREN collstatements RPAREN { + result = val[1] + result.parens = true } colljoin: AND { result=val[0][:value] } - | OR { result=val[0][:value] } + | OR { result=val[0][:value] } collexpr: colllval ISEQUAL simplervalue { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val } - | colllval NOTEQUAL simplervalue { - result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] - #result = ast AST::CollExpr - #result.push *val + | colllval NOTEQUAL simplervalue { + result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] + #result = ast AST::CollExpr + #result.push *val } colllval: variable - | name + | name resourceinst: resourcename COLON params endcomma { result = ast AST::ResourceInstance, :children => [val[0],val[2]] } resourceinstances: resourceinst - | resourceinstances SEMIC resourceinst { - if val[0].instance_of?(AST::ResourceInstance) + | resourceinstances SEMIC resourceinst { + if val[0].instance_of?(AST::ResourceInstance) result = ast AST::ASTArray, :children => [val[0],val[2]] else val[0].push val[2] @@ -322,7 +325,7 @@ resourceinstances: resourceinst } endsemi: # nothing - | SEMIC + | SEMIC undef: UNDEF { result = ast AST::Undef, :value => :undef @@ -337,12 +340,12 @@ type: CLASSREF { } resourcename: quotedtext - | name - | type - | selector - | variable - | array - | hasharrayaccesses + | name + | type + | selector + | variable + | array + | hasharrayaccesses assignment: VARIABLE EQUALS expression { if val[0][:value] =~ /::/ @@ -352,8 +355,8 @@ assignment: VARIABLE EQUALS expression { variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] } - | hasharrayaccess EQUALS expression { - result = ast AST::VarDef, :name => val[0], :value => val[2] + | hasharrayaccess EQUALS expression { + result = ast AST::VarDef, :name => val[0], :value => val[2] } append: VARIABLE APPENDS expression { @@ -365,9 +368,9 @@ params: # nothing { result = ast AST::ASTArray } - | param { result = val[0] } - | params COMMA param { - if val[0].instance_of?(AST::ASTArray) + | param { result = val[0] } + | params COMMA param { + if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else @@ -381,19 +384,19 @@ param: NAME FARROW rvalue { addparam: NAME PARROW rvalue { result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], - :add => true + :add => true } anyparam: param - | addparam + | addparam anyparams: # nothing { result = ast AST::ASTArray } - | anyparam { result = val[0] } - | anyparams COMMA anyparam { - if val[0].instance_of?(AST::ASTArray) + | anyparam { result = val[0] } + | anyparams COMMA anyparam { + if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else @@ -402,8 +405,8 @@ anyparams: # nothing } rvalues: rvalue - | rvalues comma rvalue { - if val[0].instance_of?(AST::ASTArray) + | rvalues comma rvalue { + if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] @@ -411,24 +414,24 @@ rvalues: rvalue } simplervalue: quotedtext - | name - | type - | boolean - | selector - | variable + | name + | type + | boolean + | selector + | variable rvalue: quotedtext - | name - | type - | boolean - | selector - | variable - | array - | hash - | hasharrayaccesses - | resourceref - | funcrvalue - | undef + | name + | type + | boolean + | selector + | variable + | array + | hash + | hasharrayaccesses + | resourceref + | funcrvalue + | undef # We currently require arguments in these functions. funcrvalue: NAME LPAREN funcvalues RPAREN { @@ -444,13 +447,13 @@ funcrvalue: NAME LPAREN funcvalues RPAREN { :ftype => :rvalue } -quotedtext: STRING { result = ast AST::String, :value => val[0][:value], :line => val[0][:line] } - | DQPRE dqrval { result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] } +quotedtext: STRING { result = ast AST::String, :value => val[0][:value], :line => val[0][:line] } + | DQPRE dqrval { result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] } dqrval: expression dqtail { result = [val[0]] + val[1] } dqtail: DQPOST { result = [ast(AST::String,val[0])] } - | DQMID dqrval { result = [ast(AST::String,val[0])] + val[1] } + | DQMID dqrval { result = [ast(AST::String,val[0])] + val[1] } boolean: BOOLEAN { result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] @@ -480,11 +483,11 @@ ifstatement: expression LBRACE statements RBRACE else { result = ast AST::IfStatement, args } - | expression LBRACE RBRACE else { - @lexer.commentpop - args = { - :test => val[0], - :statements => ast(AST::Nop) + | expression LBRACE RBRACE else { + @lexer.commentpop + args = { + :test => val[0], + :statements => ast(AST::Nop) } if val[3] @@ -495,16 +498,16 @@ ifstatement: expression LBRACE statements RBRACE else { } else: # nothing - | ELSIF ifstatement { - result = ast AST::Else, :statements => val[1] + | ELSIF ifstatement { + result = ast AST::Else, :statements => val[1] } - | ELSE LBRACE statements RBRACE { - @lexer.commentpop - result = ast AST::Else, :statements => val[2] + | ELSE LBRACE statements RBRACE { + @lexer.commentpop + result = ast AST::Else, :statements => val[2] } - | ELSE LBRACE RBRACE { - @lexer.commentpop - result = ast AST::Else, :statements => ast(AST::Nop) + | ELSE LBRACE RBRACE { + @lexer.commentpop + result = ast AST::Else, :statements => ast(AST::Nop) } # Unlike yacc/bison, it seems racc @@ -520,65 +523,65 @@ else: # nothing # per operator :-( expression: rvalue - | expression IN rvalue { - result = ast AST::InOperator, :lval => val[0], :rval => val[2] + | expression IN rvalue { + result = ast AST::InOperator, :lval => val[0], :rval => val[2] } - | expression MATCH regex { - result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression MATCH regex { + result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression NOMATCH regex { - result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression NOMATCH regex { + result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression PLUS expression { - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression PLUS expression { + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression MINUS expression { - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression MINUS expression { + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression DIV expression { - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression DIV expression { + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression TIMES expression { - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression TIMES expression { + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression LSHIFT expression { - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression LSHIFT expression { + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression RSHIFT expression { - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression RSHIFT expression { + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | MINUS expression =UMINUS { - result = ast AST::Minus, :value => val[1] + | MINUS expression =UMINUS { + result = ast AST::Minus, :value => val[1] } - | expression NOTEQUAL expression { - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression NOTEQUAL expression { + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression ISEQUAL expression { - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression ISEQUAL expression { + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression GREATERTHAN expression { - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression GREATERTHAN expression { + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression GREATEREQUAL expression { - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression GREATEREQUAL expression { + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression LESSTHAN expression { - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression LESSTHAN expression { + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression LESSEQUAL expression { - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression LESSEQUAL expression { + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | NOT expression { - result = ast AST::Not, :value => val[1] + | NOT expression { + result = ast AST::Not, :value => val[1] } - | expression AND expression { - result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression AND expression { + result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | expression OR expression { - result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + | expression OR expression { + result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } - | LPAREN expression RPAREN { - result = val[1] + | LPAREN expression RPAREN { + result = val[1] } casestatement: CASE rvalue LBRACE caseopts RBRACE { @@ -591,8 +594,8 @@ casestatement: CASE rvalue LBRACE caseopts RBRACE { } caseopts: caseopt - | caseopts caseopt { - if val[0].instance_of?(AST::ASTArray) + | caseopts caseopt { + if val[0].instance_of?(AST::ASTArray) val[0].push val[1] result = val[0] else @@ -605,15 +608,18 @@ caseopt: casevalues COLON LBRACE statements RBRACE { result = ast AST::CaseOpt, :value => val[0], :statements => val[3] } | casevalues COLON LBRACE RBRACE { @lexer.commentpop - result = ast(AST::CaseOpt, + + result = ast( + AST::CaseOpt, :value => val[0], + :statements => ast(AST::ASTArray) ) } casevalues: selectlhand - | casevalues COMMA selectlhand { - if val[0].instance_of?(AST::ASTArray) + | casevalues COMMA selectlhand { + if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else @@ -626,14 +632,14 @@ selector: selectlhand QMARK svalues { } svalues: selectval - | LBRACE sintvalues endcomma RBRACE { - @lexer.commentpop - result = val[1] + | LBRACE sintvalues endcomma RBRACE { + @lexer.commentpop + result = val[1] } sintvalues: selectval - | sintvalues comma selectval { - if val[0].instance_of?(AST::ASTArray) + | sintvalues comma selectval { + if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else @@ -646,21 +652,21 @@ selectval: selectlhand FARROW rvalue { } selectlhand: name - | type - | quotedtext - | variable - | funcrvalue - | boolean - | undef - | DEFAULT { - result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] + | type + | quotedtext + | variable + | funcrvalue + | boolean + | undef + | DEFAULT { + result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] } - | regex + | regex # These are only used for importing, and we don't interpolate there. string: STRING { result = [val[0][:value]] } strings: string - | strings COMMA string { result = val[0] += val[2] } + | strings COMMA string { result = val[0] += val[2] } import: IMPORT strings { val[1].each do |file| @@ -714,16 +720,16 @@ nodedef: NODE hostnames nodeparent LBRACE statements RBRACE { classref: CLASSREF { result = val[0][:value] } classname: NAME { result = val[0][:value] } - | CLASSNAME { result = val[0][:value] } - | CLASS { result = "class" } + | CLASSNAME { result = val[0][:value] } + | CLASS { result = "class" } # Multiple hostnames, as used for node names. These are all literal # strings, not AST objects. hostnames: nodename - | hostnames COMMA nodename { - result = val[0] - result = [result] unless result.is_a?(Array) - result << val[2] + | hostnames COMMA nodename { + result = val[0] + result = [result] unless result.is_a?(Array) + result << val[2] } nodename: hostname { @@ -731,9 +737,9 @@ nodename: hostname { } hostname: NAME { result = val[0][:value] } - | STRING { result = val[0][:value] } - | DEFAULT { result = val[0][:value] } - | regex + | STRING { result = val[0][:value] } + | DEFAULT { result = val[0][:value] } + | regex nil: { result = nil @@ -744,28 +750,28 @@ nothing: { } argumentlist: nil - | LPAREN nothing RPAREN { - result = nil + | LPAREN nothing RPAREN { + result = nil } - | LPAREN arguments RPAREN { - result = val[1] - result = [result] unless result[0].is_a?(Array) + | LPAREN arguments RPAREN { + result = val[1] + result = [result] unless result[0].is_a?(Array) } arguments: argument - | arguments COMMA argument { - result = val[0] - result = [result] unless result[0].is_a?(Array) - result << val[2] + | arguments COMMA argument { + result = val[0] + result = [result] unless result[0].is_a?(Array) + result << val[2] } argument: NAME EQUALS rvalue { Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value], val[2]] } - | NAME { - Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") - result = [val[0][:value]] + | NAME { + Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") + result = [val[0][:value]] } | VARIABLE EQUALS rvalue { result = [val[0][:value], val[2]] } | VARIABLE { @@ -773,13 +779,13 @@ argument: NAME EQUALS rvalue { } nodeparent: nil - | INHERITS hostname { - result = val[1] + | INHERITS hostname { + result = val[1] } classparent: nil - | INHERITS classnameordefault { - result = val[1] + | INHERITS classnameordefault { + result = val[1] } classnameordefault: classname | DEFAULT @@ -795,8 +801,8 @@ array: LBRACK rvalues RBRACK { result = ast AST::ASTArray, :children => [val[1]] end } - | LBRACK rvalues COMMA RBRACK { - if val[1].instance_of?(AST::ASTArray) + | LBRACK rvalues COMMA RBRACK { + if val[1].instance_of?(AST::ASTArray) result = val[1] else result = ast AST::ASTArray, :children => [val[1]] @@ -806,10 +812,10 @@ array: LBRACK rvalues RBRACK { } comma: FARROW - | COMMA + | COMMA endcomma: # nothing - | COMMA { result = nil } + | COMMA { result = nil } regex: REGEX { result = ast AST::Regex, :value => val[0][:value] @@ -822,8 +828,8 @@ hash: LBRACE hashpairs RBRACE { result = ast AST::ASTHash, { :value => val[1] } end } - | LBRACE hashpairs COMMA RBRACE { - if val[1].instance_of?(AST::ASTHash) + | LBRACE hashpairs COMMA RBRACE { + if val[1].instance_of?(AST::ASTHash) result = val[1] else result = ast AST::ASTHash, { :value => val[1] } @@ -833,8 +839,8 @@ hash: LBRACE hashpairs RBRACE { } hashpairs: hashpair - | hashpairs COMMA hashpair { - if val[0].instance_of?(AST::ASTHash) + | hashpairs COMMA hashpair { + if val[0].instance_of?(AST::ASTHash) result = val[0].merge(val[2]) else result = ast AST::ASTHash, :value => val[0] @@ -847,15 +853,15 @@ hashpair: key FARROW rvalue { } key: NAME { result = val[0][:value] } - | quotedtext { result = val[0] } + | quotedtext { result = val[0] } hasharrayaccess: VARIABLE LBRACK rvalue RBRACK { - result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] + result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] } hasharrayaccesses: hasharrayaccess - | hasharrayaccess LBRACK rvalue RBRACK { - result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] + | hasharrayaccess LBRACK rvalue RBRACK { + result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] } end diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 3ac16b56a..5d1ce8bc7 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -18,7 +18,7 @@ class Puppet::Parser::Lexer def lex_error msg raise Puppet::LexError.new(msg) end - + class Token attr_accessor :regex, :name, :string, :skip, :incr_line, :skip_text, :accumulate @@ -45,10 +45,10 @@ class Puppet::Parser::Lexer @name.to_s end end - + def acceptable?(context={}) # By default tokens are aceeptable in any context - true + true end end @@ -108,55 +108,58 @@ class Puppet::Parser::Lexer end TOKENS = TokenList.new - TOKENS.add_tokens( - '[' => :LBRACK, - ']' => :RBRACK, - '{' => :LBRACE, - '}' => :RBRACE, - '(' => :LPAREN, - ')' => :RPAREN, - '=' => :EQUALS, - '+=' => :APPENDS, - '==' => :ISEQUAL, - '>=' => :GREATEREQUAL, - '>' => :GREATERTHAN, - '<' => :LESSTHAN, - '<=' => :LESSEQUAL, - '!=' => :NOTEQUAL, - '!' => :NOT, - ',' => :COMMA, - '.' => :DOT, - ':' => :COLON, - '@' => :AT, - '<<|' => :LLCOLLECT, - '->' => :IN_EDGE, - '<-' => :OUT_EDGE, - '~>' => :IN_EDGE_SUB, - '<~' => :OUT_EDGE_SUB, - '|>>' => :RRCOLLECT, - '<|' => :LCOLLECT, - '|>' => :RCOLLECT, - ';' => :SEMIC, - '?' => :QMARK, - '\\' => :BACKSLASH, - '=>' => :FARROW, - '+>' => :PARROW, - '+' => :PLUS, - '-' => :MINUS, - '/' => :DIV, - '*' => :TIMES, - '<<' => :LSHIFT, - '>>' => :RSHIFT, - '=~' => :MATCH, - '!~' => :NOMATCH, - %r{([a-z][-\w]*)?(::[a-z][-\w]*)+} => :CLASSNAME, # Require '::' in the class name, else we'd compete with NAME - %r{((::){0,1}[A-Z][-\w]*)+} => :CLASSREF, - "<string>" => :STRING, - "<dqstring up to first interpolation>" => :DQPRE, - "<dqstring between two interpolations>" => :DQMID, - "<dqstring after final interpolation>" => :DQPOST, - "<boolean>" => :BOOLEAN - ) + + TOKENS.add_tokens( + + '[' => :LBRACK, + ']' => :RBRACK, + '{' => :LBRACE, + '}' => :RBRACE, + '(' => :LPAREN, + + ')' => :RPAREN, + '=' => :EQUALS, + '+=' => :APPENDS, + '==' => :ISEQUAL, + '>=' => :GREATEREQUAL, + '>' => :GREATERTHAN, + '<' => :LESSTHAN, + '<=' => :LESSEQUAL, + '!=' => :NOTEQUAL, + '!' => :NOT, + ',' => :COMMA, + '.' => :DOT, + ':' => :COLON, + '@' => :AT, + '<<|' => :LLCOLLECT, + '->' => :IN_EDGE, + '<-' => :OUT_EDGE, + '~>' => :IN_EDGE_SUB, + '<~' => :OUT_EDGE_SUB, + '|>>' => :RRCOLLECT, + '<|' => :LCOLLECT, + '|>' => :RCOLLECT, + ';' => :SEMIC, + '?' => :QMARK, + '\\' => :BACKSLASH, + '=>' => :FARROW, + '+>' => :PARROW, + '+' => :PLUS, + '-' => :MINUS, + '/' => :DIV, + '*' => :TIMES, + '<<' => :LSHIFT, + '>>' => :RSHIFT, + '=~' => :MATCH, + '!~' => :NOMATCH, + %r{([a-z][-\w]*)?(::[a-z][-\w]*)+} => :CLASSNAME, # Require '::' in the class name, else we'd compete with NAME + %r{((::){0,1}[A-Z][-\w]*)+} => :CLASSREF, + "<string>" => :STRING, + "<dqstring up to first interpolation>" => :DQPRE, + "<dqstring between two interpolations>" => :DQMID, + "<dqstring after final interpolation>" => :DQPOST, + "<boolean>" => :BOOLEAN + ) TOKENS.add_token :NUMBER, %r{\b(?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?)\b} do |lexer, value| [TOKENS[:NAME], value] @@ -224,8 +227,8 @@ class Puppet::Parser::Lexer DQ_initial_token_types = {'$' => :DQPRE,'"' => :STRING} DQ_continuation_token_types = {'$' => :DQMID,'"' => :DQPOST} - TOKENS.add_token :DQUOTE, /"/ do |lexer, value| - lexer.tokenize_interpolated_string(DQ_initial_token_types) + TOKENS.add_token :DQUOTE, /"/ do |lexer, value| + lexer.tokenize_interpolated_string(DQ_initial_token_types) end TOKENS.add_token :DQCONT, /\}/ do |lexer, value| @@ -261,23 +264,26 @@ class Puppet::Parser::Lexer KEYWORDS = TokenList.new - KEYWORDS.add_tokens( - "case" => :CASE, - "class" => :CLASS, - "default" => :DEFAULT, - "define" => :DEFINE, - "import" => :IMPORT, - "if" => :IF, - "elsif" => :ELSIF, - "else" => :ELSE, - "inherits" => :INHERITS, - "node" => :NODE, - "and" => :AND, - "or" => :OR, - "undef" => :UNDEF, - "false" => :FALSE, - "true" => :TRUE, - "in" => :IN + + KEYWORDS.add_tokens( + + "case" => :CASE, + "class" => :CLASS, + "default" => :DEFAULT, + "define" => :DEFINE, + "import" => :IMPORT, + "if" => :IF, + "elsif" => :ELSIF, + "else" => :ELSE, + "inherits" => :INHERITS, + "node" => :NODE, + "and" => :AND, + "or" => :OR, + "undef" => :UNDEF, + "false" => :FALSE, + "true" => :TRUE, + + "in" => :IN ) def clear @@ -318,7 +324,7 @@ class Puppet::Parser::Lexer # until we either match or run out of chars. This way our worst-case is three # tries, where it is otherwise the number of string token we have. Also, # the lookups are optimized hash lookups, instead of regex scans. - # + # s = @scanner.peek(3) token = TOKENS.lookup(s[0,3]) || TOKENS.lookup(s[0,2]) || TOKENS.lookup(s[0,1]) [ token, token && @scanner.scan(token.regex) ] @@ -352,7 +358,7 @@ class Puppet::Parser::Lexer end def indefine? - if defined? @indefine + if defined?(@indefine) @indefine else false @@ -380,8 +386,8 @@ class Puppet::Parser::Lexer @expected = [] @commentstack = [ ['', @line] ] @lexing_context = { - :after => nil, - :start_of_line => true, + :after => nil, + :start_of_line => true, :string_interpolation_depth => 0 } end @@ -527,7 +533,7 @@ class Puppet::Parser::Lexer ch else Puppet.warning "Unrecognised escape sequence '\\#{ch}'#{file && " in file #{file}"}#{line && " at line #{line}"}" - "\\#{ch}" + "\\#{ch}" end end } diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 644170f60..e1af32fba 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -214,10 +214,10 @@ class Puppet::Parser::Resource < Puppet::Resource # the database interaction doesn't have to worry about # whether it returns an array or a string. result[p] = if v.is_a?(Array) and v.length == 1 - v[0] - else - v - end + v[0] + else + v + end end result.file = self.file @@ -302,14 +302,14 @@ class Puppet::Parser::Resource < Puppet::Resource # If we've gotten this far, we're allowed to override. - # Merge with previous value, if the parameter was generated with the +> - # syntax. It's important that we use a copy of the new param instance - # here, not the old one, and not the original new one, so that the source - # is registered correctly for later overrides but the values aren't + # Merge with previous value, if the parameter was generated with the +> + # syntax. It's important that we use a copy of the new param instance + # here, not the old one, and not the original new one, so that the source + # is registered correctly for later overrides but the values aren't # implcitly shared when multiple resources are overrriden at once (see # ticket #3556). if param.add - param = param.dup + param = param.dup param.value = [current.value, param.value].flatten end @@ -331,8 +331,7 @@ class Puppet::Parser::Resource < Puppet::Resource params.each do |param| # Don't set the same parameter twice if @parameters[param.name] - self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" % - [param.name, self.to_s] + self.fail Puppet::ParseError, "Duplicate parameter '%s' for on %s" % [param.name, self.to_s] end set_parameter(param) diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb index f44d5a6e9..26b067703 100644 --- a/lib/puppet/parser/resource/param.rb +++ b/lib/puppet/parser/resource/param.rb @@ -1,7 +1,7 @@ require 'puppet/file_collection/lookup' require 'puppet/parser/yaml_trimmer' - # The parameters we stick in Resources. +# The parameters we stick in Resources. class Puppet::Parser::Resource::Param attr_accessor :name, :value, :source, :add include Puppet::Util diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 39317a729..d9ea3cc8f 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -416,8 +416,7 @@ class Puppet::Parser::Scope tmp = ss.scan(/[^\\$]+/) # Puppet.debug("Got other: pos:%d; m:%s" % [ss.pos, tmp]) unless tmp - error = Puppet::ParseError.new("Could not parse string %s" % - string.inspect) + error = Puppet::ParseError.new("Could not parse string %s" % string.inspect) {:file= => file, :line= => line}.each do |m,v| error.send(m, v) if v end @@ -455,7 +454,7 @@ class Puppet::Parser::Scope if level == :all @ephemeral = [ Ephemeral.new ] else - (@ephemeral.size - level).times do + (@ephemeral.size - level).times do @ephemeral.pop end end diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb index 71f0dc084..5f779cb8d 100644 --- a/lib/puppet/parser/type_loader.rb +++ b/lib/puppet/parser/type_loader.rb @@ -15,9 +15,9 @@ class Puppet::Parser::TypeLoader if !self.has_key? item self[item] = { :loader => Thread.current, :busy => self.new_cond} :nobody - elsif self[item][:loader] == Thread.current + elsif self[item][:loader] == Thread.current :this_thread - else + else flag = self[item][:busy] flag.wait flag.signal @@ -79,8 +79,8 @@ class Puppet::Parser::TypeLoader name2files(namespaces, name).each do |filename| modname = nil import_if_possible(filename) do - modname = import(filename) - @loaded << filename + modname = import(filename) + @loaded << filename end if result = yield(filename) Puppet.info "Automatically imported #{name} from #{filename}" @@ -131,14 +131,14 @@ class Puppet::Parser::TypeLoader def import_if_possible(file) return if @loaded.include?(file) begin - case @loading.owner_of(file) - when :this_thread - return - when :another_thread - return import_if_possible(file) - when :nobody - yield - end + case @loading.owner_of(file) + when :this_thread + return + when :another_thread + return import_if_possible(file) + when :nobody + yield + end rescue Puppet::ImportError => detail # We couldn't load the item ensure |