Class: ERLE::Term
- Inherits:
-
Object
- Object
- ERLE::Term
- Defined in:
- lib/erle/elements/term.rb
Class Attribute Summary collapse
-
.close ⇒ Object
Returns the value of attribute close.
-
.open ⇒ Object
Returns the value of attribute open.
-
.patterns ⇒ Object
Returns the value of attribute patterns.
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
- .enclosure(one, two = one) ⇒ Object
- .parse(parser) ⇒ Object
- .pattern(p) ⇒ Object
- .to_ruby(value) ⇒ Object
- .until_any_closing ⇒ Object
Instance Method Summary collapse
-
#initialize(input) ⇒ Term
constructor
A new instance of Term.
- #to_ruby ⇒ Object
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
.close ⇒ Object
Returns the value of attribute close.
6 7 8 |
# File 'lib/erle/elements/term.rb', line 6 def close @close end |
.open ⇒ Object
Returns the value of attribute open.
6 7 8 |
# File 'lib/erle/elements/term.rb', line 6 def open @open end |
.patterns ⇒ Object
Returns the value of attribute patterns.
6 7 8 |
# File 'lib/erle/elements/term.rb', line 6 def patterns @patterns end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
9 10 11 |
# File 'lib/erle/elements/term.rb', line 9 def input @input end |
#output ⇒ Object
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 |
Instance Method Details
#to_ruby ⇒ Object
32 33 34 |
# File 'lib/erle/elements/term.rb', line 32 def to_ruby @input end |