Module: Ibex::Frontend::Regenerator

Defined in:
lib/ibex/frontend/regenerator.rb

Overview

Builds the committed frontend parser from its canonical Ibex grammar.

Constant Summary collapse

GRAMMAR_PATH =

: String

File.expand_path("grammar.y", File.dirname(__FILE__))
SHADOW_GRAMMAR_PATH =

: String

File.expand_path("shadow_grammar.y", File.dirname(__FILE__))

Class Method Summary collapse

Class Method Details

.generateObject



32
33
34
35
36
37
38
39
40
# File 'lib/ibex/frontend/regenerator.rb', line 32

def generate
  source = File.read(GRAMMAR_PATH)
  ast = BootstrapParser.new(source, file: relative_grammar_path).parse
  grammar = Normalizer.new(ast).normalize
  automaton = LALR::Builder.new(grammar).build
  Codegen::Ruby.new(
    automaton, table: :compact, line_convert: false, runtime_require: nil
  ).generate
end

.generate_shadowObject

Build the non-published parameterized/inline grammar used to verify that preview composition features can describe the production frontend without changing its observable AST.



46
47
48
49
50
51
52
53
54
# File 'lib/ibex/frontend/regenerator.rb', line 46

def generate_shadow
  source = File.read(SHADOW_GRAMMAR_PATH)
  ast = BootstrapParser.new(source, file: relative_shadow_grammar_path, mode: :extended).parse
  grammar = Normalizer.new(ast, mode: :extended).normalize
  automaton = LALR::Builder.new(grammar).build
  Codegen::Ruby.new(
    automaton, table: :compact, line_convert: false, runtime_require: nil
  ).generate
end

.relative_grammar_pathObject



57
58
59
# File 'lib/ibex/frontend/regenerator.rb', line 57

def relative_grammar_path
  "lib/ibex/frontend/grammar.y"
end

.relative_shadow_grammar_pathObject



62
63
64
# File 'lib/ibex/frontend/regenerator.rb', line 62

def relative_shadow_grammar_path
  "lib/ibex/frontend/shadow_grammar.y"
end