Class: Preprocessor::Tokens

Inherits:
Object
  • Object
show all
Includes:
CTokenizer
Defined in:
lib/dbc/preprocessor.rb

Constant Summary

Constants included from CTokenizer

CTokenizer::CP_RESERVED, CTokenizer::C_RESERVED, CTokenizer::EOF_TOKEN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CTokenizer

check_token, #collect, #each, #error, error, line_count, #parse_error, #to_a, #token_error, #warning, whitespace?

Constructor Details

#initialize(source) ⇒ Tokens

Returns a new instance of Tokens.



22
23
24
25
# File 'lib/dbc/preprocessor.rb', line 22

def initialize(source)
  @tokens = []
  self.add_source(source)
end

Instance Attribute Details

#start_lineObject (readonly)

Returns the value of attribute start_line.



27
28
29
# File 'lib/dbc/preprocessor.rb', line 27

def start_line
  @start_line
end

Instance Method Details

#add_source(source) ⇒ Object



29
30
31
32
# File 'lib/dbc/preprocessor.rb', line 29

def add_source(source)
  @tokens.push(source)
  @start_line = true # begining of file
end

#base?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dbc/preprocessor.rb', line 46

def base?
  @tokens.length == 1
end

#empty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/dbc/preprocessor.rb', line 50

def empty?
  @tokens.length == 1 and @tokens.last.empty?
end

#fileObject



54
55
56
# File 'lib/dbc/preprocessor.rb', line 54

def file
  @tokens.last.file
end

#lineObject



58
59
60
# File 'lib/dbc/preprocessor.rb', line 58

def line
  @tokens.last.line
end

#match?(rexp) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/dbc/preprocessor.rb', line 34

def match?(rexp)
  @tokens.last.match?(rexp)
end

#post_matchObject



42
43
44
# File 'lib/dbc/preprocessor.rb', line 42

def post_match
  @tokens.last.post_match
end

#scan(rexp) ⇒ Object



38
39
40
# File 'lib/dbc/preprocessor.rb', line 38

def scan(rexp)
  @tokens.last.scan(rexp)
end

#shiftObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dbc/preprocessor.rb', line 62

def shift
  t = @tokens.last.shift
  while !t[0] and @tokens.length > 1
    # we are done with the current file
    @tokens.pop
    t = @tokens.last.shift
  end # while
  case t[0]
    when :NEWLINE
      @start_line = true
    when :SPACE, :COMMENT, false
      # do nothing, keeping @start_line the same
    else
      @start_line = false
  end # case
  t
end