model: intro `MModule::first_real_mmodule` to get the first non-fictive module
[nit.git] / lib / saxophonit / saxophonit.nit
index a225413..6b3f616 100644 (file)
@@ -30,6 +30,38 @@ private import lexer
 #
 # Also note that this XML processor is unable to retrieve a file from an URL
 # (only local paths are supported).
+#
+# Usage example:
+#
+#     # Retrieve all text nodes.
+#     class TextListener
+#      super ContentHandler
+#     #
+#      private var buf: Buffer = new FlatBuffer
+#      private var sp: Bool = false
+#     #
+#      redef fun characters(str: String) do
+#              if sp then
+#                      if buf.length > 0 then buf.append(" ")
+#                      sp = false
+#              end
+#              buf.append(str)
+#      end
+#     #
+#      redef fun ignorable_whitespace(str: String) do
+#              sp = true
+#      end
+#     #
+#      # Return the concatenation of all text nodes.
+#      redef fun to_s do return buf.to_s
+#     end
+#     #
+#     var text = new TextListener
+#     var reader = new XophonReader
+#     #
+#     reader.content_handler = text
+#     reader.parse(new InputSource.with_stream(new StringReader("<foo>bar baz <n>42</n>.</foo>")))
+#     assert text.to_s == "bar baz 42."
 class XophonReader
        super XMLReader
 
@@ -93,7 +125,6 @@ class XophonReader
        end
 
        redef fun parse(input: InputSource) do
-               var stream: IStream
                var system_id: nullable MaybeError[String, Error] = null
                model.locator = new SAXLocatorImpl
 
@@ -116,7 +147,7 @@ class XophonReader
                                model.fire_fatal_error("File <{input.system_id.as(not null)}> not found.", null)
                        else
                                lexer = new XophonLexer(model,
-                                               new IFStream.open(system_id.value))
+                                               new FileReader.open(system_id.value))
                                parse_main
                                lexer.close
                        end
@@ -150,7 +181,6 @@ class XophonReader
 
        # Expect a `document` production.
        private fun expect_document: Bool do
-               var success = true
                var got_doctype = false
                var got_element = false
 
@@ -561,7 +591,7 @@ class XophonReader
                var buffer: Buffer = new FlatBuffer
 
                # Number of consecutive closing brackets.
-               var closing: Int = 0
+               var closing = 0
 
                if lexer.expect_string("CDATA[",
                                " at the beginning of a CDATA section.") then