Class: MathML::LaTeX::Scanner

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/math_ml.rb

Instance Method Summary collapse

Instance Method Details

#_checkObject


309
# File 'lib/math_ml.rb', line 309

alias :_check :check

#_eos?Object


319
# File 'lib/math_ml.rb', line 319

alias :_eos? :eos?

#_scanObject


314
# File 'lib/math_ml.rb', line 314

alias :_scan :scan

#check(re) ⇒ Object


310
311
312
# File 'lib/math_ml.rb', line 310

def check(re)
	skip_space_and(true){_check(re)}
end

#check_any(remain_space = false) ⇒ Object


363
364
365
# File 'lib/math_ml.rb', line 363

def check_any(remain_space=false)
	skip_space_and(true){scan_any(remain_space)}
end

#check_blockObject


336
337
338
# File 'lib/math_ml.rb', line 336

def check_block
	skip_space_and(true){scan_block}
end

#check_commandObject


324
325
326
# File 'lib/math_ml.rb', line 324

def check_command
	check(RE::COMMANDS)
end

#check_optionObject


400
401
402
# File 'lib/math_ml.rb', line 400

def check_option
	skip_space_and(true){scan_option}
end

#doneObject


293
294
295
# File 'lib/math_ml.rb', line 293

def done
	self.string[0, pos]
end

#eos?Boolean

Returns:

  • (Boolean)

320
321
322
# File 'lib/math_ml.rb', line 320

def eos?
	_eos? || _check(/#{RE::SPACE}+\z/)
end

#peek_commandObject


332
333
334
# File 'lib/math_ml.rb', line 332

def peek_command
	check_command ? self[1] : nil
end

#scan(re) ⇒ Object


315
316
317
# File 'lib/math_ml.rb', line 315

def scan(re)
	skip_space_and(false){_scan(re)}
end

#scan_any(remain_space = false) ⇒ Object


367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/math_ml.rb', line 367

def scan_any(remain_space=false)
	p = pos
	scan_space
	r = remain_space ? matched.to_s : ""
	case
	when s = scan_block
	when s = scan_command
	else
		unless _scan(/./) || remain_space
			self.pos = p
			return nil
		end
		s = matched.to_s
	end
	r << s
end

#scan_blockObject


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/math_ml.rb', line 340

def scan_block
	return nil unless scan(/\{/)
	block = "{"
	bpos = pos-1
	nest = 1
	while _scan(/(#{MBEC}*?)([\{\}])/)
		block << matched
		case self[2]
		when "{"
			nest+=1
		when "}"
			nest-=1
			break if nest==0
		end
	end
	if nest>0
		self.pos = bpos
		raise BlockNotClosed
	end
	self.pos = bpos
	_scan(/\A\{(#{Regexp.escape(block[RE::BLOCK, 1].to_s)})\}/)
end

#scan_commandObject


328
329
330
# File 'lib/math_ml.rb', line 328

def scan_command
	scan(RE::COMMANDS)
end

#scan_optionObject


384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/math_ml.rb', line 384

def scan_option
	return nil unless scan(/\[/)
	opt = "["
	p = pos-1
	until (s=scan_any(true)) =~ /\A#{RE::SPACE}*\]\z/
		opt << s
		if eos?
			self.pos = p
			raise OptionNotClosed
		end
	end
	opt << s
	self.pos = p
	_scan(/\A\[(#{Regexp.escape(opt[RE::OPTION, 1].to_s)})\]/)
end

#scan_spaceObject


297
298
299
# File 'lib/math_ml.rb', line 297

def scan_space
	_scan(/#{RE::SPACE}+/)
end

#skip_space_and(check_mode) ⇒ Object


301
302
303
304
305
306
307
# File 'lib/math_ml.rb', line 301

def skip_space_and(check_mode)
	opos = pos
	scan_space
	r = yield
	self.pos = opos if check_mode || !r
	r
end