Class: IDL::Scanner::In
- Inherits:
-
Object
- Object
- IDL::Scanner::In
- Defined in:
- lib/ridl/scanner.rb
Overview
Position
Instance Method Summary collapse
- #_include?(ch, *chars) ⇒ Boolean
- #column ⇒ Object
- #getc ⇒ Object (also: #skipc)
- #getregion ⇒ Object
- #gets ⇒ Object
-
#initialize(src, name = '', line = 0, column = 1) ⇒ In
constructor
A new instance of In.
- #lookc ⇒ Object
- #mark(*ini) ⇒ Object
- #position ⇒ Object
- #skipuntil(*chars, &block) ⇒ Object
- #skipwhile(*chars, &block) ⇒ Object
-
#to_s ⇒ Object
cursor set at last gotten character.
Constructor Details
Instance Method Details
#_include?(ch, *chars) ⇒ Boolean
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ridl/scanner.rb', line 100 def _include?(ch, *chars) chars.each { |v| return true if case v when Array _include?(ch, *v) when Enumerable v.include? ch when Fixnum v == ch when String v == ch else false end } false end |
#column ⇒ Object
54 55 56 |
# File 'lib/ridl/scanner.rb', line 54 def column @pos.column end |
#getc ⇒ Object Also known as: skipc
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ridl/scanner.rb', line 65 def getc cur = @fwd @fwd = @src.getc unless @src.nil? @mark << cur unless @mark.nil? if [nil, ?\n, ?\r].include? @bwd if @bwd == ?\r and cur == ?\n else @pos.line += 1 @pos.column = 1 end else @pos.column += 1 end if false if not @bwd.nil? or cur.nil? or @fwd.nil? printf("%c(%02x), %c(%02x), %c(%02x) @(l:%d,c:%d)\n", @bwd,@bwd,cur,cur,@fwd,@fwd, @pos.line, @pos.column) end end @bwd = cur end |
#getregion ⇒ Object
157 158 159 160 161 |
# File 'lib/ridl/scanner.rb', line 157 def getregion ret = @mark @mark = nil ret end |
#gets ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ridl/scanner.rb', line 88 def gets return nil if @fwd.nil? s = '' s << getc until [nil, ?\n, ?\r].include? lookc s << getc while [?\n, ?\r].include? lookc @mark << s unless @mark.nil? s end |
#lookc ⇒ Object
61 62 63 |
# File 'lib/ridl/scanner.rb', line 61 def lookc @fwd end |
#mark(*ini) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ridl/scanner.rb', line 142 def mark(*ini) @mark = '' ini.each { |i| case i when nil when String @mark << i.dup when Fixnum @mark << i when Array i.each { |j| @mark << j } # array of array is not incoming. end } end |
#position ⇒ Object
51 52 53 |
# File 'lib/ridl/scanner.rb', line 51 def position @pos end |
#skipuntil(*chars, &block) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ridl/scanner.rb', line 130 def skipuntil(*chars, &block) if block.nil? block = Proc.new { |ch| _include?(ch, *chars) } end until (ch = lookc).nil? break if block.call(ch) skipc end ch end |
#skipwhile(*chars, &block) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ridl/scanner.rb', line 118 def skipwhile(*chars, &block) if block.nil? block = Proc.new { |ch| _include?(ch, *chars) } end until (ch = lookc).nil? break unless block.call(ch) skipc end ch end |
#to_s ⇒ Object
cursor set at last gotten character. ex: after initialization, position is (0,0).
59 |
# File 'lib/ridl/scanner.rb', line 59 def to_s; @src.to_s; end |