Exception: Grammar::Ruby0::Error
- Inherits:
-
Exception
- Object
- Exception
- Grammar::Ruby0::Error
- Defined in:
- lib/grammar/ruby0.rb
Instance Attribute Summary collapse
-
#consumed ⇒ Object
readonly
Returns the value of attribute consumed.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#raise ⇒ Object
Returns the value of attribute raise.
Instance Method Summary collapse
- #[](expected, found) ⇒ Object
- #clear ⇒ Object
- #concat(other) ⇒ Object
-
#each ⇒ Object
:yield: expected, found.
-
#initialize(raise = true) ⇒ Error
constructor
A new instance of Error.
- #noraise ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
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
#consumed ⇒ Object (readonly)
Returns the value of attribute consumed.
53 54 55 |
# File 'lib/grammar/ruby0.rb', line 53 def consumed @consumed end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
54 55 56 |
# File 'lib/grammar/ruby0.rb', line 54 def expected @expected end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
55 56 57 |
# File 'lib/grammar/ruby0.rb', line 55 def list @list end |
#raise ⇒ Object
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 |
#clear ⇒ Object
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 |
#each ⇒ Object
: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 |
#noraise ⇒ Object
71 72 73 74 75 |
# File 'lib/grammar/ruby0.rb', line 71 def noraise @raise ensure @raise = false end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/grammar/ruby0.rb', line 107 def to_s to_str end |
#to_str ⇒ Object
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 |