]> gitweb.factorcode.org Git - factor.git/commitdiff
modern: simplify string parser
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 9 Jun 2022 03:35:41 +0000 (22:35 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 9 Jun 2022 03:35:41 +0000 (22:35 -0500)
extra/modern/html/html.factor
extra/modern/modern.factor

index eee4c0728c11dd24028975e8cd836a4e9a97f75a..0ec7b034a4bb129cc190d7c2d6756099c46983eb 100644 (file)
@@ -65,12 +65,12 @@ C: <squote> squote
 TUPLE: dquote payload ;
 C: <dquote> dquote
 
-: read-squote-payload ( n string -- n' string )
+: advance-squote-payload ( n string -- n' string )
     over [
         { CHAR: \\ CHAR: ' } slice-til-separator-inclusive {
-            { f [ drop ] }
+            { f [ to>> over string-expected-got-eof ] }
             { CHAR: ' [ drop ] }
-            { CHAR: \\ [ drop next-char-from drop read-squote-payload ] }
+            { CHAR: \\ [ drop next-char-from drop advance-squote-payload ] }
         } case
     ] [
         string-expected-got-eof
@@ -78,10 +78,9 @@ C: <dquote> dquote
 
 :: read-string ( $n $string $char -- n' string payload )
     $n $string $char CHAR: ' =
-    [ read-squote-payload ]
-    [ read-dquote-payload ] if drop :> $n'
+    [ advance-squote-payload ]
+    [ advance-dquote-payload ] if drop :> $n'
     $n' $string
-    $n' [ $n $string string-expected-got-eof ] unless
     $n $n' 1 - $string <slice> ;
 
 : take-tag-name ( n string -- n' string tag )
index 04f9dbe199a83df86dbb1013f31694ad4d099253..e29eb3b5ddf6a3d081ab4c78ef5c228c1222d722 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2016 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays assocs combinators combinators.short-circuit
-continuations io.encodings.utf8 io.files kernel make math
-math.order modern.paths modern.slices sequences sequences.extras
-sets splitting strings unicode vocabs.loader ;
+USING: accessors arrays assocs combinators
+combinators.short-circuit continuations io.encodings.utf8
+io.files kernel make math math.order modern.paths modern.slices
+sequences sequences.extras sets splitting strings unicode
+vocabs.loader ;
 IN: modern
 
 ERROR: string-expected-got-eof n string ;
@@ -109,21 +110,20 @@ MACRO:: read-matched ( ch -- quot: ( n string tag -- n' string slice' ) )
 : read-bracket ( n string slice -- n' string slice' ) CHAR: [ read-matched ;
 : read-brace ( n string slice -- n' string slice' ) CHAR: { read-matched ;
 : read-paren ( n string slice -- n' string slice' ) CHAR: ( read-matched ;
-: read-dquote-payload ( n string -- n' string )
+: advance-dquote-payload ( n string -- n' string )
     over [
         { CHAR: \\ CHAR: \" } slice-til-separator-inclusive {
-            { f [ drop ] }
+            { f [ to>> over string-expected-got-eof ] }
             { CHAR: \" [ drop ] }
-            { CHAR: \\ [ drop next-char-from drop read-dquote-payload ] }
+            { CHAR: \\ [ drop next-char-from drop advance-dquote-payload ] }
         } case
     ] [
         string-expected-got-eof
     ] if ;
 
 :: read-string ( n string tag -- n' string seq )
-    n string read-dquote-payload drop :> n'
+    n string advance-dquote-payload drop :> n'
     n' string
-    n' [ n string string-expected-got-eof ] unless
     n n' 1 - string <slice>
     n' 1 - n' string <slice>
     tag -rot 3array ;