31db538f865e5284fa9eaaed2d686c48554d1f25
[booh] / lib / booh / rexml / dtd / dtd.rb
1 require "booh/rexml/dtd/elementdecl"
2 require "booh/rexml/dtd/entitydecl"
3 require "booh/rexml/comment"
4 require "booh/rexml/dtd/notationdecl"
5 require "booh/rexml/dtd/attlistdecl"
6 require "booh/rexml/parent"
7
8 module REXML
9         module DTD
10                 class Parser
11                         def Parser.parse( input )
12                                 case input
13                                 when String
14                                         parse_helper input
15                                 when File
16                                         parse_helper input.read
17                                 end
18                         end
19
20                         # Takes a String and parses it out
21                         def Parser.parse_helper( input )
22                                 contents = Parent.new
23                                 while input.size > 0
24                                         case input
25                                         when ElementDecl.PATTERN_RE
26                                                 match = $&
27                                                 source = $'
28                                                 contents << EleemntDecl.new( match )
29                                         when AttlistDecl.PATTERN_RE
30                                                 matchdata = $~
31                                                 source = $'
32                                                 contents << AttlistDecl.new( matchdata )
33                                         when EntityDecl.PATTERN_RE
34                                                 matchdata = $~
35                                                 source = $'
36                                                 contents << EntityDecl.new( matchdata )
37                                         when Comment.PATTERN_RE
38                                                 matchdata = $~
39                                                 source = $'
40                                                 contents << Comment.new( matchdata )
41                                         when NotationDecl.PATTERN_RE
42                                                 matchdata = $~
43                                                 source = $'
44                                                 contents << NotationDecl.new( matchdata )
45                                         end
46                                 end
47                                 contents
48                         end
49                 end
50         end
51 end