Class: ERLE::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/erle/elements/term.rb

Direct Known Subclasses

Atom, Enum, Number, Pid, Ref, String

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Term

Returns a new instance of Term.



28
29
30
# File 'lib/erle/elements/term.rb', line 28

def initialize(input)
  @input = input
end

Class Attribute Details

.closeObject

Returns the value of attribute close.



6
7
8
# File 'lib/erle/elements/term.rb', line 6

def close
  @close
end

.openObject

Returns the value of attribute open.



6
7
8
# File 'lib/erle/elements/term.rb', line 6

def open
  @open
end

.patternsObject

Returns the value of attribute patterns.



6
7
8
# File 'lib/erle/elements/term.rb', line 6

def patterns
  @patterns
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



9
10
11
# File 'lib/erle/elements/term.rb', line 9

def input
  @input
end

#outputObject

Returns the value of attribute output.



10
11
12
# File 'lib/erle/elements/term.rb', line 10

def output
  @output
end

Class Method Details

.enclosure(one, two = one) ⇒ Object



22
23
24
25
26
# File 'lib/erle/elements/term.rb', line 22

def self.enclosure(one, two=one)
  @open = one.freeze
  @close = two.freeze
  ERLE::Registry.enclosure(self, one, two)
end

.parse(parser) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/erle/elements/term.rb', line 49

def self.parse(parser)

  patterns.find do |pattern|
    parser.scan(pattern)
  end

  result = parser.matched

  if close && !parser.scan(close)
    raise parser.raise_unexpected_token("Expected term closure \" #{close.source} \"")
  end

  # # Make sure we kill any trailing close
  # # TODO: Consider raising if no match?
  # # TODO: Consider doing only if we started with an opening...
  # parser.scan(ERLE::Registry.closings_regex)
  # # binding.pry
  new(result)
end

.pattern(p) ⇒ Object



17
18
19
20
# File 'lib/erle/elements/term.rb', line 17

def self.pattern(p)
  patterns.add(p)
  ERLE::Registry.pattern(self, p)
end

.to_ruby(value) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/erle/elements/term.rb', line 36

def self.to_ruby(value)
  case value
  when Term
    value.to_ruby
  else
    value
  end
end

.until_any_closingObject



45
46
47
# File 'lib/erle/elements/term.rb', line 45

def self.until_any_closing
  @until_any_closing ||= Regexp.new("[^#{ERLE::Registry.closings_regex.source}]*")
end

Instance Method Details

#to_rubyObject



32
33
34
# File 'lib/erle/elements/term.rb', line 32

def to_ruby
  @input
end