Class: Ibex::IR::Lexer

Inherits:
Object
  • Object
show all
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

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.

RBS:

  • (states: Array[String], rules: Array[LexerRule], warnings: Array[Hash[Symbol, untyped]], ?schema_version: Integer, ?source_provenance: source_provenance?) -> void

Parameters:

  • states: (Array[String])
  • rules: (Array[LexerRule])
  • warnings: (Array[Hash[Symbol, untyped]])
  • schema_version: (Integer) (defaults to: LEXER_SCHEMA_VERSION)
  • source_provenance: (source_provenance, nil) (defaults to: nil)


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

#rulesArray[LexerRule] (readonly)

Signature:

  • Array[LexerRule]

Returns:



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

def rules
  @rules
end

#schema_versionInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def schema_version
  @schema_version
end

#source_provenancesource_provenance? (readonly)

Signature:

  • source_provenance?

Returns:



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

def source_provenance
  @source_provenance
end

#statesArray[String] (readonly)

Signature:

  • Array[String]

Returns:

  • (Array[String])


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

def states
  @states
end

#warningsArray[Hash[Symbol, untyped]] (readonly)

Signature:

  • Array[Hash[Symbol, untyped]]

Returns:

  • (Array[Hash[Symbol, untyped]])


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

def warnings
  @warnings
end

Instance Method Details

#to_hHash[Symbol, untyped]

RBS:

  • () -> Hash[Symbol, untyped]

Returns:

  • (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