Class: Kumi::Parser::Parser

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

Overview

Recursive-descent parser for declarations and a Pratt parser for expressions, producing kumi-core’s Kumi::Syntax::* AST directly.

The parser is the boundary of the parse phase: it reports shape errors (a missing ‘end`, an unexpected token, a malformed hash pair) with exact locations, and it does not attempt to resolve names, check types, or know anything about axes — those are semantic concerns owned by the analyzer.

Instance Method Summary collapse

Constructor Details

#initialize(tokens, source) ⇒ Parser

Returns a new instance of Parser.



15
16
17
18
19
20
# File 'lib/kumi/parser/parser.rb', line 15

def initialize(tokens, source)
  @tokens = tokens
  @source = source
  @pos = 0
  @imported_names = Set.new
end

Instance Method Details

#parseObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kumi/parser/parser.rb', line 22

def parse
  skip_separators
  imports = parse_imports
  @imported_names.merge(imports.flat_map(&:names))

  root = parse_schema(imports)

  skip_separators
  expect(:eof, 'end of input')
  root
end