diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-06-28 14:12:59 +0200 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-07-10 10:57:38 +1000 |
commit | faefd92c78f69580204c40179f3f0b766b0208fb (patch) | |
tree | 72c7c6e580e32d094126df532eaacc4195b3ccc7 /lib/puppet/parser/parser_support.rb | |
parent | 869ec273a085c1fa28da14bfd627ffc24af87a07 (diff) | |
download | puppet-faefd92c78f69580204c40179f3f0b766b0208fb.tar.gz puppet-faefd92c78f69580204c40179f3f0b766b0208fb.tar.xz puppet-faefd92c78f69580204c40179f3f0b766b0208fb.zip |
Make sure the parser sees the correct line number
Careful inspection of the parser code show that when we
associate a source line number for an AST node, we use the
current line number of the currently lexed token.
In many case, this is correct, but there are some cases where
this is incorrect.
Unfortunately due to how LALR parser works the ast node creation
of a statement can appear _after_ we lexed another token after
the current statement:
1. $foo = 1
2.
3. class test
When the parser asks for the class token, it can reduce the
assignement statement into the AST VarDef node, because no other
grammar rule match. Unfortunately we already lexed the class token
so we affect to the VarDef node the line number 3 instead of 1.
This is not a real issue for error reporting, but becomes a real
concern when we associate documentation comments to AST node for
puppetdoc.
The solution is to enhance the tokens lexed and returned to the parser
to carry their declaration line number.
Thus a token value becomes a hash: { :value => tokenvalue, :line }
Next, each time we create an AST node, we use the line number of
the correct token (ie the foo line number in the previous example).
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 | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index a7a980a0c..92db9af5f 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -310,6 +310,7 @@ class Puppet::Parser::Parser args[:code] = code if code args[:parentclass] = parent if parent args[:doc] = doc + args[:line] = options[:line] @loaded_code.add_hostclass(name, ast(AST::HostClass, args)) end @@ -336,7 +337,8 @@ class Puppet::Parser::Parser :code => options[:code], :parser => self, :classname => name, - :doc => options[:doc] + :doc => options[:doc], + :line => options[:line] } [:code, :arguments].each do |param| @@ -360,7 +362,8 @@ class Puppet::Parser::Parser args = { :name => name, :parser => self, - :doc => doc + :doc => doc, + :line => options[:line] } if options[:code] args[:code] = options[:code] |