X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=blobdiff_plain;f=basis%2Fmultiline%2Fmultiline.factor;h=c6d5576347a7122ed29eab33f6b27b209e756b57;hp=930e5b9f1ce63936d40298c39eca1cbec1247dd5;hb=f2db336221c17d3dafc0faf85371a86a330242f7;hpb=0643cf3a4403bc0f6090ccc3b3346d4a942c2973 diff --git a/basis/multiline/multiline.factor b/basis/multiline/multiline.factor index 930e5b9f1c..c6d5576347 100644 --- a/basis/multiline/multiline.factor +++ b/basis/multiline/multiline.factor @@ -1,47 +1,85 @@ ! Copyright (C) 2007 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: namespaces make parser lexer kernel sequences words -quotations math accessors ; +USING: accessors kernel lexer make math namespaces parser +quotations sequences strings.parser.private words ; IN: multiline > ; -: (parse-here) ( -- ) - next-line-text [ +: rest-of-line ( lexer -- seq ) + [ line-text>> ] [ column>> ] bi tail ; + +: next-line-text ( lexer -- str ? ) + [ next-line ] [ line-text>> ] [ still-parsing? ] tri ; + +: (parse-here) ( lexer -- ) + dup next-line-text [ dup ";" = - [ drop lexer get next-line ] - [ % "\n" % (parse-here) ] if - ] [ ";" unexpected-eof ] if* ; + [ drop next-line ] + [ % CHAR: \n , (parse-here) ] if + ] [ ";" throw-unexpected-eof ] if ; + PRIVATE> +ERROR: text-found-before-eol string ; + : parse-here ( -- str ) - [ (parse-here) ] "" make but-last - lexer get next-line ; + [ + lexer get + dup rest-of-line [ text-found-before-eol ] unless-empty + (parse-here) + ] "" make but-last ; -: STRING: - CREATE-WORD +SYNTAX: STRING: + scan-new-word parse-here 1quotation - (( -- string )) define-inline ; parsing + ( -- string ) define-inline ; > [ - 2dup start - [ rot dupd [ swap subseq % ] 2dip length + ] [ - rot tail % "\n" % 0 - lexer get next-line swap (parse-multiline-string) + +:: (scan-multiline-string) ( i end lexer -- j ) + lexer line-text>> :> text + lexer still-parsing? [ + i text end subseq-index-from [| j | + i j text subseq % j end length + + ] [ + text i index-or-length tail % CHAR: \n , + lexer next-line + 0 end lexer (scan-multiline-string) ] if* - ] [ nip unexpected-eof ] if* ; + ] [ end throw-unexpected-eof ] if ; + +:: (parse-multiline-string) ( end-text lexer skip-n-chars -- str ) + [ + lexer + [ skip-n-chars + end-text lexer (scan-multiline-string) ] + change-column check-space + ] "" make ; + +: advance-same-line ( lexer text -- ) + length [ + ] curry change-column drop ; + PRIVATE> : parse-multiline-string ( end-text -- str ) - [ - lexer get [ swap (parse-multiline-string) ] change-column drop - ] "" make rest ; + lexer get 1 (parse-multiline-string) ; + +SYNTAX: /* "*/" parse-multiline-string drop ; + +SYNTAX: (( "))" parse-multiline-string drop ; -: <" - "\">" parse-multiline-string parsed ; parsing +SYNTAX: [[ "]]" parse-multiline-string suffix! ; +SYNTAX: [=[ "]=]" parse-multiline-string suffix! ; +SYNTAX: [==[ "]==]" parse-multiline-string suffix! ; +SYNTAX: [===[ "]===]" parse-multiline-string suffix! ; +SYNTAX: [====[ "]====]" parse-multiline-string suffix! ; +SYNTAX: [=====[ "]=====]" parse-multiline-string suffix! ; +SYNTAX: [======[ "]======]" parse-multiline-string suffix! ; -: /* "*/" parse-multiline-string drop ; parsing +SYNTAX: ![[ "]]" parse-multiline-string drop ; +SYNTAX: ![=[ "]=]" parse-multiline-string drop ; +SYNTAX: ![==[ "]==]" parse-multiline-string drop ; +SYNTAX: ![===[ "]===]" parse-multiline-string drop ; +SYNTAX: ![====[ "]====]" parse-multiline-string drop ; +SYNTAX: ![=====[ "]=====]" parse-multiline-string drop ; +SYNTAX: ![======[ "]======]" parse-multiline-string drop ;