Module: Temple::Mixins::GrammarDSL Private

Included in:
Grammar
Defined in:
lib/temple/mixins/grammar_dsl.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

API:

  • private

Defined Under Namespace

Classes: Element, Or, Root, Rule, Value

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



167
168
169
# File 'lib/temple/mixins/grammar_dsl.rb', line 167

def const_missing(name)
  const_set(name, Root.new(self, name))
end

#extended(mod) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



116
117
118
119
120
121
# File 'lib/temple/mixins/grammar_dsl.rb', line 116

def extended(mod)
  mod.extend GrammarDSL
  constants.each do |name|
    const_get(name).copy_to(mod) if Rule === const_get(name)
  end
end

#match?(exp) ⇒ Boolean Also known as: ===, =~

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



123
124
125
# File 'lib/temple/mixins/grammar_dsl.rb', line 123

def match?(exp)
  const_get(:Expression).match?(exp)
end

#Rule(rule) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/temple/mixins/grammar_dsl.rb', line 137

def Rule(rule)
  case rule
  when Rule
    rule
  when Symbol, Class, true, false, nil
    Value(rule)
  when Array
    start = Or.new(self)
    curr = [start]
    rule.each do |elem|
      case elem
      when /^(.*)(\*|\?|\+)$/
        elem = Element.new(self, const_get($1))
        curr.each {|c| c << elem }
        elem << elem if $2 != '?'
        curr = $2 == '+' ? [elem] : (curr << elem)
      else
        elem = Element.new(self, elem)
        curr.each {|c| c << elem }
        curr = [elem]
      end
    end
    elem = Value([])
    curr.each {|c| c << elem }
    start
  else
    raise ArgumentError, "Invalid grammar rule '#{rule.inspect}'"
  end
end

#validate!(exp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



129
130
131
# File 'lib/temple/mixins/grammar_dsl.rb', line 129

def validate!(exp)
  const_get(:Expression).validate!(exp)
end

#Value(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



133
134
135
# File 'lib/temple/mixins/grammar_dsl.rb', line 133

def Value(value)
  Value.new(self, value)
end