1 ! Copyright (C) 2007 Daniel Ehrenberg
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators kernel lexer locals make math
4 namespaces parser quotations sequences words ;
7 ERROR: bad-heredoc identifier ;
11 : rest-of-line ( lexer -- seq )
12 [ line-text>> ] [ column>> ] bi tail ;
14 : next-line-text ( lexer -- str ? )
15 [ next-line ] [ line-text>> ] [ still-parsing? ] tri ;
17 : (parse-here) ( lexer -- )
21 [ % CHAR: \n , (parse-here) ] if
22 ] [ ";" throw-unexpected-eof ] if ;
26 ERROR: text-found-before-eol string ;
28 : parse-here ( -- str )
31 dup rest-of-line [ text-found-before-eol ] unless-empty
38 ( -- string ) define-inline ;
42 :: (scan-multiline-string) ( i end lexer -- j )
43 lexer line-text>> :> text
44 lexer still-parsing? [
45 end text i subseq-start-from [| j |
46 i j text subseq % j end length +
48 text i short tail % CHAR: \n ,
50 0 end lexer (scan-multiline-string)
52 ] [ end throw-unexpected-eof ] if ;
54 :: (parse-multiline-string) ( end-text lexer skip-n-chars -- str )
57 [ skip-n-chars + end-text lexer (scan-multiline-string) ]
61 : advance-same-line ( lexer text -- )
62 length [ + ] curry change-column drop ;
66 : parse-multiline-string ( end-text -- str )
67 lexer get 1 (parse-multiline-string) ;
69 SYNTAX: /* "*/" parse-multiline-string drop ;
71 SYNTAX: [[ "]]" parse-multiline-string suffix! ;
72 SYNTAX: [=[ "]=]" parse-multiline-string suffix! ;
73 SYNTAX: [==[ "]==]" parse-multiline-string suffix! ;
74 SYNTAX: [===[ "]===]" parse-multiline-string suffix! ;
75 SYNTAX: [====[ "]====]" parse-multiline-string suffix! ;
76 SYNTAX: [=====[ "]=====]" parse-multiline-string suffix! ;
77 SYNTAX: [======[ "]======]" parse-multiline-string suffix! ;
79 SYNTAX: ![[ "]]" parse-multiline-string drop ;
80 SYNTAX: ![=[ "]=]" parse-multiline-string drop ;
81 SYNTAX: ![==[ "]==]" parse-multiline-string drop ;
82 SYNTAX: ![===[ "]===]" parse-multiline-string drop ;
83 SYNTAX: ![====[ "]====]" parse-multiline-string drop ;
84 SYNTAX: ![=====[ "]=====]" parse-multiline-string drop ;
85 SYNTAX: ![======[ "]======]" parse-multiline-string drop ;