From fe6f537b3e23ad201ba6236a6cedef2e565349a7 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Mon, 2 Jan 2017 12:33:55 +0100 Subject: [PATCH] Add support for multi-line ( comments * fth/file.fth ((): Redefine. (MULTI-LINE-COMMENT): New helper. * fth/t_file.fth: Uncomment test for multi line comments. --- fth/file.fth | 19 +++++++++++++++++++ fth/t_file.fth | 12 ++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/fth/file.fth b/fth/file.fth index b71edc5..6b0db20 100644 --- a/fth/file.fth +++ b/fth/file.fth @@ -61,6 +61,16 @@ create (LINE-TERMINATOR) \n c, 0 2r> + c! ( ) ; +: MULTI-LINE-COMMENT ( "comment" -- ) + BEGIN + >in @ ')' parse ( >in c-addr len ) + nip + >in @ = ( delimiter-not-found? ) + WHILE ( ) + refill 0= IF EXIT THEN ( ) + REPEAT + +; + }private \ This treats \n, \r\n, and \r as line terminator. Reading is done @@ -108,4 +118,13 @@ create (LINE-TERMINATOR) \n c, THEN ; +: ( ( "comment" -- ) + source-id + CASE + -1 OF postpone ( ENDOF + 0 OF postpone ( ENDOF + multi-line-comment + ENDCASE +; immediate + privatize diff --git a/fth/t_file.fth b/fth/t_file.fth index f024926..10f434f 100644 --- a/fth/t_file.fth +++ b/fth/t_file.fth @@ -215,12 +215,12 @@ T{ FN2 R/W BIN OPEN-FILE SWAP DROP 0= -> FALSE }T T{ FN2 DELETE-FILE 0= -> FALSE }T \ ---------------------------------------------------------------------------- -\ TESTING multi-line ( comments -\ -\ T{ ( 1 2 3 -\ 4 5 6 -\ 7 8 9 ) 11 22 33 -> 11 22 33 }T -\ +TESTING multi-line ( comments + +T{ ( 1 2 3 +4 5 6 +7 8 9 ) 11 22 33 -> 11 22 33 }T + \ ---------------------------------------------------------------------------- TESTING SOURCE-ID (can only test it does not return 0 or -1) -- 2.20.1