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 strings.parser
5 strings.parser.private words ;
10 : rest-of-line ( lexer -- seq )
11 [ line-text>> ] [ column>> ] bi tail ;
13 : next-line-text ( lexer -- str ? )
14 [ next-line ] [ line-text>> ] [ still-parsing? ] tri ;
16 : (parse-here) ( lexer -- )
20 [ % CHAR: \n , (parse-here) ] if
21 ] [ ";" throw-unexpected-eof ] if ;
25 ERROR: text-found-before-eol string ;
27 : parse-here ( -- str )
30 dup rest-of-line [ text-found-before-eol ] unless-empty
37 ( -- string ) define-inline ;
41 :: (scan-multiline-string) ( i end lexer -- j )
42 lexer line-text>> :> text
43 lexer still-parsing? [
44 i text end subseq-index-from [| j |
45 i j text subseq % j end length +
47 text i index-or-length tail % CHAR: \n ,
49 0 end lexer (scan-multiline-string)
51 ] [ end throw-unexpected-eof ] if ;
53 :: (parse-multiline-string) ( end-text lexer skip-n-chars -- str )
56 [ skip-n-chars + end-text lexer (scan-multiline-string) ]
57 change-column check-space
60 : advance-same-line ( lexer text -- )
61 length [ + ] curry change-column drop ;
65 : parse-multiline-string ( end-text -- str )
66 lexer get 1 (parse-multiline-string) ;
68 SYNTAX: /* "*/" parse-multiline-string drop ;
70 SYNTAX: [[ "]]" parse-multiline-string suffix! ;
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! ;
78 SYNTAX: ![[ "]]" parse-multiline-string drop ;
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 ;