tests: error_syntax errors on `? now
[nit.git] / contrib / neo_doxygen / src / doxml / listener.nit
index 3c4dfa8..40d021f 100644 (file)
@@ -17,6 +17,7 @@ module doxml::listener
 
 import saxophonit
 import model
+import language_specific
 
 # Common abstractions for SAX listeners reading XML documents generated by Doxygen.
 abstract class DoxmlListener
@@ -28,10 +29,14 @@ abstract class DoxmlListener
        # The project graph.
        fun graph: ProjectGraph is abstract
 
+       # The language-specific strategies to use.
+       fun source_language: SourceLanguage is abstract
+
        redef fun document_locator=(locator: SAXLocator) do
                self.locator = locator
        end
 
+       # The Doxygen’s namespace IRI.
        protected fun dox_uri: String do return ""
 
        redef fun start_element(uri: String, local_name: String, qname: String,
@@ -57,6 +62,9 @@ abstract class DoxmlListener
        # See `ContentHandler.start_element` for the description of the parameters.
        protected fun end_dox_element(local_name: String) do end
 
+       # Get the boolean value of the specified attribute.
+       #
+       # `false` by default.
        protected fun get_bool(atts: Attributes, local_name: String): Bool do
                return get_optional(atts, local_name, "no") == "yes"
        end
@@ -130,13 +138,18 @@ abstract class StackableListener
        # The project graph.
        private var p_graph: ProjectGraph is noinit
 
+       # The language-specific strategies to use.
+       private var p_source: SourceLanguage is noinit
+
 
        init do
                super
                p_graph = parent.graph
+               p_source = parent.source_language
        end
 
        redef fun graph do return p_graph
+       redef fun source_language do return p_source
 
        # Temporary redirect events to itself until the end of the specified element.
        fun listen_until(uri: String, local_name: String) do
@@ -188,7 +201,10 @@ end
 class TextListener
        super StackableListener
 
+       # The read text.
        protected var buffer: Buffer = new FlatBuffer
+
+       # Is the last read chunk was ignorable white space?
        private var sp: Bool = false
 
        redef fun listen_until(uri: String, local_name: String) do
@@ -220,3 +236,53 @@ class TextListener
 
        redef fun to_s do return buffer.to_s
 end
+
+# Processes a content of type `linkedTextType`.
+abstract class LinkedTextListener[T: LinkedText]
+       super TextListener
+
+       # The read text.
+       var linked_text: T is noinit
+
+       private var refid = ""
+
+       # Create a new instance of `T`.
+       protected fun create_linked_text: T is abstract
+
+       redef fun listen_until(uri: String, local_name: String) do
+               linked_text = create_linked_text
+               refid = ""
+               super
+       end
+
+       redef fun start_dox_element(local_name: String, atts: Attributes) do
+               super
+               push_part
+               if "ref" == local_name then refid = get_required(atts, "refid")
+       end
+
+       redef fun end_dox_element(local_name: String) do
+               super
+               push_part
+               if "ref" == local_name then refid = ""
+       end
+
+       private fun push_part do
+               var s = flush_buffer
+
+               if not s.is_empty then
+                       linked_text.add_part(s, refid)
+               end
+       end
+
+       redef fun to_s do return linked_text.to_s
+end
+
+# Processes the content of a `<type>` element.
+class TypeListener
+       super LinkedTextListener[RawType]
+
+       private var raw_type: RawType is noinit
+
+       redef fun create_linked_text do return new RawType(graph)
+end