diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-25 00:31:28 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-05-25 00:31:28 +0000 |
commit | 62a4d4c91df2aa6e7a6f28dfdf81f95f28987216 (patch) | |
tree | 324aaf518981a1c6d4bf75b54c2119a82d76c0cf /lib/puppet | |
parent | 2b372df7038a268eee31372f62e8cf6be989b09e (diff) | |
download | puppet-62a4d4c91df2aa6e7a6f28dfdf81f95f28987216.tar.gz puppet-62a4d4c91df2aa6e7a6f28dfdf81f95f28987216.tar.xz puppet-62a4d4c91df2aa6e7a6f28dfdf81f95f28987216.zip |
Adding better error reporting on unmatched brackets -- you will now get notification of what was expected in most cases
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2531 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-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 ### |