]> 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 992b6600704e61eeead4472f4166e255febfa98e..cac7b39f0bfd7aede7f03611a59d5336ac48f74b 100644 (file)
@@ -1,12 +1,10 @@
 ! Copyright (C) 2005 Alex Chapman
-! Copyright (C) 2006, 2008 Slava Pestov
+! Copyright (C) 2006, 2010 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: continuations sequences kernel namespaces debugger
-combinators math quotations generic strings splitting
-accessors assocs fry vocabs.parser
-parser lexer io io.files io.streams.string io.encodings.utf8
-html.elements
-html.templates ;
+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
@@ -18,29 +16,26 @@ 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 )
-    "<%" over line-text>> rot column>> start* ;
+    "<%" swap [ line-text>> ] [ column>> ] bi subseq-start-from ;
 
 : found-<% ( accum lexer col -- accum )
     [
         over line-text>>
-        [ column>> ] 2dip subseq parsed
-        \ write-html parsed
+        [ column>> ] 2dip subseq suffix!
+        \ write suffix!
     ] 2keep 2 + >>column drop ;
 
 : still-looking ( accum lexer -- accum )
     [
         [ line-text>> ] [ column>> ] bi tail
-        parsed \ print-html parsed
+        suffix! \ print suffix!
     ] keep next-line ;
 
 : parse-%> ( accum lexer -- accum )
@@ -51,7 +46,7 @@ DEFER: <% delimiter
         drop
     ] if ;
 
-: %> lexer get parse-%> ; parsing
+SYNTAX: %> lexer get parse-%> ;
 
 : parse-template-lines ( lines -- quot )
     <template-lexer> [
@@ -60,20 +55,21 @@ DEFER: <% delimiter
 
 : parse-template ( string -- quot )
     [
-        "quiet" on
-        parser-notes off
-        "html.templates.fhtml" use+
-        string-lines parse-template-lines
-    ] with-file-vocabs ;
+        [
+            parser-quiet? on
+            "html.templates.fhtml" use-vocab
+            split-lines parse-template-lines
+        ] with-file-vocabs
+    ] with-compilation-unit ;
 
 : eval-template ( string -- )
-    parse-template call ;
+    parse-template call( -- ) ;
 
 TUPLE: fhtml path ;
 
 C: <fhtml> fhtml
 
-M: fhtml call-template* ( filename -- )
-    '[ _ path>> utf8 file-contents eval-template ] assert-depth ;
+M: fhtml call-template*
+    path>> utf8 file-contents eval-template ;
 
 INSTANCE: fhtml template