factor/basis/multiline/multiline.factor

64 lines
1.4 KiB
Factor
Raw Normal View History

2007-12-11 01:39:32 -05:00
! Copyright (C) 2007 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
2008-09-10 23:11:40 -04:00
USING: namespaces make parser lexer kernel sequences words
2009-01-20 17:12:09 -05:00
quotations math accessors locals ;
2007-12-11 01:39:32 -05:00
IN: multiline
2008-09-04 22:38:23 -04:00
<PRIVATE
2007-12-11 01:39:32 -05:00
: next-line-text ( -- str )
2008-08-31 03:28:58 -04:00
lexer get dup next-line line-text>> ;
2007-12-11 01:39:32 -05:00
: (parse-here) ( -- )
2008-02-07 18:12:50 -05:00
next-line-text [
dup ";" =
[ drop lexer get next-line ]
[ % "\n" % (parse-here) ] if
] [ ";" unexpected-eof ] if* ;
2008-09-04 22:38:23 -04:00
PRIVATE>
2007-12-11 01:39:32 -05:00
: parse-here ( -- str )
2008-05-07 02:38:34 -04:00
[ (parse-here) ] "" make but-last
2007-12-11 01:39:32 -05:00
lexer get next-line ;
SYNTAX: STRING:
2008-03-16 03:43:00 -04:00
CREATE-WORD
parse-here 1quotation
(( -- string )) define-inline ;
2007-12-11 17:23:56 -05:00
2008-09-04 22:38:23 -04:00
<PRIVATE
2009-01-20 17:12:09 -05:00
:: (parse-multiline-string) ( i end -- j )
lexer get line-text>> :> text
text [
2009-01-21 01:44:43 -05:00
end text i start* [| j |
i j text subseq % j end length +
] [
text i short tail % CHAR: \n ,
2009-01-20 17:12:09 -05:00
lexer get next-line
0 end (parse-multiline-string)
2008-02-07 18:12:50 -05:00
] if*
2009-01-20 17:12:09 -05:00
] [ end unexpected-eof ] if ;
2008-09-04 22:38:23 -04:00
PRIVATE>
2007-12-11 17:23:56 -05:00
2007-12-12 00:33:36 -05:00
: parse-multiline-string ( end-text -- str )
2007-12-11 17:23:56 -05:00
[
2009-01-20 17:12:09 -05:00
lexer get
[ 1+ swap (parse-multiline-string) ]
change-column drop
] "" make ;
2007-12-11 17:23:56 -05:00
SYNTAX: <"
"\">" parse-multiline-string parsed ;
SYNTAX: <'
"'>" parse-multiline-string parsed ;
2009-01-21 19:17:06 -05:00
SYNTAX: {'
"'}" parse-multiline-string parsed ;
2009-01-21 19:17:06 -05:00
SYNTAX: {"
"\"}" parse-multiline-string parsed ;
2009-01-21 19:17:06 -05:00
SYNTAX: /* "*/" parse-multiline-string drop ;