Multiline cleanup and bug fix
parent
67dd4ca4a4
commit
5221193034
|
@ -14,3 +14,5 @@ bar
|
||||||
|
|
||||||
[ "hello\nworld" ] [ <" hello
|
[ "hello\nworld" ] [ <" hello
|
||||||
world"> ] unit-test
|
world"> ] unit-test
|
||||||
|
|
||||||
|
[ "hello" "world" ] [ <" hello"> <" world"> ] unit-test
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2007 Daniel Ehrenberg
|
! Copyright (C) 2007 Daniel Ehrenberg
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: namespaces make parser lexer kernel sequences words
|
USING: namespaces make parser lexer kernel sequences words
|
||||||
quotations math accessors ;
|
quotations math accessors locals ;
|
||||||
IN: multiline
|
IN: multiline
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -26,20 +26,26 @@ PRIVATE>
|
||||||
(( -- string )) define-inline ; parsing
|
(( -- string )) define-inline ; parsing
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
: (parse-multiline-string) ( start-index end-text -- end-index )
|
|
||||||
lexer get line-text>> [
|
:: (parse-multiline-string) ( i end -- j )
|
||||||
2dup start
|
lexer get line-text>> :> text
|
||||||
[ rot dupd [ swap subseq % ] 2dip length + ] [
|
text [
|
||||||
rot tail % "\n" % 0
|
end text i start*
|
||||||
lexer get next-line swap (parse-multiline-string)
|
[| j | i j text subseq % j end length + ] [
|
||||||
|
text i tail % CHAR: \n ,
|
||||||
|
lexer get next-line
|
||||||
|
0 end (parse-multiline-string)
|
||||||
] if*
|
] if*
|
||||||
] [ nip unexpected-eof ] if* ;
|
] [ end unexpected-eof ] if ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: parse-multiline-string ( end-text -- str )
|
: parse-multiline-string ( end-text -- str )
|
||||||
[
|
[
|
||||||
lexer get [ swap (parse-multiline-string) ] change-column drop
|
lexer get
|
||||||
] "" make rest ;
|
[ 1+ swap (parse-multiline-string) ]
|
||||||
|
change-column drop
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
: <"
|
: <"
|
||||||
"\">" parse-multiline-string parsed ; parsing
|
"\">" parse-multiline-string parsed ; parsing
|
||||||
|
|
Loading…
Reference in New Issue