lib/wlang/parser.rb in wlang-0.8.4 vs lib/wlang/parser.rb in wlang-0.8.5
- old
+ new
@@ -134,10 +134,12 @@
# Evaluates a ruby expression on the current context.
# See WLang::Parser::Context#evaluate.
#
def evaluate(expression)
@context.evaluate(expression)
+ rescue Exception => ex
+ raise ::WLang::EvalError, "#{template.where(@offset)} evaluation of '#{expression}' failed", ex.backtrace
end
#
# Launches a child parser for instantiation at a given _offset_ in given
# _dialect_ (same dialect than self if dialect is nil) and with an output
@@ -197,30 +199,36 @@
raise(ParseError,"Unknown encoder: #{encoder}")
end
encoder.encode(src, options)
end
+ # Raises an exception with a friendly message
+ def error(offset, message)
+ template.error(offset, message)
+ end
+
#
# Raises a ParseError at a given offset.
#
def syntax_error(offset, msg=nil)
text = self.parse(offset, "wlang/dummy", "")
- raise ParseError, "Parse error at #{offset} on '#{text}': #{msg}"
+ msg = msg.nil? ? '' : ": #{msg}"
+ template.parse_error(offset, "parse error on '#{text}'#{msg}")
end
#
# Raises a ParseError at a given offset for a missing block
#
def block_missing_error(offset)
- raise ParseError.new("Block expected", offset, @source_text)
+ template.parse_error(offset, "parse error, block was expected")
end
#
# Raises a ParseError at a given offset for a unexpected EOF
# specif. the expected character when EOF found
#
def unexpected_eof(offset, expected)
- raise ParseError.new("'#{expected}' expected, EOF found.", offset, @source_text)
+ template.parse_error(offset, "#{expected} expected, EOF found")
end
#
# Puts a key/value pair in the current context. See Parser::Context::define
# for details.