Class: Ibex::IR::Lexer

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/ir/lexer_ir.rb

Overview

Independently versioned lexer contract embedded by Grammar IR v2.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(states:, rules:, warnings:, schema_version: LEXER_SCHEMA_VERSION, source_provenance: nil) ⇒ Lexer

Returns a new instance of Lexer.

Raises:

  • (ArgumentError)


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

#rulesObject (readonly)

: Array



47
48
49
# File 'lib/ibex/ir/lexer_ir.rb', line 47

def rules
  @rules
end

#schema_versionObject (readonly)

: Integer



49
50
51
# File 'lib/ibex/ir/lexer_ir.rb', line 49

def schema_version
  @schema_version
end

#source_provenanceObject (readonly)

: source_provenance?



50
51
52
# File 'lib/ibex/ir/lexer_ir.rb', line 50

def source_provenance
  @source_provenance
end

#statesObject (readonly)

: Array



46
47
48
# File 'lib/ibex/ir/lexer_ir.rb', line 46

def states
  @states
end

#warningsObject (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_hObject



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