Skip to content

Commit

Permalink
fix: keep lineno
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
seki committed Jul 25, 2003
1 parent b7b972c commit 83dde07
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/erb.rb
Expand Up @@ -13,11 +13,18 @@ def self.version
# ERB::Compiler
class ERB
class Compiler
class PercentLine
def initialize(str)
@value = str
end
attr_reader :value
alias :to_s :value
end

class Scanner
SplitRegexp = /(<%%)|(%%>)|(<%=)|(<%#)|(<%)|(%>)|(\n)/

def initialize(compiler, src)
@compiler = compiler
def initialize(src)
@src = src
@stag = nil
end
Expand All @@ -27,10 +34,10 @@ def scan; end
end

class TrimScanner < Scanner
def initialize(compiler, src)
super(compiler, src)
@trim_mode = compiler.trim_mode
@percent = compiler.percent
def initialize(src, trim_mode, percent)
super(src)
@trim_mode = trim_mode
@percent = percent
if @trim_mode
@scan_line = self.method(:trim_line)
else
Expand Down Expand Up @@ -62,9 +69,7 @@ def percent_line(line, &block)
if line[0] == ?%
@scan_line.call(line, &block)
else
yield('<%')
yield(' ' +line.chomp)
yield('%>')
yield(PercentLine.new(line.chomp))
end
end

Expand Down Expand Up @@ -148,6 +153,11 @@ def compile(s)
scanner.scan do |token|
if scanner.stag.nil?
case token
when PercentLine
out.push("#{@put_cmd} #{content.dump}") if content.size > 0
content = ''
out.push(token.to_s)
out.cr
when '<%', '<%=', '<%#'
scanner.stag = token
out.push("#{@put_cmd} #{content.dump}") if content.size > 0
Expand Down Expand Up @@ -217,9 +227,9 @@ def prepare_trim_mode(mode)

def make_scanner(src)
if @percent || @trim_mode
TrimScanner.new(self, src)
TrimScanner.new(src, @trim_mode, @percent)
else
SimpleScanner.new(self, src)
SimpleScanner.new(src)
end
end

Expand Down

0 comments on commit 83dde07

Please sign in to comment.