! 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 ;
+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
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
: forbid-tab ( c -- c )
[ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ; inline
-: skip ( i seq ? -- n )
- over length [
- [ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop
- ] dip or ; inline
-
<PRIVATE
: shebang? ( lexer -- lexer ? )
] [ f ] if
] [ f ] if ; inline
+: (skip-blank) ( col line -- newcol )
+ [ [ forbid-tab CHAR: \s eq? not ] find-from drop ]
+ [ length or ] bi ;
+
+: (skip-word) ( col line -- newcol )
+ [ [ forbid-tab " \"" member-eq? ] find-from CHAR: \" eq? [ 1 + ] when ]
+ [ length or ] bi ;
+
PRIVATE>
GENERIC: skip-blank ( lexer -- )
shebang? [
[ nip length ] change-lexer-column
] [
- [ t skip ] change-lexer-column
+ [ (skip-blank) ] change-lexer-column
] if ;
GENERIC: skip-word ( lexer -- )
M: lexer skip-word
- [
- 2dup nth CHAR: \" eq? [ drop 1 + ] [ f skip ] if
- ] change-lexer-column ;
+ [ (skip-word) ] change-lexer-column ;
: still-parsing? ( lexer -- ? )
lexer check-instance [ line>> ] [ text>> length ] bi <= ;