]> gitweb.factorcode.org Git - factor.git/commitdiff
Multiline string literals
authorDaniel Ehrenberg <ehrenbed@carleton.edu>
Tue, 11 Dec 2007 06:39:32 +0000 (01:39 -0500)
committerDaniel Ehrenberg <ehrenbed@carleton.edu>
Tue, 11 Dec 2007 06:39:32 +0000 (01:39 -0500)
extra/multiline/authors.txt [new file with mode: 0644]
extra/multiline/multiline-docs.factor [new file with mode: 0644]
extra/multiline/multiline.factor [new file with mode: 0644]
extra/multiline/summary.txt [new file with mode: 0644]

diff --git a/extra/multiline/authors.txt b/extra/multiline/authors.txt
new file mode 100644 (file)
index 0000000..f990dd0
--- /dev/null
@@ -0,0 +1 @@
+Daniel Ehrenberg
diff --git a/extra/multiline/multiline-docs.factor b/extra/multiline/multiline-docs.factor
new file mode 100644 (file)
index 0000000..15d3ead
--- /dev/null
@@ -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 (file)
index 0000000..e55112a
--- /dev/null
@@ -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 (file)
index 0000000..9d9c3ea
--- /dev/null
@@ -0,0 +1 @@
+Multiline string literals