{ $syntax "STRING: name\nfoo\n;" }
{ $description "Forms a multiline string literal, or 'here document' stored in the word called name. A semicolon is used to signify the end, and that semicolon must be on a line by itself, not preceeded or followed by any whitespace. The string will have newlines in between lines but not at the end, unless there is a blank line before the semicolon." } ;
-IN: multiline
-ABOUT: POSTPONE: STRING:
+HELP: <"
+{ $syntax "<\" text \">" }
+{ $description "This forms a multiline string literal ending in \">. Unlike the " { $link POSTPONE: STRING: } " form, you can end it in the middle of a line. This construct is non-nesting. In the example above, the string would be parsed as \"text\"." } ;
+
+{ POSTPONE: <" POSTPONE: STRING: } related-words
+
+HELP: parse-here
+{ $values { "str" "a string" } }
+{ $description "Parses a multiline string literal, as used by " { $link POSTPONE: STRING: } "." } ;
+
+HELP: parse-literal
+{ $values { "end-text" "a string delineating the end" } { "str" "the parsed string" } }
+{ $description "Parses a multiline string literal, as used by " { $link POSTPONE: <" } ". The end-text is the delimiter for the end." } ;
+
+{ parse-here parse-literal } related-words
! Copyright (C) 2007 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces parser kernel sequences words quotations ;
+USING: namespaces parser kernel sequences words quotations math ;
IN: multiline
: next-line-text ( -- str )
: STRING:
CREATE dup reset-generic
parse-here 1quotation define-compound ; parsing
+
+: (parse-literal) ( start-index end-text -- end-index )
+ lexer get line-text 2dup start
+ [ rot dupd >r >r swap subseq % r> r> length + ] [
+ rot tail % "\n" % 0
+ lexer get next-line swap (parse-literal)
+ ] if* ;
+
+: parse-literal ( end-text -- str )
+ [
+ lexer get lexer-column swap (parse-literal)
+ lexer get set-lexer-column
+ ] "" make 1 tail 1 head* ;
+
+: <"
+ "\">" parse-literal parsed ; parsing