class Chem::ParseException

Overview

Exception thrown upon parsing issues. Primarly used by PullParser.

It can hold the location of the issue found in a text document. Call #inspect_with_location to print a human-friendly error showing such information.

ex = ParseException.new(
  message: "Invalid letters",
  path: "path/to/file",
  line: "abc def 123456 ABC DEF",
  location: {247, 8, 6}
)
puts ex.inspect_with_location

Prints out:

Found a parsing issue in path/to/file:

 247 | abc def 123456 ABC DEF
               ^^^^^^
Error: Invalid letters

Defined in:

chem.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(message : String, source_file : String | Nil, line : String, location : Tuple(Int32, Int32, Int32)) #

Creates a new exception with location, which is a triplet containing line number, column number (starting at zero), and cursor size. The latter may be zero to represent the beginning (column number = 0) or end of line.


[View source]
def self.new(message : String) #

Creates a new exception without location.


[View source]

Instance Method Detail

def inspect_with_location(io : IO) : Nil #

Writes a string representation of the error including the location to io.


[View source]
def inspect_with_location : String #

Returns a string representation of the error including the location.


[View source]
def line : String | Nil #

Line (if any) where the issue was found.


[View source]
def location : Tuple(Int32, Int32, Int32) | Nil #

Error location (if any). It is a triplet containing line number, column number, and cursor size where the issue is located.


[View source]
def source_file : String | Nil #

Path to file (if any) that produced the error.


[View source]