]> gitweb.factorcode.org Git - factor.git/blob - basis/multiline/multiline.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / multiline / multiline.factor
1 ! Copyright (C) 2007 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces parser lexer kernel sequences words quotations math
4 accessors ;
5 IN: multiline
6
7 : next-line-text ( -- str )
8     lexer get dup next-line line-text>> ;
9
10 : (parse-here) ( -- )
11     next-line-text [
12         dup ";" =
13         [ drop lexer get next-line ]
14         [ % "\n" % (parse-here) ] if
15     ] [ ";" unexpected-eof ] if* ;
16
17 : parse-here ( -- str )
18     [ (parse-here) ] "" make but-last
19     lexer get next-line ;
20
21 : STRING:
22     CREATE-WORD
23     parse-here 1quotation define-inline ; parsing
24
25 : (parse-multiline-string) ( start-index end-text -- end-index )
26     lexer get line-text>> [
27         2dup start
28         [ rot dupd >r >r swap subseq % r> r> length + ] [
29             rot tail % "\n" % 0
30             lexer get next-line swap (parse-multiline-string)
31         ] if*
32     ] [ nip unexpected-eof ] if* ;
33
34 : parse-multiline-string ( end-text -- str )
35     [
36         lexer get column>> swap (parse-multiline-string)
37         lexer get (>>column)
38     ] "" make rest but-last ;
39
40 : <"
41     "\">" parse-multiline-string parsed ; parsing
42
43 : /* "*/" parse-multiline-string drop ; parsing