/tools/Ruby/lib/ruby/1.8/rexml/dtd/dtd.rb

http://github.com/agross/netopenspace · Ruby · 51 lines · 48 code · 2 blank · 1 comment · 1 complexity · 53e75f9eeffb3c43f376c1c9c3769e8d MD5 · raw file

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