File: raw_string.rb

package info (click to toggle)
ruby-htree 0.8%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 448 kB
  • ctags: 703
  • sloc: ruby: 5,931; makefile: 24
file content (127 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
74
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
119
120
121
122
123
124
125
126
127
require 'htree/modules'
require 'htree/fstr'

module HTree
  module Node
    # raw_string returns a source string recorded by parsing.
    # It returns +nil+ if the node is constructed not via parsing.
    def raw_string
      catch(:raw_string_tag) {
        return raw_string_internal('')
      }
      nil
    end
  end

  # :stopdoc:
  class Doc
    def raw_string_internal(result)
      @children.each {|n|
        n.raw_string_internal(result)
      }
    end
  end

  class Elem
    def raw_string_internal(result)
      @stag.raw_string_internal(result)
      @children.each {|n| n.raw_string_internal(result) }
      @etag.raw_string_internal(result) if @etag
    end
  end

  module Tag
    def init_raw_string() @raw_string = nil end
    def raw_string=(arg) @raw_string = HTree.frozen_string(arg) end
    def raw_string_internal(result)
      throw :raw_string_tag if !@raw_string
      result << @raw_string
    end
  end

  module Leaf
    def init_raw_string() @raw_string = nil end
    def raw_string=(arg) @raw_string = HTree.frozen_string(arg) end
    def raw_string_internal(result)
      throw :raw_string_tag if !@raw_string
      result << @raw_string
    end
  end

  class Text
    def raw_string=(arg)
      if arg == @rcdata then
        @raw_string = @rcdata
      else
        super
      end
    end
  end
  # :startdoc:

  module Node
    def eliminate_raw_string
      raise NotImplementedError
    end
  end

  # :stopdoc:

  class Doc
    def eliminate_raw_string
      Doc.new(@children.map {|c| c.eliminate_raw_string })
    end
  end

  class Elem
    def eliminate_raw_string
      Elem.new!(
        @stag.eliminate_raw_string,
        @empty ? nil : @children.map {|c| c.eliminate_raw_string },
        @etag && @etag.eliminate_raw_string)
    end
  end

  class Text
    def eliminate_raw_string
      Text.new_internal(@rcdata)
    end
  end

  class STag
    def eliminate_raw_string
      STag.new(@qualified_name, @attributes, @inherited_context)
    end
  end

  class ETag
    def eliminate_raw_string
      self.class.new(@qualified_name)
    end
  end

  class XMLDecl
    def eliminate_raw_string
      XMLDecl.new(@version, @encoding, @standalone)
    end
  end

  class DocType
    def eliminate_raw_string
      DocType.new(@root_element_name, @public_identifier, @system_identifier)
    end
  end

  class ProcIns
    def eliminate_raw_string
      ProcIns.new(@target, @content)
    end
  end

  class Comment
    def eliminate_raw_string
      Comment.new(@content)
    end
  end
  # :startdoc:
end