4 class EntityDecl < Child
6 START_RE = /^\s*#{START}/um
7 PUBLIC = /^\s*#{START}\s+(?:%\s+)?(\w+)\s+PUBLIC\s+((["']).*?\3)\s+((["']).*?\5)\s*>/um
8 SYSTEM = /^\s*#{START}\s+(?:%\s+)?(\w+)\s+SYSTEM\s+((["']).*?\3)(?:\s+NDATA\s+\w+)?\s*>/um
9 PLAIN = /^\s*#{START}\s+(\w+)\s+((["']).*?\3)\s*>/um
10 PERCENT = /^\s*#{START}\s+%\s+(\w+)\s+((["']).*?\3)\s*>/um
11 # <!ENTITY name SYSTEM "...">
12 # <!ENTITY name "...">
16 if src.match( PUBLIC )
17 md = src.match( PUBLIC, true )
19 @content = "#{md[2]} #{md[4]}"
20 elsif src.match( SYSTEM )
21 md = src.match( SYSTEM, true )
24 elsif src.match( PLAIN )
25 md = src.match( PLAIN, true )
28 elsif src.match( PERCENT )
29 md = src.match( PERCENT, true )
33 raise ParseException.new("failed Entity match", src) if md.nil?
38 rv = "<!ENTITY #@name "
39 rv << "#@middle " if @middle.size > 0
44 def write( output, indent )
45 indent( output, indent )
49 def EntityDecl.parse_source source, listener
50 md = source.match( PATTERN_RE, true )
51 thing = md[0].squeeze(" \t\n\r")
52 listener.send inspect.downcase, thing