Exception: TSJSON::TSJSONSyntaxError
- Inherits:
-
StandardError
- Object
- StandardError
- TSJSON::TSJSONSyntaxError
- Defined in:
- lib/language/lexer/syntax_error.rb
Instance Attribute Summary collapse
-
#locations ⇒ Object
Returns the value of attribute locations.
-
#message ⇒ Object
Returns the value of attribute message.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#originalError ⇒ Object
Returns the value of attribute originalError.
-
#path ⇒ Object
Returns the value of attribute path.
-
#positions ⇒ Object
Returns the value of attribute positions.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, nodes, source, positions, path = nil, originalError = nil) ⇒ TSJSONSyntaxError
constructor
A new instance of TSJSONSyntaxError.
- #to_s ⇒ Object
- #toJSON ⇒ Object
Constructor Details
#initialize(message, nodes, source, positions, path = nil, originalError = nil) ⇒ TSJSONSyntaxError
Returns a new instance of TSJSONSyntaxError.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/language/lexer/syntax_error.rb', line 13 def initialize( , nodes, source, positions, path = nil, originalError = nil ) self. = _nodes = if nodes.is_a?(Array) nodes.length != 0 ? nodes : nil else nodes ? [nodes] : nil end # Compute locations in the source for the given nodes/positions. _source = source _source = _nodes[0].loc&.source if (!_source && _nodes) _positions = positions if (!_positions && _nodes) _positions = _nodes.reduce([]) do |list, node| list.push(node.loc.start) if (node.loc) return list end end _positions = undefined if (_positions && _positions.length === 0) if (positions && source) _locations = positions.map { |pos| Location.get_location(source, pos) } elsif (_nodes) _locations = _nodes.reduce([]) do |list, node| if (node.loc) list.push( Location.get_location(node.loc.source, node.loc.start_pos) ) end return list end end self.source = _source self.positions = _positions self.locations = _locations self.nodes = _nodes end |
Instance Attribute Details
#locations ⇒ Object
Returns the value of attribute locations.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def locations @locations end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def @message end |
#nodes ⇒ Object
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def nodes @nodes end |
#originalError ⇒ Object
Returns the value of attribute originalError.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def originalError @originalError end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def path @path end |
#positions ⇒ Object
Returns the value of attribute positions.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def positions @positions end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/language/lexer/syntax_error.rb', line 5 def source @source end |
Class Method Details
.print_error(error) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/language/lexer/syntax_error.rb', line 60 def self.print_error(error) output = error. if (error.nodes) error.nodes.each do |node| output += "\n\n" + printLocation(node.loc) if (node.loc) end elsif (error.source && error.locations) error.locations.each do |location| output += "\n\n" + Source.print_source_location(error.source, location) end end return output end |
.syntax_error(source, position, description) ⇒ Object
77 78 79 |
# File 'lib/language/lexer/syntax_error.rb', line 77 def self.syntax_error(source, position, description) return new("Syntax Error: #{description}", nil, source, [position]) end |
Instance Method Details
#to_s ⇒ Object
85 86 87 |
# File 'lib/language/lexer/syntax_error.rb', line 85 def to_s return TSJSONSyntaxError.print_error(self) end |
#toJSON ⇒ Object
81 82 83 |
# File 'lib/language/lexer/syntax_error.rb', line 81 def toJSON return { message: self., locations: self.locations } end |