Exception: Grammar::Ruby0::Error

Inherits:
Exception
  • Object
show all
Defined in:
lib/grammar/ruby0.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raise = true) ⇒ Error

Returns a new instance of Error.



57
58
59
60
61
62
# File 'lib/grammar/ruby0.rb', line 57

def initialize(raise=true)
    @list = []
    @expected = []
    @consumed = 0
    @raise = raise
end

Instance Attribute Details

#consumedObject (readonly)

Returns the value of attribute consumed.



53
54
55
# File 'lib/grammar/ruby0.rb', line 53

def consumed
  @consumed
end

#expectedObject (readonly)

Returns the value of attribute expected.



54
55
56
# File 'lib/grammar/ruby0.rb', line 54

def expected
  @expected
end

#listObject (readonly)

Returns the value of attribute list.



55
56
57
# File 'lib/grammar/ruby0.rb', line 55

def list
  @list
end

#raiseObject

Returns the value of attribute raise.



56
57
58
# File 'lib/grammar/ruby0.rb', line 56

def raise
  @raise
end

Instance Method Details

#[](expected, found) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/grammar/ruby0.rb', line 63

def [](expected, found)
    @expected << expected if expected
    if @raise
        @list << [@expected, found]
        @expected = []
        Kernel.raise(self)
    end
end

#clearObject



80
81
82
83
84
85
# File 'lib/grammar/ruby0.rb', line 80

def clear
    @consumed += 1
    @raise = true
    @expected.clear
    @list.clear
end

#concat(other) ⇒ Object



76
77
78
79
# File 'lib/grammar/ruby0.rb', line 76

def concat(other)
    @expected.concat(other.expected)
    @list.concat(other.list)
end

#eachObject

:yield: expected, found



86
87
88
89
90
# File 'lib/grammar/ruby0.rb', line 86

def each # :yield: expected, found
    @list.each { |err|
        yield(*err)
    }
end

#noraiseObject



71
72
73
74
75
# File 'lib/grammar/ruby0.rb', line 71

def noraise
    @raise
ensure
    @raise = false
end

#to_sObject



107
108
109
# File 'lib/grammar/ruby0.rb', line 107

def to_s
    to_str
end

#to_strObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/grammar/ruby0.rb', line 91

def to_str
    s = ""
    first = true
    @list.each { |err|
        s.concat(first ? "expected: " : "\nor: ")
        first = true
        err[0].each { |e|
            s << ?| unless first
            s.concat(e.to_s)
            first = false
        }
        s.concat(", found: ").concat(err[1].to_s)
        first = false
    }
    s
end