Class: CodeRay::Scanners::Term

Inherits:
Scanner
  • Object
show all
Defined in:
lib/devcenter/coderay_extensions.rb

Overview

author: Vincent Landgraf <[email protected]> modified by Raul Murciano <[email protected]> licence: GPLv2.1

Instance Method Summary collapse

Instance Method Details

#scan_tokens(tokens, options) ⇒ 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
# File 'lib/devcenter/coderay_extensions.rb', line 28

def scan_tokens (tokens, options)
  until eos?
    line = scan(/.*?(\n|\z)/)

    # multiline commands
    while line =~ /\\\n\z/
      line += scan(/.*?(\n|\z)/)
    end

    if line =~ /\A(\s*\$)/ # command
      tokens << [$1, :comment] # prompt
      line = line[($1.size)..-1]

      comment_start = line.rindex('#')
      if comment_start
        command = line[0..comment_start-1]
        unfinished_string = command.count('"').odd?
        if unfinished_string
          tokens << [line, :method]
        else
          comment = line[comment_start..-1]
          tokens << [command, :method] if command
          tokens << [comment, :comment] if comment
        end
      else
        tokens << [line, :method]
      end
    else
      tokens << [line, :string]
    end
    prev = line
  end
  return tokens
end