From fd63917d8b78bd6a522345cf5d4ebabc478aa375 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Tue, 11 Dec 2007 01:39:32 -0500 Subject: [PATCH] Multiline string literals --- extra/multiline/authors.txt | 1 + extra/multiline/multiline-docs.factor | 8 ++++++++ extra/multiline/multiline.factor | 19 +++++++++++++++++++ extra/multiline/summary.txt | 1 + 4 files changed, 29 insertions(+) create mode 100644 extra/multiline/authors.txt create mode 100644 extra/multiline/multiline-docs.factor create mode 100644 extra/multiline/multiline.factor create mode 100644 extra/multiline/summary.txt diff --git a/extra/multiline/authors.txt b/extra/multiline/authors.txt new file mode 100644 index 0000000000..f990dd0ed2 --- /dev/null +++ b/extra/multiline/authors.txt @@ -0,0 +1 @@ +Daniel Ehrenberg diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor new file mode 100644 index 0000000000..15d3ead705 --- /dev/null +++ b/extra/multiline/multiline-docs.factor @@ -0,0 +1,8 @@ +USING: help.markup help.syntax multiline ; + +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 and at the end." } ; + +IN: multiline +ABOUT: POSTPONE: STRING: diff --git a/extra/multiline/multiline.factor b/extra/multiline/multiline.factor new file mode 100644 index 0000000000..e55112a5f0 --- /dev/null +++ b/extra/multiline/multiline.factor @@ -0,0 +1,19 @@ +! Copyright (C) 2007 Daniel Ehrenberg +! See http://factorcode.org/license.txt for BSD license. +USING: namespaces parser kernel sequences words quotations ; +IN: multiline + +: next-line-text ( -- str ) + lexer get dup next-line line-text ; + +: (parse-here) ( -- ) + next-line-text dup ";" = + [ drop lexer get next-line ] [ % "\n" % (parse-here) ] if ; + +: parse-here ( -- str ) + [ (parse-here) ] "" make + lexer get next-line ; + +: STRING: + CREATE dup reset-generic + parse-here 1quotation define-compound ; parsing diff --git a/extra/multiline/summary.txt b/extra/multiline/summary.txt new file mode 100644 index 0000000000..9d9c3ea73f --- /dev/null +++ b/extra/multiline/summary.txt @@ -0,0 +1 @@ +Multiline string literals