Merge branch 'master' of git://factorcode.org/git/factor

db4
Slava Pestov 2008-02-26 17:34:21 -06:00
commit fe37c87d2f
3 changed files with 57 additions and 10 deletions

View File

@ -24,3 +24,19 @@ IN: temporary
[ "<p>foo</p>\n<p>bar</p>" ] [ "foo\n\n\nbar" parse-farkup ] unit-test [ "<p>foo</p>\n<p>bar</p>" ] [ "foo\n\n\nbar" parse-farkup ] unit-test
[ "" ] [ "" parse-farkup ] unit-test [ "" ] [ "" parse-farkup ] unit-test
[ "<p>|a</p>" ]
[ "|a" parse-farkup ] unit-test
[ "<p>|a|</p>" ]
[ "|a|" parse-farkup ] unit-test
[ "<table><tr><td>a</td><td>b</td></tr></table>" ]
[ "a|b" parse-farkup ] unit-test
[ "<table><tr><td>a</td><td>b</td></tr></table>\n<table><tr><td>c</td><td>d</td></tr></table>" ]
[ "a|b\nc|d" parse-farkup ] unit-test
[ "<table><tr><td>a</td><td>b</td></tr></table>\n<table><tr><td>c</td><td>d</td></tr></table>\n" ]
[ "a|b\nc|d\n" parse-farkup ] unit-test

View File

@ -82,15 +82,16 @@ MEMO: list ( -- parser )
list-item "\n" token hide list-of list-item "\n" token hide list-of
[ "ul" surround-with-foo ] action ; [ "ul" surround-with-foo ] action ;
MEMO: table-column ( -- parser ) [ "|" token text ] seq* ; MEMO: table-column ( -- parser )
text [ "td" surround-with-foo ] action ;
MEMO: table-row ( -- parser ) MEMO: table-row ( -- parser )
[ [
"|" table-column "|" token hide list-of* ,
] seq* ; ] seq* [ "tr" surround-with-foo ] action ;
MEMO: table ( -- parser ) MEMO: table ( -- parser )
[ table-row repeat1 [ "table" surround-with-foo ] action ;
"|"
] seq* ;
MEMO: code ( -- parser ) MEMO: code ( -- parser )
[ [
@ -122,9 +123,26 @@ MEMO: paragraph ( -- parser )
MEMO: farkup ( -- parser ) MEMO: farkup ( -- parser )
[ [
list , h1 , h2 , h3 , h4 , code , paragraph , 2nl , nl , list , table , h1 , h2 , h3 , h4 , code , paragraph , 2nl , nl ,
] choice* repeat0 "\n" token optional 2seq ; ] choice* repeat0 "\n" token optional 2seq ;
: farkup. ( parse-result -- )
parse-result-ast
[ dup string? [ write ] [ drop ] if ] deep-each ;
: parse-farkup ( string -- string' ) : parse-farkup ( string -- string' )
farkup parse parse-result-ast farkup parse [ farkup. ] with-string-writer ;
[ [ dup string? [ write ] [ drop ] if ] deep-each ] with-string-writer ;
! MEMO: table-column ( -- parser )
! text [ "td" surround-with-foo ] action ;
!
! MEMO: table-row ( -- parser )
! [
! "|" token hide ,
! table-column "|" token hide list-of ,
! "|" token "\n" token 2array choice hide ,
! ] seq* [ "tr" surround-with-foo ] action ;
!
! MEMO: table ( -- parser )
! table-row repeat1
! [ "table" surround-with-foo ] action ;

View File

@ -318,6 +318,12 @@ MEMO: range ( min max -- parser )
: choice ( seq -- parser ) : choice ( seq -- parser )
choice-parser construct-boa init-parser ; choice-parser construct-boa init-parser ;
: 2choice ( parser1 parser2 -- parser )
2array choice ;
: 3choice ( parser1 parser2 parser3 -- parser )
3array choice ;
: choice* ( quot -- paser ) : choice* ( quot -- paser )
{ } make choice ; inline { } make choice ; inline
@ -348,8 +354,15 @@ MEMO: hide ( parser -- parser )
MEMO: delay ( parser -- parser ) MEMO: delay ( parser -- parser )
delay-parser construct-boa init-parser ; delay-parser construct-boa init-parser ;
MEMO: (list-of) ( items separator repeat1? -- parser )
>r over 2seq r> [ repeat1 ] [ repeat0 ] if [ concat ] action 2seq
[ unclip 1vector swap first append ] action ;
MEMO: list-of ( items separator -- parser ) MEMO: list-of ( items separator -- parser )
hide over 2seq repeat0 [ concat ] action 2seq [ unclip 1vector swap first append ] action ; hide f (list-of) ;
MEMO: list-of* ( items separator -- parser )
hide t (list-of) ;
MEMO: 'digit' ( -- parser ) MEMO: 'digit' ( -- parser )
[ digit? ] satisfy [ digit> ] action ; [ digit? ] satisfy [ digit> ] action ;