Class: Ibex::IR::Lexer
- Inherits:
-
Object
- Object
- Ibex::IR::Lexer
- Defined in:
- lib/ibex/ir/lexer_ir.rb
Overview
Independently versioned lexer contract embedded by Grammar IR v2.
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
: Array.
-
#schema_version ⇒ Object
readonly
: Integer.
-
#source_provenance ⇒ Object
readonly
: source_provenance?.
-
#states ⇒ Object
readonly
: Array.
-
#warnings ⇒ Object
readonly
: Array[Hash[Symbol, untyped]].
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 ⇒ Object
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 ⇒ Object (readonly)
: Array
47 48 49 |
# File 'lib/ibex/ir/lexer_ir.rb', line 47 def rules @rules end |
#schema_version ⇒ Object (readonly)
: Integer
49 50 51 |
# File 'lib/ibex/ir/lexer_ir.rb', line 49 def schema_version @schema_version end |
#source_provenance ⇒ Object (readonly)
: source_provenance?
50 51 52 |
# File 'lib/ibex/ir/lexer_ir.rb', line 50 def source_provenance @source_provenance end |
#states ⇒ Object (readonly)
: Array
46 47 48 |
# File 'lib/ibex/ir/lexer_ir.rb', line 46 def states @states end |
#warnings ⇒ Object (readonly)
: Array[Hash[Symbol, untyped]]
48 49 50 |
# File 'lib/ibex/ir/lexer_ir.rb', line 48 def warnings @warnings end |
Instance Method Details
#to_h ⇒ Object
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 |