Class: CountLnString
- Inherits:
-
String
- Object
- String
- CountLnString
- Defined in:
- lib/erbpp/line_number.rb
Instance Method Summary collapse
- #concat0(s) ⇒ Object
- #concat1(s) ⇒ Object
- #d(s) ⇒ Object
- #final ⇒ Object
-
#initialize(filename) ⇒ CountLnString
constructor
A new instance of CountLnString.
- #ln(status = nil) ⇒ Object
- #report_line ⇒ Object
Constructor Details
#initialize(filename) ⇒ CountLnString
Returns a new instance of CountLnString.
3 4 5 6 7 8 9 10 11 |
# File 'lib/erbpp/line_number.rb', line 3 def initialize(filename) @filename = filename @lnchar = "\n" @buf = "" @str = "" @countln = 1 @current = 1 super("\n"+report_line) end |
Instance Method Details
#concat0(s) ⇒ Object
17 18 19 20 21 |
# File 'lib/erbpp/line_number.rb', line 17 def concat0(s) ln(caller[0]) @buf.concat(s) @str.concat(s) end |
#concat1(s) ⇒ Object
23 24 25 26 |
# File 'lib/erbpp/line_number.rb', line 23 def concat1(s) ln(caller[0]) @buf.concat(s) end |
#d(s) ⇒ Object
84 85 86 87 |
# File 'lib/erbpp/line_number.rb', line 84 def d(s) p [s, [x,y], r] r end |
#final ⇒ Object
89 90 91 |
# File 'lib/erbpp/line_number.rb', line 89 def final concat(@buf) end |
#ln(status = nil) ⇒ Object
28 29 30 31 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 |
# File 'lib/erbpp/line_number.rb', line 28 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_line ⇒ Object
13 14 15 |
# File 'lib/erbpp/line_number.rb', line 13 def report_line "#line #{@current} \"#{@filename}\"\n" end |