class Grammar

This is the main DSL interface. It builds up grammar rules and sets up the DSL.

Public Class Methods

build(&block) click to toggle source
# File lib/grammar.rb, line 11
def build(&block)
  raise "Must provide a block" unless block_given?
  @rules = {}
  instance_eval &block
end
fail(*args) click to toggle source
# File lib/grammar.rb, line 32
def fail(*args)
  ParserResult.fail(*args)
end
ok(*args) click to toggle source

Aliases for DSL

# File lib/grammar.rb, line 28
def ok(*args)
  ParserResult.ok(*args)
end
rule(name, &wrapper) click to toggle source

Adds or references a new rule

# File lib/grammar.rb, line 18
def rule(name, &wrapper)
  return @rules.fetch(name.to_sym) { raise "Could not find rule: #{name}"} if wrapper.nil?
  @rules[name.to_sym] = Parser.new { |input| wrapper.call.run(input) }
end
start(name) click to toggle source
# File lib/grammar.rb, line 23
def start(name)
  @rules[name]
end