diff options
Diffstat (limited to 'lib/puppet/parser/lexer.rb')
-rw-r--r-- | lib/puppet/parser/lexer.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 9fc1f9a38..daa75f236 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -54,6 +54,16 @@ module Puppet %r{\$(\w*::)*\w+} => :VARIABLE } + @@pairs = { + "{" => "}", + "(" => ")", + "[" => "]", + "<|" => "|>", + "<<|" => "|>>" + } + + @@reverse_pairs = @@pairs.inject({}) { |hash, pair| hash[pair[1]] = pair[0]; hash } + @@keywords = { "case" => :CASE, "class" => :CLASS, @@ -76,6 +86,20 @@ module Puppet initvars end + def expected + if @expected.empty? + nil + else + token = @expected[-1] + @@tokens.each do |value, name| + if token == name + return value + end + end + return token + end + end + # scan the whole file # basically just used for testing def fullscan @@ -130,6 +154,8 @@ module Puppet @namestack = [] @indefine = false + + @expected = [] end # Go up one in the namespace. @@ -247,6 +273,12 @@ module Puppet value = value.sub(/^\$/, '') end + if match = @@pairs[value] and ptoken != :DQUOTE and ptoken != :SQUOTE + @expected << match + elsif exp = @expected[-1] and exp == value and ptoken != :DQUOTE and ptoken != :SQUOTE + @expected.pop + end + yield [ptoken, value] if @lasttoken == :CLASS |