lib/gobstones/cli/runner.rb in gobstones-0.0.1.1 vs lib/gobstones/cli/runner.rb in gobstones-0.0.2
- old
+ new
@@ -21,10 +21,12 @@
def run
print_program_result parse_program.evaluate
rescue Gobstones::Parser::ParseError => parse_error
handle_parse_error parse_error
+ rescue Gobstones::Runner::GobstonesTypeError => type_error
+ handle_type_error type_error
rescue Exception => e
# TODO handle more gobstones exceptions
raise e
end
@@ -33,20 +35,24 @@
def print_program_result(context)
Printer.new(context).print
end
def parse_program
- @parser.parse(@code)
+ @parser.parse @code
end
def handle_parse_error(parse_error)
parse_error.parser.failure_reason =~ /^(Expected .+) after/m
puts "#{$1.gsub("\n", '$NEWLINE')}:"
puts parse_error.code.lines.to_a[parse_error.parser.failure_line - 1]
puts "#{'~' * (parse_error.parser.failure_column - 1)}^"
end
+ def handle_type_error(type_error)
+ puts "Type Error: #{type_error.message} occurred in #{type_error.statement}"
+ end
+
end
end
-end
\ No newline at end of file
+end