(Arne Babenhauserheide)
2013-05-03: line splitting is actually called, but still cuts of the beginning line splitting is actually called, but still cuts of the beginning of the content.
diff --git a/wisp.w b/wisp.w --- a/wisp.w +++ b/wisp.w @@ -104,6 +104,7 @@ define : nostringandbracketbreaks inport ; As next part we have split a text into a list of lines which we can process one by one. +; FIXME: Cuts off the beginning of the content. define : splitlines inport let : lines '() @@ -137,47 +138,67 @@ define : splitindent inport when : and inindentunderbar : not : char=? nextchar #\_ set! inindentunderbar #f set! indent : + indent 1 + set! nextchar : read-char inport continue ; check whether we leave the indentation when : and inindent : not : char=? nextchar #\space set! inindent #f set! indent : + indent 1 + set! nextchar : read-char inport continue ; check whether we leave the content when : and ( not incomment ) : char=? nextchar #\; set! commentstart #t set! comment : string-append comment : string nextchar + set! nextchar : read-char inport continue ; check whether we stay in the commentcheck when : and commentstart : char=? nextchar : string-ref commentstartidentifier commentidentifierindex - set! commentidentifierindex : + commentidentifierindex 1 - set! comment : string-append comment : string nextchar - when : = commentidentifierindex : - commentstartidentifierlength 1 - set! commentstart #f - set! incomment #t - ; reset used variables - set! commentidentifierindex 0 - set! comment "" - continue + set! commentidentifierindex : + commentidentifierindex 1 + set! comment : string-append comment : string nextchar + when : = commentidentifierindex : - commentstartidentifierlength 1 + set! commentstart #f + set! incomment #t + ; reset used variables + set! commentidentifierindex 0 + set! comment "" + set! nextchar : read-char inport + continue ; if we cannot complete the commentcheck, we did not start a real comment. Append it to the content when : and commentstart : not : char=? nextchar : string-ref commentstartidentifier commentidentifierindex set! commentstart #f set! content : string-append content comment set! comment "" set! commentidentifierindex 0 + set! nextchar : read-char inport continue ; if we are in the comment, just append to the comment when incomment set! comment : string-append comment : string nextchar + set! nextchar : read-char inport continue ; if nothing else is true, we are in the content set! content : string-append content : string nextchar + set! nextchar : read-char inport ; return the indentation, the content and the comment - ' indent content comment + list indent content comment + + +; Now use the function to split a list of lines +define : linestoindented lines + let + : split '() + lineindex 0 + nextline : list-ref lines 0 + while : < ( + lineindex 1 ) : length lines + set! split : append split : list : call-with-input-string nextline splitindent + set! lineindex : + lineindex 1 + set! nextline : list-ref lines lineindex + + . split ; first step: Be able to mirror a file to stdout - let* : filename : list-ref ( command-line ) 1 origfile : open-file filename "r" ; mode @@ -190,6 +211,8 @@ let* set! text : call-with-input-string text nostringandbracketbreaks ; display text set! lines : call-with-input-string text splitlines - ; display : list-ref lines 0 + set! lines : linestoindented lines + display : list-ref lines 100 + newline