Class: Ibex::IR::ParserContract
- Inherits:
-
Object
- Object
- Ibex::IR::ParserContract
- Defined in:
- lib/ibex/ir/parser_contract.rb,
sig/ibex/ir/parser_contract.rbs
Overview
Root-owned parser configuration persisted by the current Grammar IR.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- DEFINITIONS =
{ algorithm: { configuration: "parser.algorithm", values: %i[slr lalr ielr lr1].freeze }.freeze, entries: { configuration: "parser.entries", values: %i[shared isolated].freeze }.freeze, cst_trivia: { configuration: "cst.trivia", values: %i[leading balanced drop].freeze }.freeze }.freeze
Instance Attribute Summary collapse
- #algorithm ⇒ Entry readonly
- #cst_trivia ⇒ Entry readonly
- #entries ⇒ Entry readonly
Instance Method Summary collapse
-
#configuration_locations ⇒ Hash[String, Location]
Source locations supplied to the typed resolver.
-
#configuration_values ⇒ Hash[String, Symbol]
Values supplied to the typed resolver; unspecified fields are absent.
-
#initialize(algorithm: nil, entries: nil, cst_trivia: nil) ⇒ ParserContract
constructor
A new instance of ParserContract.
- #normalize_entry(key, entry) ⇒ Entry
- #specified_entries ⇒ Array[Entry]
- #to_h ⇒ Hash[Symbol, Hash[Symbol, entry_value]]
Constructor Details
#initialize(algorithm: nil, entries: nil, cst_trivia: nil) ⇒ ParserContract
Returns a new instance of ParserContract.
84 85 86 87 88 89 |
# File 'lib/ibex/ir/parser_contract.rb', line 84 def initialize(algorithm: nil, entries: nil, cst_trivia: nil) @algorithm = normalize_entry(:algorithm, algorithm) @entries = normalize_entry(:entries, entries) @cst_trivia = normalize_entry(:cst_trivia, cst_trivia) freeze end |
Instance Attribute Details
#algorithm ⇒ Entry (readonly)
79 80 81 |
# File 'lib/ibex/ir/parser_contract.rb', line 79 def algorithm @algorithm end |
#cst_trivia ⇒ Entry (readonly)
81 82 83 |
# File 'lib/ibex/ir/parser_contract.rb', line 81 def cst_trivia @cst_trivia end |
#entries ⇒ Entry (readonly)
80 81 82 |
# File 'lib/ibex/ir/parser_contract.rb', line 80 def entries @entries end |
Instance Method Details
#configuration_locations ⇒ Hash[String, Location]
Source locations supplied to the typed resolver.
111 112 113 114 115 116 |
# File 'lib/ibex/ir/parser_contract.rb', line 111 def configuration_locations specified_entries.to_h do |entry| location = entry.location || raise("explicit parser contract entry is missing its location") [DEFINITIONS.fetch(entry.key).fetch(:configuration), location] end end |
#configuration_values ⇒ Hash[String, Symbol]
Values supplied to the typed resolver; unspecified fields are absent.
102 103 104 105 106 107 |
# File 'lib/ibex/ir/parser_contract.rb', line 102 def configuration_values specified_entries.to_h do |entry| value = entry.value || raise("explicit parser contract entry is missing its value") [DEFINITIONS.fetch(entry.key).fetch(:configuration), value] end end |
#normalize_entry(key, entry) ⇒ Entry
121 122 123 124 125 126 127 |
# File 'lib/ibex/ir/parser_contract.rb', line 121 def normalize_entry(key, entry) entry ||= Entry.new(key) raise ArgumentError, "#{key} must be a ParserContract::Entry" unless entry.is_a?(Entry) raise ArgumentError, "#{key} entry has key #{entry.key.inspect}" unless entry.key == key entry end |
#specified_entries ⇒ Array[Entry]
130 131 132 |
# File 'lib/ibex/ir/parser_contract.rb', line 130 def specified_entries [@algorithm, @entries, @cst_trivia].select(&:explicit) end |
#to_h ⇒ Hash[Symbol, Hash[Symbol, entry_value]]
92 93 94 95 96 97 98 |
# File 'lib/ibex/ir/parser_contract.rb', line 92 def to_h { algorithm: @algorithm.to_h, entries: @entries.to_h, cst_trivia: @cst_trivia.to_h } end |