diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2008-11-15 13:10:55 +0100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-11-17 21:05:36 +1100 |
commit | 064fb006a350e9555abe766c5cb4aeb803fd623a (patch) | |
tree | e9dd550404cb84a4a9c11d08560c9408bbba6f40 /lib/puppet/parser/parser_support.rb | |
parent | 724a6f672308ab6f52d738caf20c5994e6225071 (diff) | |
download | puppet-064fb006a350e9555abe766c5cb4aeb803fd623a.tar.gz puppet-064fb006a350e9555abe766c5cb4aeb803fd623a.tar.xz puppet-064fb006a350e9555abe766c5cb4aeb803fd623a.zip |
Add a doc attribute to AST nodes and fill it with the last seen comments
The lexer maintains a stack of last seen comments.
On blank lines the lexer flush the comments.
On each opening brace the lexer enters a new stack level.
On each block AST nodes, the stack is popped.
Each AST nodes has a doc property that is filled with the
last seen comments on node creation (in fact only on important node
creation representing statements).
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/parser_support.rb')
-rw-r--r-- | lib/puppet/parser/parser_support.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index 1583973a7..d59093799 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -18,6 +18,7 @@ class Puppet::Parser::Parser attr_reader :version, :environment attr_accessor :files + attr_accessor :lexer # Add context to a message; useful for error messages and such. def addcontext(message, obj = nil) @@ -56,7 +57,9 @@ class Puppet::Parser::Parser end end - return klass.new(hash) + k = klass.new(hash) + k.doc = lexer.getcomment if !k.nil? and k.use_docs and k.doc.empty? + return k end # The fully qualifed name, with the full namespace. @@ -272,6 +275,7 @@ class Puppet::Parser::Parser end code = options[:code] parent = options[:parent] + doc = options[:doc] # If the class is already defined, then add code to it. if other = @astset.classes[name] @@ -304,6 +308,12 @@ class Puppet::Parser::Parser other.code ||= code end end + + if other.doc and doc + other.doc += doc + else + other.doc ||= doc + end else # Define it anew. # Note we're doing something somewhat weird here -- we're setting @@ -312,6 +322,8 @@ class Puppet::Parser::Parser args = {:namespace => name, :classname => name, :parser => self} args[:code] = code if code args[:parentclass] = parent if parent + args[:doc] = doc + @astset.classes[name] = ast AST::HostClass, args end @@ -336,7 +348,8 @@ class Puppet::Parser::Parser :arguments => options[:arguments], :code => options[:code], :parser => self, - :classname => name + :classname => name, + :doc => options[:doc] } [:code, :arguments].each do |param| @@ -350,6 +363,7 @@ class Puppet::Parser::Parser # table, not according to namespaces. def newnode(names, options = {}) names = [names] unless names.instance_of?(Array) + doc = lexer.getcomment names.collect do |name| name = name.to_s.downcase if other = @astset.nodes[name] @@ -358,7 +372,8 @@ class Puppet::Parser::Parser name = name.to_s if name.is_a?(Symbol) args = { :name => name, - :parser => self + :parser => self, + :doc => doc } if options[:code] args[:code] = options[:code] @@ -399,6 +414,7 @@ class Puppet::Parser::Parser self.string = string end begin + @yydebug = false main = yyparse(@lexer,:scan) rescue Racc::ParseError => except error = Puppet::ParseError.new(except) |