summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-23 20:42:08 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-09-23 20:42:08 +0000
commit8211df036e1d2d24e1084616fc3fc4891b06cfdd (patch)
tree597f8b999cf5210a7ceff5ef1e1977f1de08c241 /lib/puppet/parser
parentd20ac8e0b564e5413d571f2059de559e0783b72d (diff)
downloadpuppet-8211df036e1d2d24e1084616fc3fc4891b06cfdd.tar.gz
puppet-8211df036e1d2d24e1084616fc3fc4891b06cfdd.tar.xz
puppet-8211df036e1d2d24e1084616fc3fc4891b06cfdd.zip
Many, many changes toward a completely functional system. The only current problems with my home config are that apache's stupid init script does not do status and that packages are not working as non-root users (which makes sense).
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@703 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/ast.rb8
-rw-r--r--lib/puppet/parser/grammar.ra37
-rw-r--r--lib/puppet/parser/interpreter.rb30
-rw-r--r--lib/puppet/parser/parser.rb41
-rw-r--r--lib/puppet/parser/scope.rb17
5 files changed, 75 insertions, 58 deletions
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index 7fa1a156d..602067436 100644
--- a/lib/puppet/parser/ast.rb
+++ b/lib/puppet/parser/ast.rb
@@ -239,6 +239,10 @@ module Puppet
# meant completely different things.
class ObjectInst < ASTArray; end
+ # Another simple container class to make sure we can correctly arrayfy
+ # things.
+ class CompArgument < ASTArray; end
+
# The base class for all of the leaves of the parse trees. These
# basically just have types and values. Both of these parameters
# are simple values, not AST objects.
@@ -1289,8 +1293,10 @@ module Puppet
# arguments...
self.args.each { |arg, default|
unless hash.include?(arg)
- if defined? default
+ if defined? default and ! default.nil?
hash[arg] = default
+ Puppet.debug "Got default %s for %s in %s" %
+ [default.inspect, arg.inspect, objname.inspect]
else
error = Puppet::ParseError.new(
"Must pass %s to %s of type %s" %
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index 78fb9aa47..5fe801e15 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -25,18 +25,18 @@ program: statements {
# this is mainly so we can test the parser separately from the
# interpreter
- if Puppet[:parseonly]
- begin
- if Puppet[:debug]
- puts result.tree(0)
- end
- rescue NoMethodError => detail
- Puppet.err detail
- #exit(78)
- end
- #require 'puppet/parser/interpreter'
- #result = Puppet::Server.new(result)
- end
+# if Puppet[:parseonly]
+# begin
+# if Puppet[:debug]
+# puts result.tree(0)
+# end
+# rescue NoMethodError => detail
+# Puppet.err detail
+# #exit(78)
+# end
+# #require 'puppet/parser/interpreter'
+# #result = Puppet::Server.new(result)
+# end
}
statements: statement
@@ -447,7 +447,7 @@ import: IMPORT QTEXT {
Dir.chdir(dir) {
Dir.glob(val[1]).each { |file|
parser = Puppet::Parser::Parser.new()
- parser.stack = self.stack
+ parser.files = self.files
Puppet.debug("importing '%s'" % file)
begin
parser.file = file
@@ -554,7 +554,7 @@ argumentlist: nothing
arguments: argument
| arguments COMMA argument {
- if val[0].is_a?(AST::ASTArray)
+ if val[0].instance_of?(AST::ASTArray)
val[0].push(val[2])
result = val[0]
else
@@ -567,14 +567,14 @@ arguments: argument
}
argument: name EQUALS rvalue {
- result = AST::ASTArray.new(
+ result = AST::CompArgument.new(
:line => @lexer.line,
:file => @lexer.file,
:children => [val[0],val[2]]
)
}
| name {
- result = AST::ASTArray.new(
+ result = AST::CompArgument.new(
:line => @lexer.line,
:file => @lexer.file,
:children => [val[0]]
@@ -635,14 +635,15 @@ Puppet[:typecheck] = true
Puppet[:paramcheck] = true
---- inner ----
-attr_reader :file, :files
+attr_reader :file
+attr_accessor :files
# Create an AST array out of all of the args
def aryfy(*args)
if args[0].is_a?(AST::ASTArray)
result = args.shift
args.each { |arg|
- args.push arg
+ result.push arg
}
else
result = AST::ASTArray.new(
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index cd7ac46d6..e076bc1ca 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -45,15 +45,19 @@ module Puppet
if @usenodes
unless client
raise Puppet::Error,
- "Cannot evaluate no nodes with a nil client"
+ "Cannot evaluate nodes with a nil client"
end
# We've already evaluated the AST, in this case
- @scope.evalnode(names, facts)
+ retval = @scope.evalnode(names, facts)
+ return retval
else
+ # We've already evaluated the AST, in this case
@scope = Puppet::Parser::Scope.new() # no parent scope
@scope.interp = self
- @scope.evaluate(@ast, facts)
+ @scope.type = "puppet"
+ @scope.name = "top"
+ return @scope.evaluate(@ast, facts)
end
#@ast.evaluate(@scope)
rescue Puppet::DevError, Puppet::Error, Puppet::ParseError => except
@@ -82,14 +86,14 @@ module Puppet
# to pass to the client
# this will be heirarchical, and will (at this point) contain
# only TransObjects and TransSettings
- @scope.name = "top"
- @scope.type = "puppet"
- begin
- topbucket = @scope.to_trans
- rescue => detail
- Puppet.warning detail
- raise
- end
+ #@scope.name = "top"
+ #@scope.type = "puppet"
+ #begin
+ # topbucket = @scope.to_trans
+ #rescue => detail
+ # Puppet.warning detail
+ # raise
+ #end
# add our settings to the front of the array
# at least, for now
@@ -104,7 +108,7 @@ module Puppet
#retlist = TransObject.list
#Puppet.debug "retobject length is %s" % retlist.length
#TransObject.clear
- return topbucket
+ #return topbucket
end
def scope
@@ -120,6 +124,8 @@ module Puppet
if @usenodes
@scope = Puppet::Parser::Scope.new() # no parent scope
+ @scope.name = "top"
+ @scope.type = "puppet"
@scope.interp = self
Puppet.debug "Nodes defined"
@ast.safeevaluate(@scope)
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index df92e9c2e..733de138c 100644
--- a/lib/puppet/parser/parser.rb
+++ b/lib/puppet/parser/parser.rb
@@ -32,15 +32,16 @@ module Puppet
class Parser < Racc::Parser
-module_eval <<'..end grammar.ra modeval..id4705e629f1', 'grammar.ra', 638
-attr_reader :file, :files
+module_eval <<'..end grammar.ra modeval..idb211ea7fd3', 'grammar.ra', 638
+attr_reader :file
+attr_accessor :files
# Create an AST array out of all of the args
def aryfy(*args)
if args[0].is_a?(AST::ASTArray)
result = args.shift
args.each { |arg|
- args.push arg
+ result.push arg
}
else
result = AST::ASTArray.new(
@@ -144,7 +145,7 @@ end
def string=(string)
@lexer.string = string
end
-..end grammar.ra modeval..id4705e629f1
+..end grammar.ra modeval..idb211ea7fd3
##### racc 1.4.4 generates ###
@@ -561,18 +562,18 @@ module_eval <<'.,.,', 'grammar.ra', 40
# this is mainly so we can test the parser separately from the
# interpreter
- if Puppet[:parseonly]
- begin
- if Puppet[:debug]
- puts result.tree(0)
- end
- rescue NoMethodError => detail
- Puppet.err detail
- #exit(78)
- end
- #require 'puppet/parser/interpreter'
- #result = Puppet::Server.new(result)
- end
+# if Puppet[:parseonly]
+# begin
+# if Puppet[:debug]
+# puts result.tree(0)
+# end
+# rescue NoMethodError => detail
+# Puppet.err detail
+# #exit(78)
+# end
+# #require 'puppet/parser/interpreter'
+# #result = Puppet::Server.new(result)
+# end
result
end
.,.,
@@ -1118,7 +1119,7 @@ module_eval <<'.,.,', 'grammar.ra', 469
Dir.chdir(dir) {
Dir.glob(val[1]).each { |file|
parser = Puppet::Parser::Parser.new()
- parser.stack = self.stack
+ parser.files = self.files
Puppet.debug("importing '%s'" % file)
begin
parser.file = file
@@ -1252,7 +1253,7 @@ module_eval <<'.,.,', 'grammar.ra', 553
module_eval <<'.,.,', 'grammar.ra', 567
def _reduce_80( val, _values, result )
- if val[0].is_a?(AST::ASTArray)
+ if val[0].instance_of?(AST::ASTArray)
val[0].push(val[2])
result = val[0]
else
@@ -1268,7 +1269,7 @@ module_eval <<'.,.,', 'grammar.ra', 567
module_eval <<'.,.,', 'grammar.ra', 575
def _reduce_81( val, _values, result )
- result = AST::ASTArray.new(
+ result = AST::CompArgument.new(
:line => @lexer.line,
:file => @lexer.file,
:children => [val[0],val[2]]
@@ -1279,7 +1280,7 @@ module_eval <<'.,.,', 'grammar.ra', 575
module_eval <<'.,.,', 'grammar.ra', 582
def _reduce_82( val, _values, result )
- result = AST::ASTArray.new(
+ result = AST::CompArgument.new(
:line => @lexer.line,
:file => @lexer.file,
:children => [val[0]]
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 3730af606..054a0e7b7 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -128,6 +128,7 @@ module Puppet
# it will be removed during translation.
# And now return the whole thing
+ #return self.to_trans
return self.to_trans
end
@@ -485,8 +486,8 @@ module Puppet
# Convert our scope to a list of Transportable objects.
def to_trans
- Puppet.debug "Translating scope %s at level %s" %
- [self.object_id,self.level]
+ #Puppet.debug "Translating scope %s at level %s" %
+ # [self.object_id,self.level]
results = []
@@ -494,8 +495,8 @@ module Puppet
@children.each { |child|
if child.is_a?(Scope)
cresult = child.to_trans
- Puppet.debug "Got %s from scope %s" %
- [cresult.class,child.object_id]
+ #Puppet.debug "Got %s from scope %s" %
+ # [cresult.class,child.object_id]
# Scopes normally result in a TransBucket, but they could
# also result in a normal array; if that happens, get rid
@@ -553,8 +554,10 @@ module Puppet
error.stack = caller
raise error
end
- Puppet.debug "TransBucket with name %s and type %s in scope %s" %
- [@name,@type,self.object_id]
+ #Puppet.debug(
+ # "TransBucket with name %s and type %s in scope %s" %
+ # [@name,@type,self.object_id]
+ #)
# now find metaparams
@symtable.each { |var,value|
@@ -569,7 +572,7 @@ module Puppet
# [bucket.name,self.object_id]
return bucket
else
- #Puppet.debug "nameless scope; just returning a list"
+ Puppet.debug "nameless scope; just returning a list"
return results
end
end