Class: Ibex::IR::Grammar
- Inherits:
-
Object
- Object
- Ibex::IR::Grammar
- Defined in:
- lib/ibex/ir/grammar_ir.rb
Overview
Immutable normalized grammar exchanged between pipeline stages.
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
: String.
-
#conversions ⇒ Object
readonly
: Hash[String, String].
-
#expect ⇒ Object
readonly
: Integer.
-
#expect_rr ⇒ Object
readonly
: Integer?.
-
#grammar_tests ⇒ Object
readonly
: Array.
-
#lexer ⇒ Object
readonly
: Lexer?.
-
#mode ⇒ Object
readonly
: grammar_mode.
-
#options ⇒ Object
readonly
: grammar_options.
-
#parser_contract ⇒ Object
readonly
: ParserContract.
-
#parser_parameters ⇒ Object
readonly
: Array.
-
#productions ⇒ Object
readonly
: Array.
-
#recovery ⇒ Object
readonly
: recovery_policy.
-
#schema_version ⇒ Object
readonly
: Integer.
-
#source_provenance ⇒ Object
readonly
: source_provenance?.
-
#start ⇒ Object
readonly
: String.
-
#starts ⇒ Object
readonly
: Array.
-
#superclass ⇒ Object
readonly
: String?.
-
#symbols ⇒ Object
readonly
: Array.
-
#user_code_chunks ⇒ Object
readonly
: user_code_chunks.
-
#value_printers ⇒ Object
readonly
: Array.
-
#warnings ⇒ Object
readonly
: Array.
Instance Method Summary collapse
-
#initialize(class_name:, superclass:, start:, expect:, options:, symbols:, productions:, user_code:, conversions:, warnings:, user_code_chunks: nil, source_provenance: nil, expect_rr: nil, parser_parameters: [], value_printers: [], grammar_tests: [], recovery: nil, lexer: nil, mode: :default, starts: nil, parser_contract: ParserContract.new) ⇒ Grammar
constructor
rubocop:disable Metrics/AbcSize, Metrics/ParameterLists Immutable current IR is constructed from explicit public fields.
- #nonterminals ⇒ Object
- #symbol(name) ⇒ Object
- #symbol_by_id(id) ⇒ Object
- #terminals ⇒ Object
- #to_h ⇒ Object
- #user_code ⇒ Object
Constructor Details
#initialize(class_name:, superclass:, start:, expect:, options:, symbols:, productions:, user_code:, conversions:, warnings:, user_code_chunks: nil, source_provenance: nil, expect_rr: nil, parser_parameters: [], value_printers: [], grammar_tests: [], recovery: nil, lexer: nil, mode: :default, starts: nil, parser_contract: ParserContract.new) ⇒ Grammar
rubocop:disable Metrics/AbcSize, Metrics/ParameterLists Immutable current IR is constructed from explicit public fields.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ibex/ir/grammar_ir.rb', line 195 def initialize(class_name:, superclass:, start:, expect:, options:, symbols:, productions:, user_code:, conversions:, warnings:, user_code_chunks: nil, source_provenance: nil, expect_rr: nil, parser_parameters: [], value_printers: [], grammar_tests: [], recovery: nil, lexer: nil, mode: :default, starts: nil, parser_contract: ParserContract.new) initialize_current( class_name: class_name, superclass: superclass, start: start, expect: expect, options: , symbols: symbols, productions: productions, user_code: user_code, conversions: conversions, warnings: warnings, user_code_chunks: user_code_chunks, source_provenance: source_provenance, expect_rr: expect_rr, parser_parameters: parser_parameters, value_printers: value_printers, grammar_tests: grammar_tests, recovery: recovery, lexer: lexer, mode: mode, starts: starts, parser_contract: parser_contract ) end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
: String
162 163 164 |
# File 'lib/ibex/ir/grammar_ir.rb', line 162 def class_name @class_name end |
#conversions ⇒ Object (readonly)
: Hash[String, String]
178 179 180 |
# File 'lib/ibex/ir/grammar_ir.rb', line 178 def conversions @conversions end |
#expect ⇒ Object (readonly)
: Integer
167 168 169 |
# File 'lib/ibex/ir/grammar_ir.rb', line 167 def expect @expect end |
#expect_rr ⇒ Object (readonly)
: Integer?
168 169 170 |
# File 'lib/ibex/ir/grammar_ir.rb', line 168 def expect_rr @expect_rr end |
#grammar_tests ⇒ Object (readonly)
: Array
171 172 173 |
# File 'lib/ibex/ir/grammar_ir.rb', line 171 def grammar_tests @grammar_tests end |
#lexer ⇒ Object (readonly)
: Lexer?
172 173 174 |
# File 'lib/ibex/ir/grammar_ir.rb', line 172 def lexer @lexer end |
#mode ⇒ Object (readonly)
: grammar_mode
166 167 168 |
# File 'lib/ibex/ir/grammar_ir.rb', line 166 def mode @mode end |
#options ⇒ Object (readonly)
: grammar_options
174 175 176 |
# File 'lib/ibex/ir/grammar_ir.rb', line 174 def @options end |
#parser_contract ⇒ Object (readonly)
: ParserContract
182 183 184 |
# File 'lib/ibex/ir/grammar_ir.rb', line 182 def parser_contract @parser_contract end |
#parser_parameters ⇒ Object (readonly)
: Array
169 170 171 |
# File 'lib/ibex/ir/grammar_ir.rb', line 169 def parser_parameters @parser_parameters end |
#productions ⇒ Object (readonly)
: Array
176 177 178 |
# File 'lib/ibex/ir/grammar_ir.rb', line 176 def productions @productions end |
#recovery ⇒ Object (readonly)
: recovery_policy
173 174 175 |
# File 'lib/ibex/ir/grammar_ir.rb', line 173 def recovery @recovery end |
#schema_version ⇒ Object (readonly)
: Integer
180 181 182 |
# File 'lib/ibex/ir/grammar_ir.rb', line 180 def schema_version @schema_version end |
#source_provenance ⇒ Object (readonly)
: source_provenance?
181 182 183 |
# File 'lib/ibex/ir/grammar_ir.rb', line 181 def source_provenance @source_provenance end |
#start ⇒ Object (readonly)
: String
164 165 166 |
# File 'lib/ibex/ir/grammar_ir.rb', line 164 def start @start end |
#starts ⇒ Object (readonly)
: Array
165 166 167 |
# File 'lib/ibex/ir/grammar_ir.rb', line 165 def starts @starts end |
#superclass ⇒ Object (readonly)
: String?
163 164 165 |
# File 'lib/ibex/ir/grammar_ir.rb', line 163 def superclass @superclass end |
#symbols ⇒ Object (readonly)
: Array
175 176 177 |
# File 'lib/ibex/ir/grammar_ir.rb', line 175 def symbols @symbols end |
#user_code_chunks ⇒ Object (readonly)
: user_code_chunks
177 178 179 |
# File 'lib/ibex/ir/grammar_ir.rb', line 177 def user_code_chunks @user_code_chunks end |
#value_printers ⇒ Object (readonly)
: Array
170 171 172 |
# File 'lib/ibex/ir/grammar_ir.rb', line 170 def value_printers @value_printers end |
#warnings ⇒ Object (readonly)
: Array
179 180 181 |
# File 'lib/ibex/ir/grammar_ir.rb', line 179 def warnings @warnings end |
Instance Method Details
#nonterminals ⇒ Object
280 |
# File 'lib/ibex/ir/grammar_ir.rb', line 280 def nonterminals = @symbols.select(&:nonterminal?) |
#symbol(name) ⇒ Object
260 |
# File 'lib/ibex/ir/grammar_ir.rb', line 260 def symbol(name) = @symbols_by_name[name] |
#symbol_by_id(id) ⇒ Object
276 277 |
# File 'lib/ibex/ir/grammar_ir.rb', line 276 def symbol_by_id(id) = @symbols_by_id[id] # @rbs () -> Array[GrammarSymbol] |
#terminals ⇒ Object
278 279 |
# File 'lib/ibex/ir/grammar_ir.rb', line 278 def terminals = @symbols.select(&:terminal?) # @rbs () -> Array[GrammarSymbol] |
#to_h ⇒ Object
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/ibex/ir/grammar_ir.rb', line 283 def to_h value = { ibex_ir: "grammar", schema_version: @schema_version, class_name: @class_name, superclass: @superclass, start: @start, expect: @expect, options: @options, symbols: @symbols.map(&:to_h), productions: @productions.map(&:to_h), user_code: user_code, conversions: @conversions, warnings: @warnings } #: Hash[Symbol, Object?] (value) value end |
#user_code ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/ibex/ir/grammar_ir.rb', line 263 def user_code @user_code_names.to_h do |name| code = if @user_code_chunks.key?(name) @user_code_chunks.fetch(name).map(&:code).join else @legacy_user_code.fetch(name) end [name, code] end .freeze end |