]> gitweb.factorcode.org Git - factor.git/commitdiff
fix comments and dtds in html parser
authorDoug Coleman <erg@jobim.local>
Wed, 20 May 2009 20:50:01 +0000 (15:50 -0500)
committerDoug Coleman <erg@jobim.local>
Wed, 20 May 2009 20:50:01 +0000 (15:50 -0500)
extra/html/parser/parser-tests.factor
extra/html/parser/parser.factor

index ca276fc54e069fd645570062add13e24c0a79ea7..2876d03b163205ebf0dce8f95997ecd9cd5544a2 100644 (file)
@@ -73,3 +73,26 @@ V{
     T{ tag f "head" H{ } f t }
 }
 ] [ "<head<title>Spagna</title></head" parse-html ] unit-test
+
+[
+V{
+    T{ tag
+        { name dtd }
+        { text
+            "DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Draft//EN\""
+        }
+    }
+}
+]
+[
+    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Draft//EN\">"
+    parse-html
+] unit-test
+
+[
+V{
+    T{ tag { name comment } { text "comment" } }
+}
+] [
+    "<!--comment-->" parse-html
+] unit-test
index d95c79dd887b053d129fe51630d2cc4857c2e032..948bd0c954907eab4317306f411a635ca6ac5214 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays hashtables sequence-parser
-html.parser.utils kernel namespaces sequences
+html.parser.utils kernel namespaces sequences math
 unicode.case unicode.categories combinators.short-circuit
 quoting fry ;
 IN: html.parser
@@ -63,10 +63,12 @@ SYMBOL: tagstack
     [ blank? ] trim ;
 
 : read-comment ( sequence-parser -- )
-    "-->" take-until-sequence comment new-tag push-tag ;
+    [ "-->" take-until-sequence comment new-tag push-tag ]
+    [ '[ _ advance drop ] 3 swap times ] bi ;
 
 : read-dtd ( sequence-parser -- )
-    ">" take-until-sequence dtd new-tag push-tag ;
+    [ ">" take-until-sequence dtd new-tag push-tag ]
+    [ advance drop ] bi ;
 
 : read-bang ( sequence-parser -- )
     advance dup { [ current CHAR: - = ] [ peek-next CHAR: - = ] } 1&&