class HamlI18nLint::RubyParser

Public Class Methods

new(src, *) click to toggle source
Calls superclass method
# File lib/haml_i18n_lint/ruby_parser.rb, line 12
def initialize(src, *)
  @src = src
  super
end
sexp(src, filename = '-', lineno = 1) click to toggle source
# File lib/haml_i18n_lint/ruby_parser.rb, line 6
def self.sexp(src, filename = '-', lineno = 1)
  builder = new(src, filename, lineno)
  sexp = builder.parse
  sexp unless builder.error?
end

Public Instance Methods

on_heredoc_beg(tok) click to toggle source
Calls superclass method
# File lib/haml_i18n_lint/ruby_parser.rb, line 23
def on_heredoc_beg(tok)
  @buf ||= []
  @buf << [[lineno, column]]
  super
end
on_heredoc_end(tok) click to toggle source
Calls superclass method
# File lib/haml_i18n_lint/ruby_parser.rb, line 34
def on_heredoc_end(tok)
  @buf.last << [lineno, column + tok.size-1]
  super
end
on_string_literal(*args) click to toggle source
# File lib/haml_i18n_lint/ruby_parser.rb, line 39
def on_string_literal(*args)
  pos = @buf.pop
  lineno_pos = pos.map(&:first)
  column_pos = pos.map(&:last)
  lines = @src.lines[lineno_pos.first-1...lineno_pos.last]
  if lineno_pos.first == lineno_pos.last
    lines[0] = lines[0].byteslice(column_pos.first..column_pos.last).force_encoding(@src.encoding)
  else
    lines[0] = lines[0].dup.tap { |l| l.force_encoding(Encoding::BINARY)[0...column_pos.first] = ''; l.force_encoding(@src.encoding) }
    lines[-1] = lines[-1].dup.tap { |l| l.force_encoding(Encoding::BINARY)[column_pos.last+1..-1] = ''; l.force_encoding(@src.encoding) }
  end
  args.unshift(:string_literal, lines.join, pos)
  args
end
on_tstring_beg(tok) click to toggle source
Calls superclass method
# File lib/haml_i18n_lint/ruby_parser.rb, line 17
def on_tstring_beg(tok)
  @buf ||= []
  @buf << [[lineno, column]]
  super
end
on_tstring_end(tok) click to toggle source
Calls superclass method
# File lib/haml_i18n_lint/ruby_parser.rb, line 29
def on_tstring_end(tok)
  @buf.last << [lineno, column]
  super
end