Class: BitClust::Preprocessor

Inherits:
LineFilter show all
Defined in:
lib/bitclust/preprocessor.rb

Overview

Handle pragmas like #@todo, #@include, #@since, etc.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LineFilter

#each, #gets

Methods included from ParseUtils

#parse_error

Constructor Details

#initialize(f, params = {}) ⇒ Preprocessor

Returns a new instance of Preprocessor.


67
68
69
70
71
72
# File 'lib/bitclust/preprocessor.rb', line 67

def initialize(f, params = {})
  super f
  @params = params
  @last_if = nil
  cond_init
end

Class Method Details

.process(path, params = {}) ⇒ Object


57
58
59
60
61
# File 'lib/bitclust/preprocessor.rb', line 57

def Preprocessor.process(path, params = {})
  fopen(path, 'r:UTF-8') {|f|
    return wrap(f, params).to_a
  }
end

.read(path, params = {}) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bitclust/preprocessor.rb', line 44

def self.read(path, params = {})
  if path.respond_to?(:gets)
    io = wrap(path, params)
  else
    io = wrap(fopen(path, 'r:UTF-8'), params)
  end
  ret = ""
  while s = io.gets
    ret << s
  end
  ret
end

.wrap(f, params = {}) ⇒ Object


63
64
65
# File 'lib/bitclust/preprocessor.rb', line 63

def Preprocessor.wrap(f, params = {})
  new(LineStream.new(f), params)
end