Paste: table-syntax

Author: anatoo
Mode: factor
Date: Tue, 14 Apr 2009 07:46:01
Plain Text |
IN: table-syntax
USING: parser arrays sequences splitting kernel ;

DEFER: |
DEFER: |}

: (split-|_|) ( ex seq -- seq' )
  { | | } split1 [ suffix ] dip dup [ (split-|_|) ] [ drop ] if ;
  
: split-|_| ( seq -- seq' ) { } swap (split-|_|) ;

: split-| ( seq -- seq' ) { | } split ;

: 1array>first ( array -- array/first ) dup length 1 = [ first ] when ;

: process ( array -- array' ) split-|_| [ split-| 1array>first ] map 1array>first ;

: {| \ |} [ >array process ] parse-literal ; parsing

! ( scratchpad ) {| 1 2 3 |
!                 | 3 4 5 |} .
! { { 1 2 3 } { 4 5 6 } } 

! ( scratchpad ) {| 1 2 | 3 4 |} .
! { { 1 2 } { 3 4 } } 

! ( scratchpad ) {| 1 2 | 3 4 |
!                 | 5 6 | 7 8 |} .
! { { { 1 2 } { 3 4 } } { { 5 6 } { 7 8 } } } 

! ( scratchpad ) {| 1 2 3 |} .
! { 1 2 3 }

New Annotation

Summary:
Author:
Mode:
Body: