Class: Rubber::CRScanner
- Inherits:
-
Object
- Object
- Rubber::CRScanner
- Defined in:
- lib/rubber/scanner.rb
Instance Attribute Summary collapse
-
#allocs ⇒ Object
readonly
Returns the value of attribute allocs.
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#current_file ⇒ Object
readonly
Returns the value of attribute current_file.
-
#defs ⇒ Object
readonly
Returns the value of attribute defs.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#inc_dirs ⇒ Object
readonly
Returns the value of attribute inc_dirs.
-
#incs ⇒ Object
readonly
Returns the value of attribute incs.
-
#lib_dirs ⇒ Object
readonly
Returns the value of attribute lib_dirs.
-
#libs ⇒ Object
readonly
Returns the value of attribute libs.
-
#nested_functions ⇒ Object
readonly
Returns the value of attribute nested_functions.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pkgs ⇒ Object
readonly
Returns the value of attribute pkgs.
-
#post_init_code ⇒ Object
readonly
Returns the value of attribute post_init_code.
-
#pre_init_code ⇒ Object
readonly
Returns the value of attribute pre_init_code.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #_scan(fp) ⇒ Object
- #current_line ⇒ Object
-
#initialize(file) ⇒ CRScanner
constructor
A new instance of CRScanner.
- #misc_error(message, show_location = true) ⇒ Object
- #scan(fp) ⇒ Object
- #scan_args ⇒ Object
- #syntax_error(message) ⇒ Object
Constructor Details
#initialize(file) ⇒ CRScanner
Returns a new instance of CRScanner.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubber/scanner.rb', line 23 def initialize(file) @file = file @ext = File::basename(file).gsub(/\..*$/, '') @nested_functions = {} @functions = {} @modules = {} @classes = {} @calls = [] @allocs = [] @options = Options.new # Default settings @options.glib= true @options.gtk= true @options.gnu= false @current_file = file end |
Instance Attribute Details
#allocs ⇒ Object (readonly)
Returns the value of attribute allocs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def allocs @allocs end |
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def calls @calls end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def classes @classes end |
#current_file ⇒ Object (readonly)
Returns the value of attribute current_file.
39 40 41 |
# File 'lib/rubber/scanner.rb', line 39 def current_file @current_file end |
#defs ⇒ Object (readonly)
Returns the value of attribute defs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def defs @defs end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def doc @doc end |
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def ext @ext end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def file @file end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def functions @functions end |
#inc_dirs ⇒ Object (readonly)
Returns the value of attribute inc_dirs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def inc_dirs @inc_dirs end |
#incs ⇒ Object (readonly)
Returns the value of attribute incs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def incs @incs end |
#lib_dirs ⇒ Object (readonly)
Returns the value of attribute lib_dirs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def lib_dirs @lib_dirs end |
#libs ⇒ Object (readonly)
Returns the value of attribute libs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def libs @libs end |
#nested_functions ⇒ Object (readonly)
Returns the value of attribute nested_functions.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def nested_functions @nested_functions end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/rubber/scanner.rb', line 22 def @options end |
#pkgs ⇒ Object (readonly)
Returns the value of attribute pkgs.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def pkgs @pkgs end |
#post_init_code ⇒ Object (readonly)
Returns the value of attribute post_init_code.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def post_init_code @post_init_code end |
#pre_init_code ⇒ Object (readonly)
Returns the value of attribute pre_init_code.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def pre_init_code @pre_init_code end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def raw @raw end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
21 22 23 |
# File 'lib/rubber/scanner.rb', line 21 def stack @stack end |
#state ⇒ Object
Returns the value of attribute state.
67 68 69 |
# File 'lib/rubber/scanner.rb', line 67 def state @state end |
Instance Method Details
#_scan(fp) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/rubber/scanner.rb', line 80 def _scan(fp) @lines = IO.readlines(@file) @str = StringScanner.new(@string = @lines.join) tokens = [] @state = ScanState.new(0,0,false,0) @stack = [C_RootModule.new] func = nil until @str.empty? ######## Doc if @str.skip(/=begin([ \t][^\n]*)?\n/) # skip =begin/=end blocks lines = @str.scan_until(/\n=end([ \t].*)?/).split("\n") lines.pop if state.in_func (func.doc ||= "") << lines.join("\n") elsif @class and not @class.kind_of?(C_RootModule) (@class.doc ||= "") << lines.join("\n") else (@doc ||= "") << lines.join("\n") end ######## Config elsif @str.skip(/%\{/) # Scan raw raw = @str.scan_until(/%\}/) raw[-2..-1] = "" (@raw ||= "") << raw elsif @str.skip(/%pre_init\{/) # Scan raw raw = @str.scan_until(/%\}/) raw[-2..-1] = "" (@pre_init_code ||= "") << raw elsif @str.skip(/%post_init\{/) # Scan raw raw = @str.scan_until(/%\}/) raw[-2..-1] = "" (@post_init_code ||= "") << raw elsif @str.skip(/\s+/) # skip func.text += " " if state.in_func elsif @str.skip(/%name */) # Extension name @ext = @str.scan(/[a-zA-Z0-9]+/) elsif @str.skip(/%min-version */) @version = @str.scan(/([0-9]+)\.([0-9]+)\.([0-9]+)/) version = [1,2,3].map{|i|@str[i].to_i} Rubber::VERSION.each_with_index do |ver,idx| if ver < version[idx] misc_error "This version of rubber-generate (#{Rubber::VERSION}) is too old: #{@file} requires version #{version.map{|i|i.to_s}.join('.')}", false end end elsif @str.skip(/%pkg-config\s*([-a-z.0-9+]+)/) # pkg-config library @pkgs ||= [] @pkgs << @str[1] elsif @str.skip(/%include_dir\s+(.+)\n/) # Include dirs @inc_dirs ||= [] @inc_dirs << @str[1].strip elsif @str.skip(/%lib_dir\s+(.+)\n/) # Library dir @lib_dirs ||= [] @lib_dirs << @str[1].strip elsif @str.skip(/%include\s+(.+)\n/) # Include file @incs ||= [] @incs << @str[1].strip elsif @str.skip(/%option +([a-z]+)=(yes|no)\n/) # Option case @str[1] when 'glib', 'gtk', 'gnu' @options[@str[1]] = (@str[2] == 'yes') else syntax_error "Unknown option #{@str[1]}" end elsif @str.skip(/%lib\s+(.+)\n/) # Skip single-line comment @libs ||= [] @libs << @str[1].strip elsif @str.skip(/%define\s+(.+)\n/) # Skip single-line comment @defs ||= [] @defs << @str[1].strip elsif @str.skip(/%equiv[a-z]*\s+([^=\n]+)=([^=\n]+)\n/) # Skip single-line comment $equivalents[@str[1].gsub(/ /,'').strip] = @str[2].gsub(/ /,'').strip elsif @str.skip(/%map\s+([^->]+?)\>([^:]+):([^@\n]+) *@? *(.*)\n/) # Skip single-line comment from, to, code = *[@str[1], @str[2], @str[3]].collect { |i| i.strip } free_code = @str[4] from.gsub!(/ /,'') to.gsub!(/ /,'') puts "Mapping #{from} -> #{to}" ($custom_maps[from] ||= {})[to] = code $custom_frees[to] = free_code elsif state.in_class > 0 and state.in_func == false and @str.skip(/%flag\s+([a-z0-9_A-Z]+)/) flag = ("flag_"+@str[1]+"=").intern if stack.last.respond_to?(flag) stack.last.__send__(flag, true) else syntax_error "%flags directive cannot be used here (#{stack.last.class} doesn't respond to #{flag})" end elsif state.in_class > 0 and state.in_func == false and @str.skip(/%feature\s+([a-z0-9_A-Z]+)/) flag = ("feature_"+@str[1]).intern @str.skip(/\s+/) args = [] if @str.skip(/\(/) args = @str.scan_until(/\)/)[0..-2].split(/, */).map { |i| i.strip } end @str.skip(/;/) if stack.last.respond_to?(flag) stack.last.__send__(flag, *args) else syntax_error "%feature '#{@str[1]}' directive cannot be used here (#{stack.last.class} doesn't support it)" end elsif @str.skip(/%/) # Skip single-line comment @str.skip_until(/\n/) ####### Comments elsif state.in_func == false and @str.skip(/#.*/) # Comment elsif state.in_func == false and @str.skip(/\/\/.*/) # Comment elsif state.in_func == false and @str.skip(/\/\*(.|\n)*\*\//) # Multi-line Comment ####### Code elsif txt = @str.scan(/['"]/) #' Skip quoted string txt += @str.scan_until(/(^|[^\\])#{txt}/) # Skip until unescaped quote func.text += txt if state.in_func elsif state.in_func == false and @str.skip(/module(?= )/x) # Module defn @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) @classes[name] = C_Module.new(name, [], [], []) @classes[name].parent = stack.last stack.last.classes.push(@classes[name]) stack.push(@class = @classes[name]) puts "module "+ @class.fullname + "-#{@class.name}" state.in_class += 1 elsif state.in_func == false and @str.skip(/class(?= )/x) # Class defn @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) superclass = nil @str.skip(/\s*/) if @str.skip(/</) @str.skip(/\s*/) superclass = @str.scan(/[A-Z][a-z_0-9A-Z]*/) end @classes[name] = C_Class.new(name, superclass, [], [], []) @classes[name].parent = stack.last stack.last.classes.push(@classes[name]) stack.push(@class = @classes[name]) puts "class "+ @class.fullname state.in_class += 1 elsif state.in_func == false and @str.skip(/struct(?= )/x) # Ruby Struct @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) @str.skip(/\s+/) if @str.skip(/\(/) args = @str.scan_until(/\)/)[0..-2].split(/, */).collect { |i| i.strip } end # NB. struct Name(arg0...argN) if @str.skip(/\s*;/) stack.last.classes.push(C_Struct.new(name, args, stack.last)) else @classes[name] = C_Struct.new(name, args, stack.last) stack.last.classes.push(@classes[name]) stack.push(@class = @classes[name]) puts "struct "+ @class.fullname state.in_class += 1 end elsif state.in_func == false and @str.skip(/gcpool(?= )/x) # GC Pool @str.skip(/\s+/) name = @str.scan(/[a-z_0-9A-Z]*/) puts "GCPool #{name}" stack.first.classes.push(C_GCRefPool.new(name)) elsif state.in_func == false and @str.skip(/(enum|flags)(?= )/x) # C Enum as module wrapper what = @str[1] @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) @str.skip(/\s+/) if @str.skip(/\(/) args = @str.scan_until(/\)/)[0..-2].split(/, */).collect { |i| i.strip } end if what == "flags" stack.last.classes.push(C_Flags.new(name, args, stack.last)) else stack.last.classes.push(C_Enum.new(name, args, stack.last)) end elsif state.in_func == false and @str.skip(/(genum|gflags)(?= )/x) # C GEnum as module wrapper what = @str[1] @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) @str.skip(/\s+/) g_type = @str.scan(/[A-Z][_0-9A-Z]*/) @str.skip(/\s+/) prefix = @str.scan(/(prefix=)?[A-Z][_0-9A-Z]*/i).to_s.sub(/^prefix=/i,'') @str.skip(/\s*/) define_on_self = @str.scan(/define_on_self/) @str.skip(/\s*;/) if what == "gflags" obj = C_GFlags.new(name, g_type, prefix, stack.last) else obj = C_GEnum.new(name, g_type, prefix, stack.last) obj.define_on_self = !! define_on_self; end stack.last.classes.push(obj) elsif state.in_func == false and @str.skip(/(gobject|ginterface|gboxed)(?= )/x) # Class defn type=@str[1] @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) superclass = nil @str.skip(/\s*/) if @str.skip(/\</) @str.skip(/\s*/) gtype = @str.scan(/[A-Z_]+/) end @str.skip(/\s*/) if @str.skip(/:/) @str.skip(/\s*/) gparent_class = @str.scan(/[A-Z_:a-z0-9]+/) end case type when "gobject" @classes[name] = C_GObject.new(name, gtype, [], [], []) when "ginterface" @classes[name] = C_GInterface.new(name, gtype, [], [], []) when "gboxed" @classes[name] = C_GBoxed.new(name, gtype, [], [], []) else syntax_error "#{name} is not a GObject or GInterface..." end @classes[name].gparent_class = gparent_class @classes[name].parent = stack.last stack.last.classes.push(@classes[name]) stack.push(@class = @classes[name]) puts "class "+ @class.fullname state.in_class += 1 elsif @str.scan(/@type\s+([A-Za-z_0-9]+)/) type = @str[1] prev = stack.last if prev.is_a?(C_GObject) # p c_type, self puts "Converting #{type}* to & from VALUE" prev.c_type_name = type ($custom_maps[type+'*'] ||= {})["VALUE"] = "GOBJ2RVAL(%%)" ($custom_maps["VALUE"] ||= {})[type+'*'] = "RVAL2GOBJ(%%)" elsif prev.is_a?(C_GBoxed) prev.c_type_name = type ($custom_maps[type+'*'] ||= {})["VALUE"] = "BOXED2RVAL(%%, #{prev.superclass})" ($custom_maps["VALUE"] ||= {})[type+'*'] = "RVAL2BOXED(%%, #{prev.superclass})" else # Invalid type directive end elsif @str.skip(/end(?=\s)/x) last = stack.pop puts "#{last.class} - #{last.name}" case last when C_Module, C_Class, C_Enum, C_Flags, C_Struct, C_GObject, C_GInterface, C_GBoxed state.in_class -= 1 @class = stack.last when C_Function state.in_func = false else STDERR.puts "Remaining code: #{@str.rest}" STDERR.puts "Defined Classes: #{@classes.keys.join(', ')}" p stack syntax_error "Invalid stack entry #{last.class}" end elsif @str.skip(/alias\s+:([A-Za-z0-9_]*[\[\]]{0,2}[?!=]?)\s+:([A-Za-z0-9_]*[\[\]]{0,2}[?!=]?)/) # Alias @class.add_alias(@str[1], @str[2]) if @class.respond_to?(:add_alias) elsif @str.skip(/(pre|post)_func\s+do/) where = @str[1] str = @str.scan_until(/\bend/)#[0,-4] unless str syntax_error "Invalid #{where}_func definition" end str = str[0..-4].strip except = only = nil @str.skip(/\s*/) if @str.skip(/,\s*:(only|except)\s*=\>\s*(\[[^\]]+\])/) if @str[1] == 'only' only = eval(@str[2]).map{|i|i.to_s} else except = eval(@str[2]).map{|i|i.to_s} end end if where == 'pre' @class.pre_func = str @class.pre_only = only if only @class.pre_except = except if except else @class.post_func = str @class.post_only = only if only @class.post_except = except if except end elsif @str.skip(/pre_func\s+(.*)/) # Pre func code @class.pre_func= @str[1] if @class.respond_to?(:pre_func) elsif @str.skip(/post_func\s+(.*)/) # Post func code @class.post_func= @str[1] if @class.respond_to?(:post_func) elsif @str.skip(/def(?=\s+)/x) # Function defn @str.skip(/\s+/) if @str.scan(/([a-zA-Z_* 0-9]+):/) returntype = @str[1] elsif @str.skip(/(GS?List)[{]([^}]+)[}]:/) container = @str[1] ct = @str[2] cn = ct.gsub(/\s+/,'').gsub(/[*]/,'__p') rule = container+'{'+ct+'}' returntype = rule #syntax_error "Auto converting (#{rule}) GSList of #{ct} is not yet supported" # sane unless $custom_maps[rule] && $custom_maps[rule]['VALUE'] function = "rubber_#{container}_of_#{cn}_to_array" @raw = @raw.to_s + <<-EOADD inline VALUE #{function}(#{container} *list) { #{container} *p; volatile VALUE ary; ary = rb_ary_new(); for(p = list ; p ; p = p->next) { rb_ary_push(ary, #{Rubber.explicit_cast('(('+ct+') p->data )', ct, 'VALUE')}); } return ary; } EOADD $custom_maps[rule] ||={} $custom_maps[rule]['VALUE'] = function+"(%%)" end else returntype = 'VALUE' end prename = '' prename = @str.scan(/self\./) name = @str.scan(/[a-z_0-9A-Z.]+[?!=]?/) unless name name = @str.scan(/[-\[\]<>~=+|&]{1,3}/) end oname = name name = prename.to_s + oname #p [prename, oname, name] @str.skip(/\s*/) args = scan_args().collect { |i| C_Param.new(i) } func = @functions[name] = C_Function.new(name, args, '') func.returntype = returntype func.parent = @class stack.last.functions.push(func) puts "def "+ func.fullname stack.push(func) func.source_line = current_line func.source_file = current_file state.in_func = true elsif state.in_func == false and @str.skip(/(string|integer|float|double|int)(?= )/x) # C String as module wrapper type= @str[1] @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) @str.skip(/\s*=\s*/) if @str.skip(/"/) #" string = '"' + @str.scan_until(/[^\\]?"/) #" elsif t = @str.scan(/([A-Z][a-z_0-9A-Z]*)/) string = @str[1] elsif type =~ /^(flo|dou|int)/ and t = @str.scan(/([0-9]+(\.[0-9]+)?(e[0-9]+)?)/) string = @str[1] end klass = nil case type when /^str/ klass = C_String when /^int/ klass = C_Integer when /^(flo|dou)/ klass = C_Float end stack.last.classes.push(klass.new(name, string, stack.last)) if klass elsif state.in_func == false && @str.skip(/(array)(?= )/x) type = @str[1] @str.skip(/\s+/) name = @str.scan(/[A-Z][a-z_0-9A-Z]*/) @str.skip(/\s*=\s*/) values = [] if @str.skip(/\[/) @str.skip(/\s+/) until @str.skip(/\s*\]/) if @str.skip(/(".*?[^\\]")/) values << { :string => @str[1] } # unescape escaped chars? elsif @str.skip(/(\d[.]\d+)/) values << { :float => @str[1] } elsif @str.skip(/(\d+)/) values << { :int => @str[1] } elsif @str.skip(/NULL/) values << { :nil => true } elsif @str.skip(/(TRUE|FALSE)/) values << { :bool => @str[1] == 'TRUE' } elsif @str.skip(/([A-Za-z0-9_]+)/) values << { :int => @str[1] } # Assume a constant else syntax_error "Unrecognised array value" end @str.skip(/\s*,\s*/) end stack.last.classes.push(C_Array.new(name, values, stack.last)) p [ :create_array, values ] else syntax_error "Arrays should be in the form: [value1, value2, ... valueN]" end elsif txt = @str.get_byte # Spare chars if state.in_func func.text += txt else syntax_error "Invalid character #{txt}" end end end end |
#current_line ⇒ Object
488 489 490 491 492 |
# File 'lib/rubber/scanner.rb', line 488 def current_line count = 0 @string[0..@str.pos].each_byte { |b| count += 1 if b == 10 } count end |
#misc_error(message, show_location = true) ⇒ Object
502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/rubber/scanner.rb', line 502 def misc_error(, show_location=true) STDERR.puts "Error: #{} at line #{current_line}\n" if show_location if @str.rest.size > 255 STDERR.puts @str.rest[0..255]+"..." else STDERR.puts @str.rest end end exit 1 end |
#scan(fp) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rubber/scanner.rb', line 68 def scan(fp) _scan(fp) rescue Exception off,ind = 0,0 for line in @lines off += line.size break if off > @str.pos ind += 1 end #p @state, @str, ind raise end |
#scan_args ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rubber/scanner.rb', line 40 def scan_args() args = [] return args unless @str.peep(1) == '(' brackets = 1 arg = '' @str.get_byte # Get first bracket until @str.peep(1) == ')' and brackets == 1 brackets += 1 if @str.peep(1) == '(' brackets -= 1 if @str.peep(1) == ')' if brackets == 1 and @str.peep(1) == ',' @str.pos = @str.pos + 1 arg.strip! args.push arg unless arg.empty? arg = '' else arg += @str.get_byte end end @str.get_byte # Get last bracket arg.strip! args.push arg unless arg.empty? args end |
#syntax_error(message) ⇒ Object
493 494 495 496 497 498 499 500 501 |
# File 'lib/rubber/scanner.rb', line 493 def syntax_error() STDERR.puts "Syntax Error: #{} at line #{current_line}\n" if @str.rest.size > 255 STDERR.puts @str.rest[0..255]+"..." else STDERR.puts @str.rest end exit 1 end |