Class: Ibex::Frontend::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/frontend/resolver.rb

Overview

Loads an explicit root grammar and resolves its extended-mode fragment graph.

Constant Summary collapse

GLOB_CHARACTERS =

: Regexp

/[*?\[\]{}]/
WINDOWS_ABSOLUTE =

: Regexp

%r{\A(?:[A-Za-z]:[\\/]|\\\\)}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, mode: :default, loader: SourceLoader.new) ⇒ Resolver

Returns a new instance of Resolver.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
# File 'lib/ibex/frontend/resolver.rb', line 27

def initialize(path, mode: :default, loader: SourceLoader.new)
  raise ArgumentError, "mode must be :default or :extended" unless %i[default extended].include?(mode)

  @input_path = path
  @mode = mode
  @loader = loader
  @attempted_paths = [File.expand_path(path)]
end

Instance Attribute Details

#attempted_pathsObject (readonly)



24
25
26
# File 'lib/ibex/frontend/resolver.rb', line 24

def attempted_paths
  @attempted_paths
end

Instance Method Details

#dependenciesObject



58
59
60
# File 'lib/ibex/frontend/resolver.rb', line 58

def dependencies
  resolve.files
end

#resolveObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ibex/frontend/resolver.rb', line 37

def resolve
  cached = @resolution
  return cached if cached

  prepare_resolution
  parsed_root = parse_root(@root_path)
  declarations, rules = expand_node(parsed_root, [])
  root = AST::Root.new(
    class_name: parsed_root.class_name, superclass: parsed_root.superclass,
    declarations: declarations, rules: rules, user_code: parsed_root.user_code, loc: parsed_root.loc,
    extended: parsed_root.extended, cst: parsed_root.cst
  )
  @loaded[@root_path] = true
  @visiting.pop
  @resolution = Resolution.new(
    root: root, root_path: @root_path, root_directory: @root_directory,
    files: @files, include_chains: @include_chains
  )
end

#source_recordsObject

Source bytes actually consumed by the parser, in resolution order.



64
65
66
# File 'lib/ibex/frontend/resolver.rb', line 64

def source_records
  @loader.read_records
end