Class: VER::Syntax::Processor

Inherits:
VER::Struct show all
Defined in:
lib/ver/syntax/processor.rb

Constant Summary

Constants inherited from VER::Struct

VER::Struct::CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from VER::Struct

new

Instance Attribute Details

#linenoObject

Returns the value of attribute lineno

Returns:

  • (Object)

    the current value of lineno



3
4
5
# File 'lib/ver/syntax/processor.rb', line 3

def lineno
  @lineno
end

#stackObject

Returns the value of attribute stack

Returns:

  • (Object)

    the current value of stack



3
4
5
# File 'lib/ver/syntax/processor.rb', line 3

def stack
  @stack
end

#tagsObject

Returns the value of attribute tags

Returns:

  • (Object)

    the current value of tags



3
4
5
# File 'lib/ver/syntax/processor.rb', line 3

def tags
  @tags
end

#textareaObject

Returns the value of attribute textarea

Returns:

  • (Object)

    the current value of textarea



3
4
5
# File 'lib/ver/syntax/processor.rb', line 3

def textarea
  @textarea
end

#themeObject

Returns the value of attribute theme

Returns:

  • (Object)

    the current value of theme



3
4
5
# File 'lib/ver/syntax/processor.rb', line 3

def theme
  @theme
end

Instance Method Details

#close_tag(name, mark) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ver/syntax/processor.rb', line 40

def close_tag(name, mark)
  from_name, from_lineno, pos = stack.pop

  tags[name] << "#{from_lineno}.#{pos}" << "#{lineno}.#{mark}"
rescue RuntimeError => exception
  # if you modify near the end of the textarea, sometimes the last tag
  # cannot be closed because the contents of the textarea changed since
  # the last highlight was issued.
  # this will cause Tk to raise an error that doesn't have a message and
  #  is of no major conpatterns.
  # We swallow that exception to avoid confusion.
  raise exception unless exception.message.empty?
end

#end_parsing(syntax_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ver/syntax/processor.rb', line 11

def end_parsing(syntax_name)
  tags.each do |name, indices|
    tag_name = theme.get(name) || name
    textarea.tag_add(tag_name, *indices)
  end

  @tag_stack.uniq!
  @tag_stack.each_cons(2){|under, over| textarea.tag_raise(under, over) }

  stack.clear
end

#new_line(line) ⇒ Object



23
24
25
# File 'lib/ver/syntax/processor.rb', line 23

def new_line(line)
  self.lineno += 1
end

#open_tag(name, pos) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ver/syntax/processor.rb', line 27

def open_tag(name, pos)
  stack << [name, lineno, pos]

  if tag_name = theme.get(name)
    if stack.size > 1
      below_name = stack[-2][0]
      below = theme.get(below_name)
      return if !below || below.empty?
      @tag_stack << tag_name << below
    end
  end
end

#start_parsing(syntax_name) ⇒ Object



4
5
6
7
8
9
# File 'lib/ver/syntax/processor.rb', line 4

def start_parsing(syntax_name)
  self.stack = []
  self.tags = Hash.new{|h,k| h[k] = [] }
  @tag_stack = []
  tags[syntax_name] << "1.0" << "end"
end