diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2010-04-23 20:41:29 +0200 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 9ddee72e05af79ab7f453b37e9497dca33f7d5ba (patch) | |
tree | bf0a233689c15f54a1c76fd8eb0fe32383233728 | |
parent | a32381e822779b56030f6bd7009cd978970cecd2 (diff) | |
download | puppet-9ddee72e05af79ab7f453b37e9497dca33f7d5ba.tar.gz puppet-9ddee72e05af79ab7f453b37e9497dca33f7d5ba.tar.xz puppet-9ddee72e05af79ab7f453b37e9497dca33f7d5ba.zip |
Fix #3664 - qualified variable parsing in string interpolation
"${myclass::var}" was lexed as a CLASSNAME instead of a VARIABLE token,
giving an error while parsing because a rvalue can't be a bare CLASSNAME
token.
This patch fixes the issue by making VARIABLE lexing higher priority than
CLASSNAME.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
-rw-r--r-- | lib/puppet/parser/lexer.rb | 10 | ||||
-rwxr-xr-x | spec/unit/parser/lexer.rb | 1 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index def462129..c3c53a528 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -108,6 +108,12 @@ class Puppet::Parser::Lexer end TOKENS = TokenList.new + + TOKENS.add_token :VARIABLE, %r{(\w*::)*\w+} + def (TOKENS[:VARIABLE]).acceptable?(context={}) + [:DQPRE,:DQMID].include? context[:after] + end + TOKENS.add_tokens( '[' => :LBRACK, ']' => :RBRACK, @@ -231,10 +237,6 @@ class Puppet::Parser::Lexer [TOKENS[:VARIABLE],value[1..-1]] end - TOKENS.add_token :VARIABLE, %r{(\w*::)*\w+} - def (TOKENS[:VARIABLE]).acceptable?(context={}) - [:DQPRE,:DQMID].include? context[:after] - end TOKENS.sort_tokens diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb index b1524f1e0..204cde759 100755 --- a/spec/unit/parser/lexer.rb +++ b/spec/unit/parser/lexer.rb @@ -413,6 +413,7 @@ describe Puppet::Parser::Lexer,"when lexing strings" do %q["string with an escaped '\\$'"] => [[:STRING,"string with an escaped '$'"]], %q["string with $v (but no braces)"] => [[:DQPRE,"string with "],[:VARIABLE,'v'],[:DQPOST,' (but no braces)']], %q["string with ${v} in braces"] => [[:DQPRE,"string with "],[:VARIABLE,'v'],[:DQPOST,' in braces']], + %q["string with ${qualified::var} in braces"] => [[:DQPRE,"string with "],[:VARIABLE,'qualified::var'],[:DQPOST,' in braces']], %q["string with $v and $v (but no braces)"] => [[:DQPRE,"string with "],[:VARIABLE,"v"],[:DQMID," and "],[:VARIABLE,"v"],[:DQPOST," (but no braces)"]], %q["string with ${v} and ${v} in braces"] => [[:DQPRE,"string with "],[:VARIABLE,"v"],[:DQMID," and "],[:VARIABLE,"v"],[:DQPOST," in braces"]], %q["string with ${'a nested single quoted string'} inside it."] => [[:DQPRE,"string with "],[:STRING,'a nested single quoted string'],[:DQPOST,' inside it.']], |