Exception: Kumi::Parser::ParseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/kumi/parser/parse_error.rb

Overview

A syntax error detected during the parse phase — lexing or AST construction — and nothing past it. Parse errors are about shape: an unexpected character, a missing ‘end`, a hash key that isn’t a symbol or string. Anything that needs to know what a name means (types, axes, whether a referenced declaration exists) is a semantic concern and belongs to kumi-core’s analyzer, not here.

The error knows the byte offset where parsing got stuck and a plain-English description of what was expected versus what was found. The Source renders the caret frame; we keep a reference so callers that want a fully formatted message (file:line:col + frame) can get one without re-deriving locations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, source:, offset:) ⇒ ParseError

Returns a new instance of ParseError.



19
20
21
22
23
24
# File 'lib/kumi/parser/parse_error.rb', line 19

def initialize(message, source:, offset:)
  @source = source
  @offset = offset
  @short_message = message
  super(build_message(message))
end

Instance Attribute Details

#offsetObject (readonly)

Returns the value of attribute offset.



17
18
19
# File 'lib/kumi/parser/parse_error.rb', line 17

def offset
  @offset
end

#short_messageObject (readonly)

The bare “what/why” without location or frame — used where a caller wants to compose its own message.



40
41
42
# File 'lib/kumi/parser/parse_error.rb', line 40

def short_message
  @short_message
end

#sourceObject (readonly)

Returns the value of attribute source.



17
18
19
# File 'lib/kumi/parser/parse_error.rb', line 17

def source
  @source
end

Instance Method Details

#columnObject



34
35
36
# File 'lib/kumi/parser/parse_error.rb', line 34

def column
  location.column
end

#lineObject



30
31
32
# File 'lib/kumi/parser/parse_error.rb', line 30

def line
  location.line
end

#locationObject



26
27
28
# File 'lib/kumi/parser/parse_error.rb', line 26

def location
  source.location(offset)
end