From 604dbf4df7f3530cdfe6e412a3c6b4d66eea0c61 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 3 Sep 2011 12:17:30 -0500 Subject: [PATCH] parse-here doesn't consume an extra line now, and it checks that once a line has started there are no extra characters --- basis/multiline/multiline-tests.factor | 23 ++++++++++++++++++++++- basis/multiline/multiline.factor | 16 +++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/basis/multiline/multiline-tests.factor b/basis/multiline/multiline-tests.factor index ad624dd917..3a4e3dd62e 100644 --- a/basis/multiline/multiline-tests.factor +++ b/basis/multiline/multiline-tests.factor @@ -1,4 +1,4 @@ -USING: accessors eval multiline tools.test ; +USING: accessors eval multiline sequences tools.test ; IN: multiline.tests STRING: test-it @@ -78,3 +78,24 @@ lolaol ] unit-test [ "whoa" ] [ DELIMITED: factor blows my mind whoafactor blows my mind ] unit-test + +<< +SYNTAX: MULTILINE-LITERAL: parse-here suffix! ; +>> + +[ { "bar" } ] +[ + CONSTANT: foo { MULTILINE-LITERAL: +bar +; +} foo +] unit-test + + +! Make sure parse-here fails if extra crap appears on the first line +[ + "CONSTANT: foo { MULTILINE-LITERAL: asdfasfdasdfas +bar +; +}" eval +] must-fail diff --git a/basis/multiline/multiline.factor b/basis/multiline/multiline.factor index 5182c33e59..1b62513abf 100644 --- a/basis/multiline/multiline.factor +++ b/basis/multiline/multiline.factor @@ -7,6 +7,10 @@ IN: multiline ERROR: bad-heredoc identifier ; > ] [ column>> ] bi tail ; + : next-line-text ( -- str ) lexer get dup next-line line-text>> ; @@ -16,11 +20,16 @@ ERROR: bad-heredoc identifier ; [ drop lexer get next-line ] [ % "\n" % (parse-here) ] if ] [ ";" unexpected-eof ] if* ; + PRIVATE> +ERROR: text-found-before-eol string ; + : parse-here ( -- str ) - [ (parse-here) ] "" make but-last - lexer get next-line ; + [ + rest-of-line dup [ drop ] [ text-found-before-eol ] if-empty + (parse-here) + ] "" make but-last ; SYNTAX: STRING: CREATE-WORD @@ -48,9 +57,6 @@ SYNTAX: STRING: change-column drop ] "" make ; -: rest-of-line ( -- seq ) - lexer get [ line-text>> ] [ column>> ] bi tail ; - :: advance-same-line ( text -- ) lexer get [ text length + ] change-column drop ; -- 2.34.1