]> gitweb.factorcode.org Git - factor.git/blob - extra/literate/literate.factor
e3ad04fadcd9b9c58578a44113b1de6c1c6f5097
[factor.git] / extra / literate / literate.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: accessors combinators.short-circuit compiler.units kernel
4 lexer math multiline parser sequences splitting ;
5
6 IN: literate
7
8 TUPLE: literate-lexer < lexer ;
9
10 : <literate-lexer> ( text -- lexer ) literate-lexer new-lexer ;
11
12 M: literate-lexer skip-blank
13     dup column>> zero? [
14         dup line-text>> [
15             "> " head?
16             [ [ 2 + ] change-column call-next-method ]
17             [ [ nip length ] change-lexer-column ]
18             if
19         ] [ drop ] if*
20     ] [ call-next-method ] if ;
21
22 SYNTAX: <LITERATE
23     "LITERATE>" parse-multiline-string string-lines [
24         <literate-lexer> (parse-lines) append!
25     ] with-nested-compilation-unit ;