summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-02-07 05:58:00 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-02-07 05:58:00 +0000
commit6affe220db1248cee8489347dc7d7ac071a534e4 (patch)
treee885f7ac374336c818374556065da70036b71211 /lib/puppet/parser/ast
parent59c7b02f8fb0c5f2820577f11c9c34935ac16a0a (diff)
downloadpuppet-6affe220db1248cee8489347dc7d7ac071a534e4.tar.gz
puppet-6affe220db1248cee8489347dc7d7ac071a534e4.tar.xz
puppet-6affe220db1248cee8489347dc7d7ac071a534e4.zip
Committing both the finalization of the config code, plus all of the code necessary to get basic isomorphism from code to transportables and back. Mostly keyword and autoname stuff.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@871 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/classdef.rb7
-rw-r--r--lib/puppet/parser/ast/compdef.rb17
-rw-r--r--lib/puppet/parser/ast/component.rb9
-rw-r--r--lib/puppet/parser/ast/node.rb1
-rw-r--r--lib/puppet/parser/ast/nodedef.rb9
-rw-r--r--lib/puppet/parser/ast/objectdef.rb15
6 files changed, 40 insertions, 18 deletions
diff --git a/lib/puppet/parser/ast/classdef.rb b/lib/puppet/parser/ast/classdef.rb
index 7386b25eb..147ab88e5 100644
--- a/lib/puppet/parser/ast/classdef.rb
+++ b/lib/puppet/parser/ast/classdef.rb
@@ -36,9 +36,9 @@ class Puppet::Parser::AST
# [name,args])
begin
- scope.settype(name,
- HostClass.new(arghash)
- )
+ hclass = HostClass.new(arghash)
+ hclass.keyword = self.keyword
+ scope.settype(name, hclass)
rescue Puppet::ParseError => except
except.line = self.line
except.file = self.file
@@ -54,6 +54,7 @@ class Puppet::Parser::AST
def initialize(hash)
@parentclass = nil
+ @keyword = "class"
super
end
diff --git a/lib/puppet/parser/ast/compdef.rb b/lib/puppet/parser/ast/compdef.rb
index 4118c7184..ef099eff8 100644
--- a/lib/puppet/parser/ast/compdef.rb
+++ b/lib/puppet/parser/ast/compdef.rb
@@ -9,7 +9,7 @@ class Puppet::Parser::AST
# encounter an error if the component is instantiated more than
# once.
class CompDef < AST::Branch
- attr_accessor :name, :args, :code
+ attr_accessor :name, :args, :code, :keyword
def each
[@name,@args,@code].each { |child| yield child }
@@ -21,13 +21,13 @@ class Puppet::Parser::AST
args = @args.safeevaluate(scope)
begin
- scope.settype(name,
- AST::Component.new(
- :name => name,
- :args => args,
- :code => @code
- )
+ comp = AST::Component.new(
+ :name => name,
+ :args => args,
+ :code => @code
)
+ comp.keyword = self.keyword
+ scope.settype(name, comp)
rescue Puppet::ParseError => except
except.line = self.line
except.file = self.file
@@ -43,6 +43,9 @@ class Puppet::Parser::AST
def initialize(hash)
@parentclass = nil
+
+ # Set a default keyword
+ @keyword = "define"
super
#Puppet.debug "Defining type %s" % @name.value
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb
index 841977b2f..f5105c44b 100644
--- a/lib/puppet/parser/ast/component.rb
+++ b/lib/puppet/parser/ast/component.rb
@@ -10,7 +10,7 @@ class Puppet::Parser::AST
# The class name
@name = :component
- attr_accessor :name, :args, :code, :scope
+ attr_accessor :name, :args, :code, :scope, :autoname, :keyword
def evaluate(scope,hash,objtype,objname)
@@ -23,6 +23,13 @@ class Puppet::Parser::AST
# been dynamically generated. This is almost never used
scope.name = objname
+ scope.keyword = self.keyword
+
+ # Retain the fact that we were autonamed, if so
+ if self.autoname
+ scope.autoname = true
+ end
+
#if self.is_a?(Node)
# scope.isnodescope
#end
diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb
index 18d7f8aa7..2e33eb672 100644
--- a/lib/puppet/parser/ast/node.rb
+++ b/lib/puppet/parser/ast/node.rb
@@ -16,6 +16,7 @@ class Puppet::Parser::AST
# string.
scope.type = @name
scope.name = @name
+ scope.keyword = @keyword
# Mark this scope as a nodescope, so that classes will be
# singletons within it
diff --git a/lib/puppet/parser/ast/nodedef.rb b/lib/puppet/parser/ast/nodedef.rb
index c0e1ee63e..da93069b2 100644
--- a/lib/puppet/parser/ast/nodedef.rb
+++ b/lib/puppet/parser/ast/nodedef.rb
@@ -3,7 +3,7 @@ class Puppet::Parser::AST
# specified node, and this parse tree is only ever looked up when
# a client connects.
class NodeDef < AST::Branch
- attr_accessor :names, :code, :parentclass
+ attr_accessor :names, :code, :parentclass, :keyword
def each
[@names,@code].each { |child| yield child }
@@ -30,9 +30,9 @@ class Puppet::Parser::AST
end
begin
- scope.setnode(name,
- Node.new(arghash)
- )
+ node = Node.new(arghash)
+ node.keyword = true
+ scope.setnode(name, node)
rescue Puppet::ParseError => except
except.line = self.line
except.file = self.file
@@ -48,6 +48,7 @@ class Puppet::Parser::AST
def initialize(hash)
@parentclass = nil
+ @keyword = "node"
super
end
diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb
index 844b7a71d..dc355be77 100644
--- a/lib/puppet/parser/ast/objectdef.rb
+++ b/lib/puppet/parser/ast/objectdef.rb
@@ -52,7 +52,7 @@ class Puppet::Parser::AST
self.typecheck(objtype)
end
- # See if our object was defined
+ # See if our object type was defined
begin
object = scope.lookuptype(objtype)
rescue Puppet::ParseError => except
@@ -81,11 +81,13 @@ class Puppet::Parser::AST
end
+ autonamed = false
# Autogenerate the name if one was not passed.
if defined? @name
objnames = @name.safeevaluate(scope)
else
objnames = self.autoname(objtype, object)
+ autonamed = true
end
# it's easier to always use an array, even for only one name
@@ -106,7 +108,8 @@ class Puppet::Parser::AST
# if someone passed an array as the name, then we act
# just like the called us many times
objnames.collect { |objname|
- # If the object is a class, that means it's a builtin type
+ # If the object is a class, that means it's a builtin type, so
+ # we just store it in the scope
if object.is_a?(Class)
begin
#Puppet.debug(
@@ -138,7 +141,13 @@ class Puppet::Parser::AST
# one of those, evaluate that with our arguments
#Puppet.debug("Calling object '%s' with arguments %s" %
# [object.name, hash.inspect])
- object.safeevaluate(scope,hash,objtype,objname)
+ obj = object.safeevaluate(scope,hash,objtype,objname)
+
+ # Retain any name generation stuff
+ obj.autoname = autonamed
+
+ # and pass the result on
+ obj
end
}.reject { |obj| obj.nil? }
end