Class: Ibex::IR::Lexer
- Inherits:
-
Object
- Object
- Ibex::IR::Lexer
- Defined in:
- lib/ibex/ir/lexer_ir.rb,
sig/ibex/ir/lexer_ir.rbs
Overview
Independently versioned lexer contract embedded by Grammar IR v2.
Instance Attribute Summary collapse
- #rules ⇒ Array[LexerRule] readonly
- #schema_version ⇒ Integer readonly
- #source_provenance ⇒ source_provenance? readonly
- #states ⇒ Array[String] readonly
- #warnings ⇒ Array[Hash[Symbol, untyped]] readonly
Instance Method Summary collapse
-
#initialize(states:, rules:, warnings:, schema_version: LEXER_SCHEMA_VERSION, source_provenance: nil) ⇒ Lexer
constructor
A new instance of Lexer.
- #to_h ⇒ Hash[Symbol, untyped]
Constructor Details
#initialize(states:, rules:, warnings:, schema_version: LEXER_SCHEMA_VERSION, source_provenance: nil) ⇒ Lexer
Returns a new instance of Lexer.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ibex/ir/lexer_ir.rb', line 54 def initialize(states:, rules:, warnings:, schema_version: LEXER_SCHEMA_VERSION, source_provenance: nil) raise ArgumentError, "lexer states must start with INITIAL" unless states.first == "INITIAL" raise ArgumentError, "lexer states must be unique" unless states.uniq.length == states.length @states = states.map(&:freeze).freeze @rules = rules.freeze @warnings = IR.deep_freeze(warnings) @schema_version = schema_version @source_provenance = IR.deep_freeze(source_provenance) freeze end |
Instance Attribute Details
#rules ⇒ Array[LexerRule] (readonly)
47 48 49 |
# File 'lib/ibex/ir/lexer_ir.rb', line 47 def rules @rules end |
#schema_version ⇒ Integer (readonly)
49 50 51 |
# File 'lib/ibex/ir/lexer_ir.rb', line 49 def schema_version @schema_version end |
#source_provenance ⇒ source_provenance? (readonly)
50 51 52 |
# File 'lib/ibex/ir/lexer_ir.rb', line 50 def source_provenance @source_provenance end |
#states ⇒ Array[String] (readonly)
46 47 48 |
# File 'lib/ibex/ir/lexer_ir.rb', line 46 def states @states end |
#warnings ⇒ Array[Hash[Symbol, untyped]] (readonly)
48 49 50 |
# File 'lib/ibex/ir/lexer_ir.rb', line 48 def warnings @warnings end |
Instance Method Details
#to_h ⇒ Hash[Symbol, untyped]
67 68 69 70 71 72 73 |
# File 'lib/ibex/ir/lexer_ir.rb', line 67 def to_h { ibex_ir: "lexer", schema_version: @schema_version, initial_state: "INITIAL", states: @states, rules: @rules.map(&:to_h), warnings: @warnings, source_provenance: @source_provenance } end |