]> gitweb.factorcode.org Git - factor.git/blob - basis/multiline/multiline.factor
Merge branch 'master' into new_ui
[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* [| j |
34             i j text subseq % j end length +
35         ] [
36             text i short tail % CHAR: \n ,
37             lexer get next-line
38             0 end (parse-multiline-string)
39         ] if*
40     ] [ end unexpected-eof ] if ;
41         
42 PRIVATE>
43
44 : parse-multiline-string ( end-text -- str )
45     [
46         lexer get
47         [ 1+ swap (parse-multiline-string) ]
48         change-column drop
49     ] "" make ;
50
51 : <"
52     "\">" parse-multiline-string parsed ; parsing
53
54 : /* "*/" parse-multiline-string drop ; parsing