Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Created November 26, 2022 10:49
Show Gist options
  • Select an option

  • Save neuro-sys/ec5655a153208687e215735ee1b00a73 to your computer and use it in GitHub Desktop.

Select an option

Save neuro-sys/ec5655a153208687e215735ee1b00a73 to your computer and use it in GitHub Desktop.

Revisions

  1. neuro-sys created this gist Nov 26, 2022.
    27 changes: 27 additions & 0 deletions multi-line-string.fs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    : """s s\" \"\"\"s" ;

    : s""" ( -- caddr u )
    begin
    refill 0= if exit then
    source """s compare 0= if
    refill drop ( ignore the line )
    0 c, ( put zero terminator )
    exit
    then
    source s, \n,
    again
    ;

    ( example )

    create sample-string

    s"""
    This is a
    multi line string
    """s

    \ Print zero terminated string
    : ztype ( addr -- ) begin dup c@ emit 1+ dup c@ 0= until drop ;

    sample-string ztype