diff options
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/ast/classdef.rb | 7 | ||||
-rw-r--r-- | lib/puppet/parser/ast/compdef.rb | 17 | ||||
-rw-r--r-- | lib/puppet/parser/ast/component.rb | 9 | ||||
-rw-r--r-- | lib/puppet/parser/ast/node.rb | 1 | ||||
-rw-r--r-- | lib/puppet/parser/ast/nodedef.rb | 9 | ||||
-rw-r--r-- | lib/puppet/parser/ast/objectdef.rb | 15 | ||||
-rw-r--r-- | lib/puppet/parser/grammar.ra | 6 | ||||
-rw-r--r-- | lib/puppet/parser/parser.rb | 44 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 12 |
9 files changed, 82 insertions, 38 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 diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 3630d27ef..bd32f2c5b 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -483,6 +483,7 @@ definition: DEFINE NAME argumentlist LBRACE statements RBRACE { :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] ) } | DEFINE NAME argumentlist LBRACE RBRACE { @@ -491,6 +492,7 @@ definition: DEFINE NAME argumentlist LBRACE statements RBRACE { :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -506,6 +508,7 @@ hostclass: CLASS NAME parent LBRACE statements RBRACE { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] } # It'll be an ASTArray if we didn't get a parent @@ -518,6 +521,7 @@ hostclass: CLASS NAME parent LBRACE statements RBRACE { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -543,6 +547,7 @@ nodedef: NODE names parent LBRACE statements RBRACE { :file => @lexer.file, :line => @lexer.line, :names => val[1], + :keyword => val[0], :code => val[4] } if val[2].is_a?(AST::Name) @@ -560,6 +565,7 @@ nodedef: NODE names parent LBRACE statements RBRACE { args = { :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :names => val[1], :code => AST::ASTArray.new( :line => @lexer.line, diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 582283704..43fa51119 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -29,7 +29,7 @@ module Puppet class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..idc16574e75e', 'grammar.ra', 697 +module_eval <<'..end grammar.ra modeval..id3b98377f5e', 'grammar.ra', 703 attr_reader :file attr_accessor :files @@ -144,7 +144,7 @@ def string=(string) end # $Id$ -..end grammar.ra modeval..idc16574e75e +..end grammar.ra modeval..id3b98377f5e ##### racc 1.4.4 generates ### @@ -1162,26 +1162,28 @@ module_eval <<'.,.,', 'grammar.ra', 478 end .,., -module_eval <<'.,.,', 'grammar.ra', 488 +module_eval <<'.,.,', 'grammar.ra', 489 def _reduce_71( val, _values, result ) result = AST::CompDef.new( :name => AST::Name.new(:value => val[1], :line => @lexer.line), :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] ) result end .,., -module_eval <<'.,.,', 'grammar.ra', 500 +module_eval <<'.,.,', 'grammar.ra', 502 def _reduce_72( val, _values, result ) result = AST::CompDef.new( :name => AST::Name.new(:value => val[1], :line => @lexer.line), :args => val[2], :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -1192,13 +1194,14 @@ module_eval <<'.,.,', 'grammar.ra', 500 end .,., -module_eval <<'.,.,', 'grammar.ra', 516 +module_eval <<'.,.,', 'grammar.ra', 519 def _reduce_73( val, _values, result ) #:args => val[2], args = { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => val[4] } # It'll be an ASTArray if we didn't get a parent @@ -1210,12 +1213,13 @@ module_eval <<'.,.,', 'grammar.ra', 516 end .,., -module_eval <<'.,.,', 'grammar.ra', 532 +module_eval <<'.,.,', 'grammar.ra', 536 def _reduce_74( val, _values, result ) args = { :name => AST::Name.new(:value => val[1], :line => @lexer.line), :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :code => AST::ASTArray.new( :line => @lexer.line, :file => @lexer.file, @@ -1231,7 +1235,7 @@ module_eval <<'.,.,', 'grammar.ra', 532 end .,., -module_eval <<'.,.,', 'grammar.ra', 552 +module_eval <<'.,.,', 'grammar.ra', 557 def _reduce_75( val, _values, result ) unless val[1].is_a?(AST::ASTArray) val[1] = AST::ASTArray.new( @@ -1244,6 +1248,7 @@ module_eval <<'.,.,', 'grammar.ra', 552 :file => @lexer.file, :line => @lexer.line, :names => val[1], + :keyword => val[0], :code => val[4] } if val[2].is_a?(AST::Name) @@ -1254,7 +1259,7 @@ module_eval <<'.,.,', 'grammar.ra', 552 end .,., -module_eval <<'.,.,', 'grammar.ra', 574 +module_eval <<'.,.,', 'grammar.ra', 580 def _reduce_76( val, _values, result ) unless val[1].is_a?(AST::ASTArray) val[1] = AST::ASTArray.new( @@ -1266,6 +1271,7 @@ module_eval <<'.,.,', 'grammar.ra', 574 args = { :file => @lexer.file, :line => @lexer.line, + :keyword => val[0], :names => val[1], :code => AST::ASTArray.new( :line => @lexer.line, @@ -1283,7 +1289,7 @@ module_eval <<'.,.,', 'grammar.ra', 574 # reduce 77 omitted -module_eval <<'.,.,', 'grammar.ra', 588 +module_eval <<'.,.,', 'grammar.ra', 594 def _reduce_78( val, _values, result ) if val[0].is_a?(AST::ASTArray) result = val[0] @@ -1299,7 +1305,7 @@ module_eval <<'.,.,', 'grammar.ra', 588 end .,., -module_eval <<'.,.,', 'grammar.ra', 596 +module_eval <<'.,.,', 'grammar.ra', 602 def _reduce_79( val, _values, result ) result = AST::ASTArray.new( :line => @lexer.line, @@ -1312,14 +1318,14 @@ module_eval <<'.,.,', 'grammar.ra', 596 # reduce 80 omitted -module_eval <<'.,.,', 'grammar.ra', 601 +module_eval <<'.,.,', 'grammar.ra', 607 def _reduce_81( val, _values, result ) result = val[1] result end .,., -module_eval <<'.,.,', 'grammar.ra', 612 +module_eval <<'.,.,', 'grammar.ra', 618 def _reduce_82( val, _values, result ) if val[1].is_a?(AST::ASTArray) result = val[1] @@ -1336,7 +1342,7 @@ module_eval <<'.,.,', 'grammar.ra', 612 # reduce 83 omitted -module_eval <<'.,.,', 'grammar.ra', 626 +module_eval <<'.,.,', 'grammar.ra', 632 def _reduce_84( val, _values, result ) if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) @@ -1352,7 +1358,7 @@ module_eval <<'.,.,', 'grammar.ra', 626 end .,., -module_eval <<'.,.,', 'grammar.ra', 634 +module_eval <<'.,.,', 'grammar.ra', 640 def _reduce_85( val, _values, result ) result = AST::CompArgument.new( :line => @lexer.line, @@ -1363,7 +1369,7 @@ module_eval <<'.,.,', 'grammar.ra', 634 end .,., -module_eval <<'.,.,', 'grammar.ra', 641 +module_eval <<'.,.,', 'grammar.ra', 647 def _reduce_86( val, _values, result ) result = AST::CompArgument.new( :line => @lexer.line, @@ -1376,7 +1382,7 @@ module_eval <<'.,.,', 'grammar.ra', 641 # reduce 87 omitted -module_eval <<'.,.,', 'grammar.ra', 650 +module_eval <<'.,.,', 'grammar.ra', 656 def _reduce_88( val, _values, result ) result = AST::Name.new( :value => val[1], @@ -1387,7 +1393,7 @@ module_eval <<'.,.,', 'grammar.ra', 650 end .,., -module_eval <<'.,.,', 'grammar.ra', 659 +module_eval <<'.,.,', 'grammar.ra', 665 def _reduce_89( val, _values, result ) name = val[0].sub(/^\$/,'') result = AST::Variable.new( @@ -1399,7 +1405,7 @@ module_eval <<'.,.,', 'grammar.ra', 659 end .,., -module_eval <<'.,.,', 'grammar.ra', 671 +module_eval <<'.,.,', 'grammar.ra', 677 def _reduce_90( val, _values, result ) if val[1].is_a?(AST::ASTArray) result = val[1] @@ -1420,7 +1426,7 @@ module_eval <<'.,.,', 'grammar.ra', 671 # reduce 93 omitted -module_eval <<'.,.,', 'grammar.ra', 676 +module_eval <<'.,.,', 'grammar.ra', 682 def _reduce_94( val, _values, result ) result = nil result diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 9392d6cf9..3e88490e3 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -8,7 +8,9 @@ module Puppet class Scope include Enumerable attr_accessor :parent, :level, :interp - attr_accessor :name, :type, :topscope, :base + attr_accessor :name, :type, :topscope, :base, :keyword, :autoname + + attr_accessor :top # This is probably not all that good of an idea, but... # This way a parent can share its tables with all of its children. @@ -210,6 +212,9 @@ module Puppet objects.classes = nodescope.classlist end + if objects.is_a?(Puppet::TransBucket) + objects.top = true + end # I should do something to add the node as an object with tags # but that will possibly end up with far too many tags. #self.logtags @@ -262,6 +267,7 @@ module Puppet } objects = self.to_trans + objects.top = true # Add our class list unless self.classlist.empty? @@ -733,6 +739,10 @@ module Puppet raise Puppet::ParseError, "No type for scope %s" % @name end + + if defined? @keyword + bucket.keyword = @keyword + end #Puppet.debug( # "TransBucket with name %s and type %s in scope %s" % # [@name,@type,self.object_id] |