diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor index d2d9c7967f..05ccdefe6f 100644 --- a/extra/multiline/multiline-docs.factor +++ b/extra/multiline/multiline-docs.factor @@ -4,5 +4,18 @@ HELP: STRING: { $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 diff --git a/extra/multiline/multiline-tests.factor b/extra/multiline/multiline-tests.factor index 5ef289f4c3..a9b9ee2322 100644 --- a/extra/multiline/multiline-tests.factor +++ b/extra/multiline/multiline-tests.factor @@ -7,3 +7,6 @@ bar ; [ "foo\nbar\n" ] [ test-it ] unit-test +[ "foo\nbar\n" ] [ <" foo +bar + "> ] unit-test diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor index 1229dcc689..e808b78997 100644 --- a/extra/multiline/multiline.factor +++ b/extra/multiline/multiline.factor @@ -1,6 +1,6 @@ ! 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 ) @@ -17,3 +17,19 @@ IN: multiline : 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