( Title: Line-File Input Test File: lfinput-test.fs Author: David N. Williams License: LGPL Version: 0.5.6 Last revision: August 21, 2021 ) 53 constant MAX-/LINE \ 52 constant MAX-/LINE \ should ABORT on line 3 of lftest.txt \ 1 constant MAX-FILE-DEPTH \ no nesting 2 constant MAX-FILE-DEPTH \ Uncomment the following line to test with the PFE parsing module. \ true CONSTANT USE-PFE-PARSING s" lfinput.fs" included USE-PFE-PARSING [IF] cr .( Using the PFE parsing external module.) cr [ELSE] cr .( Using parsing.fs.) cr [THEN] : >type< ( s -- ) ." =|" type ." |=" ; : next-type ( -- ) next-lfinput-name >type< ; : parse-area-type ( -- ) lfparse-area@ >type< ; : ?true ( flag -- ) ABORT" ***LFPARSE flag should be TRUE." ; : ?false ( flag -- ) 0= ABORT" ***LFPARSE flag should be FALSE." ; : open-test1 ( -- ) s" lftest1.txt" r/o open-file throw to lfid ; : open-test2 ( -- ) s" lftest2.txt" r/o open-file throw to lfid ; : close-lfid ( -- ) lfid close-file throw ; open-test1 cr .( First word in lftest1.txt: ) next-type MAX-FILE-DEPTH 1 u> [IF] save-lfin open-test2 cr .( First word in lftest2.txt: ) next-type close-lfid restore-lfin [THEN] cr .( Second word in lftest1.txt: ) next-type cr .( Rest of the first line: ) parse-area-type lfrefill drop cr .( Next line is empty: ) parse-area-type cr .( We're about to read the third line.) MAX-/LINE 53 < [IF] cr .( Since MAX-/LINE = ) MAX-/LINE . .( < 53, the test should abort.) [ELSE] cr .( Since MAX-/LINE = ) MAX-/LINE . .( >= 53, the test should not abort.) [THEN] lfrefill drop cr .( Fine, it didn't. Next line: ) cr 2 spaces parse-area-type cr .( Substrings before and after "x":) cr 2 spaces char x lfparse ?false >type< cr 2 spaces parse-area-type cr .( The after part again, followed by the empty string:) cr 2 spaces char q lfparse ?true >type< 2 spaces parse-area-type cr .( First word of the fourth line: ) next-type empty-lfparse-area next-lfinput-name cr .( We've executed EMPTY-LFPARSE-AREA NEXT-LFINPUT-NAME, cr .( should be empty: ) >type< close-lfid cr MAX-FILE-DEPTH 1 u> [IF] cr .( SEAMLESSNESS OF SAVE-LFIN ... RESTORE-LFIN:) cr .( First we exhaust the first line of lftest2.txt and) cr .( type the parse area: ) open-test2 lfrefill drop empty-lfparse-area lfparse-area@ >type< close-lfid cr .( Next we exhaust the first line, SAVE-LFIN RESTORE-LFIN,) cr .( then type the parse area: ) open-test2 lfrefill drop empty-lfparse-area lfpos 2@ >lfin 0 d+ save-lfin restore-lfin lfparse-area@ >type< cr .( The file position is ) lfpos 2@ d= [IF] .( CORRECT.) [ELSE] .( WRONG.) [THEN] close-lfid cr [THEN]