Module: Hemingway::Text

Includes:
Treetop::Runtime
Included in:
Latex, TextParser
Defined in:
lib/hemingway/text/text.rb

Defined Under Namespace

Modules: Text0

Instance Method Summary collapse

Instance Method Details

#_nt_non_textObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/hemingway/text/text.rb', line 75

def _nt_non_text
  start_index = index
  if node_cache[:non_text].has_key?(index)
    cached = node_cache[:non_text][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  i0 = index
  r1 = _nt_escape
  if r1
    r0 = r1
  else
    r2 = _nt_tag_end
    if r2
      r0 = r2
    else
      r3 = _nt_math_start
      if r3
        r0 = r3
      else
        r4 = _nt_newline
        if r4
          r0 = r4
        else
          r5 = _nt_override
          if r5
            r0 = r5
          else
            @index = i0
            r0 = nil
          end
        end
      end
    end
  end

  node_cache[:non_text][start_index] = r0

  r0
end

#_nt_textObject



17
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
# File 'lib/hemingway/text/text.rb', line 17

def _nt_text
  start_index = index
  if node_cache[:text].has_key?(index)
    cached = node_cache[:text][index]
    if cached
      cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
      @index = cached.interval.end
    end
    return cached
  end

  s0, i0 = [], index
  loop do
    i1, s1 = index, []
    i2 = index
    r3 = _nt_non_text
    if r3
      r2 = nil
    else
      @index = i2
      r2 = instantiate_node(SyntaxNode,input, index...index)
    end
    s1 << r2
    if r2
      if index < input_length
        r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
        @index += 1
      else
        terminal_parse_failure("any character")
        r4 = nil
      end
      s1 << r4
    end
    if s1.last
      r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
      r1.extend(Text0)
    else
      @index = i1
      r1 = nil
    end
    if r1
      s0 << r1
    else
      break
    end
  end
  if s0.empty?
    @index = i0
    r0 = nil
  else
    r0 = instantiate_node(TextNode,input, i0...index, s0)
  end

  node_cache[:text][start_index] = r0

  r0
end

#rootObject



10
11
12
# File 'lib/hemingway/text/text.rb', line 10

def root
  @root ||= :text
end