! 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 math
-unicode.case unicode.categories combinators.short-circuit
-quoting fry ;
+USING: accessors combinators.short-circuit html.parser.utils
+kernel make math namespaces quoting sequences sequences.parser
+unicode ;
IN: html.parser
TUPLE: tag name attributes text closing? ;
CHAR: ' (read-quote) ;
: read-double-quote ( sequence-parser -- string )
- CHAR: " (read-quote) ;
+ CHAR: \" (read-quote) ;
: read-quote ( sequence-parser -- string )
dup get+increment CHAR: ' =
[ advance advance read-comment ] [ read-dtd ] if ;
: read-tag ( sequence-parser -- string )
- [ [ current "><" member? ] take-until ]
- [ dup current CHAR: < = [ advance ] unless drop ] bi ;
+ [
+ [ current "><" member? ] take-until
+ [ CHAR: / = ] trim-tail
+ ] [ dup current CHAR: < = [ advance ] unless drop ] bi ;
: read-until-< ( sequence-parser -- string )
[ current CHAR: < = ] take-until ;
dup sequence-parse-end? [
drop
] [
- [ parse-key/value swap set ] [ (parse-attributes) ] bi
+ [ parse-key/value swap ,, ] [ (parse-attributes) ] bi
] if ;
: parse-attributes ( sequence-parser -- hashtable )
- [ (parse-attributes) ] H{ } make-assoc ;
+ [ (parse-attributes) ] H{ } make ;
: (parse-tag) ( string -- string' hashtable )
[