]> 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 ;
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 : (parse-multiline-string) ( start-index end-text -- end-index )
30     lexer get line-text>> [
31         2dup start
32         [ rot dupd [ swap subseq % ] 2dip length + ] [
33             rot tail % "\n" % 0
34             lexer get next-line swap (parse-multiline-string)
35         ] if*
36     ] [ nip unexpected-eof ] if* ;
37 PRIVATE>
38
39 : parse-multiline-string ( end-text -- str )
40     [
41         lexer get [ swap (parse-multiline-string) ] change-column drop
42     ] "" make rest ;
43
44 : <"
45     "\">" parse-multiline-string parsed ; parsing
46
47 : /* "*/" parse-multiline-string drop ; parsing