Class: ErbPP::CountLnString

Inherits:
String
  • Object
show all
Defined in:
ext/numo/narray/gen/erbln.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ CountLnString

Returns a new instance of CountLnString.



7
8
9
10
11
12
13
14
15
# File 'ext/numo/narray/gen/erbln.rb', line 7

def initialize(filename)
  @filename = filename
  @lnchar = "\n"
  @buf = ""
  @str = ""
  @countln = 1
  @current = 1
  super("\n"+report_line)
end

Instance Method Details

#concat0(s) ⇒ Object



21
22
23
24
25
# File 'ext/numo/narray/gen/erbln.rb', line 21

def concat0(s)
  ln(caller[0])
  @buf.concat(s)
  @str.concat(s)
end

#concat1(s) ⇒ Object



27
28
29
30
# File 'ext/numo/narray/gen/erbln.rb', line 27

def concat1(s)
  ln(caller[0])
  @buf.concat(s)
end

#d(s) ⇒ Object



88
89
90
91
# File 'ext/numo/narray/gen/erbln.rb', line 88

def d(s)
  p [s, [x,y], r]
  r
end

#finalObject



93
94
95
96
# File 'ext/numo/narray/gen/erbln.rb', line 93

def final
  ln(caller[0])
  concat(@buf)
end

#ln(status = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'ext/numo/narray/gen/erbln.rb', line 32

def ln(status=nil)
  case status
  when /:(\d+):/
    n = $1.to_i
  else
    n = status.to_i
  end
  return if n == @current
  if @current != @countln || @postpone
    if /\A\s*\z/ =~ @str || /\A#line / =~ @buf
      @postpone = true
    elsif @in_comment
      @postpone = false
    else
      if self[-1] != "\n"
        concat("\n")
      end
      concat(report_line)
      @postpone = false
    end
  end
  concat(@buf)

  b = @buf.gsub(/".*?(?<!\\)"/,'""')
  /^.*(\/\*)(.*?)$/ =~ b
  x = $2
  /^.*(\*\/)(.*?)$/ =~ b
  y = $2
  if x
    if y
      if x.size < y.size
        #:in_comment
        @in_comment = true
      else
        #:out_comment
        @in_comment = false
      end
    else
      #:in_comment
      @in_comment = true
    end
  else
    if y
      #:out_comment
      @in_comment = false
    else
      #:keep
    end
  end

  @countln = @current + @buf.count(@lnchar)
  @current = n
  @buf = ""
  @str = ""
end

#report_lineObject



17
18
19
# File 'ext/numo/narray/gen/erbln.rb', line 17

def report_line
  "#line #{@current} \"#{@filename}\"\n"
end