Module: EBNF::BNF

Included in:
Base
Defined in:
lib/ebnf/bnf.rb

Instance Method Summary collapse

Instance Method Details

#make_bnfENBF

Transform EBNF Rule set to BNF:

  • Add rule [0] (_empty rule (seq))

  • Transform each rule into a set of rules that are just BNF, using Rule#to_bnf.

Returns:

  • (ENBF)

    self



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ebnf/bnf.rb', line 9

def make_bnf
  progress("make_bnf") {"Start: #{@ast.length} rules"}
  new_ast = [Rule.new(:_empty, "0", [:seq], kind: :rule)]

  ast.each do |rule|
    debug("make_bnf") {"expand from: #{rule.inspect}"}
    new_rules = rule.to_bnf
    debug(" => ") {new_rules.map(&:sym).join(', ')}
    new_ast += new_rules
  end

  @ast = new_ast
  progress("make_bnf") {"End: #{@ast.length} rules"}
  self
end