Class: VER::Syntax::Processor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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



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

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

  tags[name] << "#{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 consequences.
  # We swallow that exception to avoid confusion.
  raise exception unless exception.message.empty?
end

#end_parsing(syntax_name) ⇒ Object



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

def end_parsing(syntax_name)
  tags.each do |name, indices|
    tag_name = theme.get(name) || name
    textarea.fast_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



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

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

#open_tag(name, pos) ⇒ Object



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

def open_tag(name, pos)
  stack << [name, 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
# 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 = []
end