diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/grammar.ra | 7 | ||||
-rw-r--r-- | lib/puppet/parser/lexer.rb | 32 | ||||
-rw-r--r-- | lib/puppet/parser/parser.rb | 11 |
3 files changed, 48 insertions, 2 deletions
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index c8130ccf0..2d09c9671 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -655,6 +655,9 @@ end # Raise a Parse error. def error(message) + if brace = @lexer.expected + message += "; expected '%s'" + end except = Puppet::ParseError.new(message) except.line = @lexer.line if @lexer.file @@ -758,6 +761,10 @@ def on_error(token,value,stack) # [@lexer.line,@lexer.last] error = "Syntax error at '%s'" % [value] + if brace = @lexer.expected + error += "; expected '%s'" % brace + end + except = Puppet::ParseError.new(error) except.line = @lexer.line if @lexer.file 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 diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 236bd390f..e52d53faa 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..id3bb0c917f5', 'grammar.ra', 608 +module_eval <<'..end grammar.ra modeval..idec1116a64f', 'grammar.ra', 608 require 'puppet/parser/functions' attr_reader :file, :interp @@ -80,6 +80,9 @@ end # Raise a Parse error. def error(message) + if brace = @lexer.expected + message += "; expected '%s'" + end except = Puppet::ParseError.new(message) except.line = @lexer.line if @lexer.file @@ -183,6 +186,10 @@ def on_error(token,value,stack) # [@lexer.line,@lexer.last] error = "Syntax error at '%s'" % [value] + if brace = @lexer.expected + error += "; expected '%s'" % brace + end + except = Puppet::ParseError.new(error) except.line = @lexer.line if @lexer.file @@ -254,7 +261,7 @@ end # $Id$ -..end grammar.ra modeval..id3bb0c917f5 +..end grammar.ra modeval..idec1116a64f ##### racc 1.4.5 generates ### |