]> gitweb.factorcode.org Git - factor.git/blob - basis/multiline/multiline.factor
Multiline cleanup and bug fix
[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 make parser lexer kernel sequences words
4 quotations math accessors locals ;
5 IN: multiline
6
7 <PRIVATE
8 : next-line-text ( -- str )
9     lexer get dup next-line line-text>> ;
10
11 : (parse-here) ( -- )
12     next-line-text [
13         dup ";" =
14         [ drop lexer get next-line ]
15         [ % "\n" % (parse-here) ] if
16     ] [ ";" unexpected-eof ] if* ;
17 PRIVATE>
18
19 : parse-here ( -- str )
20     [ (parse-here) ] "" make but-last
21     lexer get next-line ;
22
23 : STRING:
24     CREATE-WORD
25     parse-here 1quotation
26     (( -- string )) define-inline ; parsing
27
28 <PRIVATE
29
30 :: (parse-multiline-string) ( i end -- j )
31     lexer get line-text>> :> text
32     text [
33         end text i start*
34         [| j | i j text subseq % j end length + ] [
35             text i tail % CHAR: \n ,
36             lexer get next-line
37             0 end (parse-multiline-string)
38         ] if*
39     ] [ end unexpected-eof ] if ;
40         
41 PRIVATE>
42
43 : parse-multiline-string ( end-text -- str )
44     [
45         lexer get
46         [ 1+ swap (parse-multiline-string) ]
47         change-column drop
48     ] "" make ;
49
50 : <"
51     "\">" parse-multiline-string parsed ; parsing
52
53 : /* "*/" parse-multiline-string drop ; parsing