]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/html/templates/fhtml/fhtml.factor
factor: trim using lists
[factor.git] / basis / html / templates / fhtml / fhtml.factor
index f4ee1bca8fa96f11ffa659fca9ea358cd38538cd..cac7b39f0bfd7aede7f03611a59d5336ac48f74b 100644 (file)
@@ -1,9 +1,10 @@
 ! Copyright (C) 2005 Alex Chapman
 ! Copyright (C) 2006, 2010 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators compiler.units html.templates io
-io.encodings.utf8 io.files kernel lexer math namespaces parser
-parser.notes quotations sequences splitting vocabs.parser ;
+USING: accessors compiler.units html.templates io
+io.encodings.utf8 io.files kernel lexer lexer.private math
+namespaces parser parser.notes quotations sequences splitting
+vocabs.parser ;
 IN: html.templates.fhtml
 
 ! We use a custom lexer so that %> ends a token even if not
@@ -15,17 +16,14 @@ TUPLE: template-lexer < lexer ;
 
 M: template-lexer skip-word
     [
-        {
-            { [ 2dup nth CHAR: \" = ] [ drop 1 + ] }
-            { [ 2dup swap tail-slice "%>" head? ] [ drop 2 + ] }
-            [ f skip ]
-        } cond
+        2dup swap tail-slice "%>" head?
+        [ drop 2 + ] [ (skip-word) ] if
     ] change-lexer-column ;
 
 DEFER: <% delimiter
 
 : check-<% ( lexer -- col )
-    [ line-text>> "<%" ] [ column>> ] bi start ;
+    "<%" swap [ line-text>> ] [ column>> ] bi subseq-start-from ;
 
 : found-<% ( accum lexer col -- accum )
     [
@@ -60,7 +58,7 @@ SYNTAX: %> lexer get parse-%> ;
         [
             parser-quiet? on
             "html.templates.fhtml" use-vocab
-            string-lines parse-template-lines
+            split-lines parse-template-lines
         ] with-file-vocabs
     ] with-compilation-unit ;
 
@@ -71,7 +69,7 @@ TUPLE: fhtml path ;
 
 C: <fhtml> fhtml
 
-M: fhtml call-template* ( filename -- )
+M: fhtml call-template*
     path>> utf8 file-contents eval-template ;
 
 INSTANCE: fhtml template