Class: Ruvi::CPPHighlighter

Inherits:
Highlighter show all
Defined in:
lib/plugins/hl_cpp.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Highlighter

has_structure?, inherited

Class Method Details

.can_highlight?(buffer) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/plugins/hl_cpp.rb', line 9

def self.can_highlight? buffer
    return (buffer.fname =~ /\.cpp$/)
end

.importanceObject



6
7
8
# File 'lib/plugins/hl_cpp.rb', line 6

def self.importance
    0
end

Instance Method Details

#get_highlight_state(buf, y) ⇒ Object



12
13
14
# File 'lib/plugins/hl_cpp.rb', line 12

def get_highlight_state buf, y
    buf.hlstacks[y]
end

#highlight_line(buf, line, ypos) ⇒ Object



18
19
20
21
22
23
24
25
26
27
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
83
84
85
86
87
# File 'lib/plugins/hl_cpp.rb', line 18

def highlight_line buf, line, ypos
    hl_stack = (ypos == 0) ? [] : buf.hlstacks[ypos - 1].dup rescue [] # HACK
    current_class_stack = buf.classstacks[ypos-1]
    current_class_stack = current_class_stack.nil? ? [] : current_class_stack.dup
    dbg(:dbg_highlight) { "-#- #{line} #{ypos} #{hl_stack.inspect}" }
    s = StringScanner.new line
    while !s.eos?
        state = :normal
        state = :string if hl_stack.last == '"'
        state = :comment if hl_stack.last == '/*'
        case state
        when :comment
            matched = s.scan(/(\*\/|[^*]+|\*)/)
            dbg(:dbg_highlight) { matched.inspect }
            bold = true
            color = Curses::COLOR_CYAN
            hl_stack.pop if matched == "*/"
            yield color, bold, matched if block_given?
        when :string
            matched = s.scan(/("|[^"]+)/)
            dbg(:dbg_highlight) { matched.inspect }
            bold = true
            color = Curses::COLOR_MAGENTA
            hl_stack.pop if matched == "\""
            yield color, bold, matched if block_given?
        when :normal
            matched = s.scan(/(\/\/.*$|\/\*|\w+|\s+|.)/)
            dbg(:dbg_highlight) { matched.inspect }
            bold = nil
            color = Curses::COLOR_WHITE
            case matched
            when /\/\/.*$/
                color = Curses::COLOR_CYAN
                bold = true
            when /[0-9]/
                color = Curses::COLOR_MAGENTA
                bold = true
            when *%w(if)
                color = Curses::COLOR_YELLOW
                bold = true
            when *%w(void int char)
                color = Curses::COLOR_GREEN
                bold = true
            when /\w+/
                color = Curses::COLOR_WHITE
            when "{"
                hl_stack.push "{"
            when "}"
                hl_stack.pop
            when "("
                hl_stack.push "("
            when ")"
                hl_stack.pop
            when "\""
                bold = true
                color = Curses::COLOR_MAGENTA
                hl_stack.push "\""
            when "/*"
                bold = true
                color = Curses::COLOR_CYAN
                hl_stack.push "/*"
            end
            bold = false unless !bold.nil?
            yield color, bold, matched if block_given?
        end
        dbg(:dbg_highlight) { "STATE : #{hl_stack.inspect} : #{state}" }
    end
    buf.classstacks[ypos] = current_class_stack
    buf.hlstacks[ypos]    = hl_stack
end

#should_continue_highlight_pass?(buf, y, state) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/plugins/hl_cpp.rb', line 15

def should_continue_highlight_pass? buf, y, state
    buf.hlstacks[y] != state
end