git @ Cat's Eye Technologies Tamsin / master eg / csv_extract.tamsin
master

Tree @master (Download .tar.gz)

csv_extract.tamsin @masterraw · history · blame

# This example Tamsin program was written by Chris Pressey, and is
# hereby placed in the public domain.  It comes with NO WARRANTY.

main = line → L & L ← lines(nil, L) &
       {"\n" & line → M & L ← lines(L, M)} & extract(L) & ''.
line = field → F & {"," & field → G & F ← fields(G, F)} & F.
field = strings | bare.
strings = string → T & {string → S & T ← T + '"' + S} & T.
string = "\"" & T ← '' & {!"\"" & any → S & T ← T + S} & "\"" & T.
bare = T ← '' & {!(","|"\n") & any → S & T ← T + S} & T.
extract(lines(Lines, Line)) = extract(Lines) & extract_field(Line).
extract(L) = L.
extract_field(fields(Last, fields(This, X))) = print This.
extract_field(X) = return X.