Class: Antelope::DSL::Contexts::Main

Inherits:
Base
  • Object
show all
Defined in:
lib/antelope/dsl/contexts/main.rb

Overview

The main context of the Antelope DSL.

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#call, #context, #initialize

Constructor Details

This class inherits a constructor from Antelope::DSL::Contexts::Base

Instance Method Details

#before_callObject (private)



43
44
45
46
47
48
49
# File 'lib/antelope/dsl/contexts/main.rb', line 43

def before_call
  @defines     = {}
  @templates   = {}
  @terminals   = {}
  @precedences = []
  @productions = []
end

#dataObject (private)



51
52
53
54
55
56
57
58
59
# File 'lib/antelope/dsl/contexts/main.rb', line 51

def data
  {
    defines:     @defines,
    templates:   @templates,
    terminals:   @terminals,
    precedences: @precedences,
    productions: @productions
  }
end

#define(pass) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/antelope/dsl/contexts/main.rb', line 6

def define(pass)
  pass.each do |key, value|
    case value
    when Array
      @defines[key] = value
    else
      @defines[key] = [value]
    end
  end
end

#precedences(&block) ⇒ Object



21
22
23
# File 'lib/antelope/dsl/contexts/main.rb', line 21

def precedences(&block)
  @precedences = context(Precedence, &block)
end

#productions(&block) ⇒ Object



25
26
27
# File 'lib/antelope/dsl/contexts/main.rb', line 25

def productions(&block)
  @productions = context(Production, &block)
end

#template(template) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/antelope/dsl/contexts/main.rb', line 29

def template(template)
  case template
  when Hash
    @templates.merge(template)
  when String
    @templates[:default] = template
  else
    raise ArgumentError, "Unexpected #{template.class}, " \
      "expected String or Hash"
  end
end

#terminals(&block) ⇒ Object



17
18
19
# File 'lib/antelope/dsl/contexts/main.rb', line 17

def terminals(&block)
  @terminals.merge! context(Terminal, &block)
end