From fd44378736ec67f44e68bfb34460b303b5be81dd Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 28 Mar 2009 15:29:58 -0500 Subject: [PATCH 1/2] Trailing [[ no longer throws an error in farkup parser --- basis/farkup/farkup-tests.factor | 29 ++++++++++++++++++++++++++++- basis/farkup/farkup.factor | 5 +++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/basis/farkup/farkup-tests.factor b/basis/farkup/farkup-tests.factor index cc379810ac..7cae523efb 100644 --- a/basis/farkup/farkup-tests.factor +++ b/basis/farkup/farkup-tests.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: farkup kernel peg peg.ebnf tools.test namespaces xml -urls.encoding assocs xml.traversal xml.data ; +urls.encoding assocs xml.traversal xml.data sequences random +io continuations math ; IN: farkup.tests relative-link-prefix off @@ -180,3 +181,29 @@ link-no-follow? off [ "

italicsbothafter

" ] [ "_italics*both_after*" convert-farkup ] unit-test [ "
foo|bar
" ] [ "|foo\\|bar|" convert-farkup ] unit-test [ "

" ] [ "\\" convert-farkup ] unit-test + +! [ "

[abc]

" ] [ "[abc]" convert-farkup ] unit-test + +: random-markup ( -- string ) + 10 [ + 2 random 1 = [ + { + "[[" + "*" + "_" + "|" + "-" + "[{" + "\n" + } random + ] [ + "abc" + ] if + ] replicate concat ; + +[ t ] [ + 100 [ + drop random-markup + [ convert-farkup drop t ] [ drop print f ] recover + ] all? +] unit-test diff --git a/basis/farkup/farkup.factor b/basis/farkup/farkup.factor index 23a9023835..41c6c4aa00 100644 --- a/basis/farkup/farkup.factor +++ b/basis/farkup/farkup.factor @@ -75,7 +75,7 @@ DEFER: (parse-paragraph) "|" split1 [ "" like dup simple-link-title ] unless* [ "image:" ?head ] dip swap [ image boa ] [ parse-paragraph link boa ] if - ] dip [ (parse-paragraph) cons ] when* ; + ] dip [ (parse-paragraph) cons ] [ 1list ] if* ; : ?first ( seq -- elt ) 0 swap ?nth ; @@ -187,7 +187,8 @@ DEFER: (parse-paragraph) : parse-code ( state -- state' item ) dup 1 look CHAR: [ = [ unclip-slice make-paragraph ] [ - "{" take-until [ rest ] dip + "{" take-until + [ rest ] dip "}]" take-until [ code boa ] dip swap ] if ; From fe0a71cd88d211975227114cf966fff9d35e3cf6 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 28 Mar 2009 22:13:58 -0500 Subject: [PATCH 2/2] Fix an XMode bug exposed in the pastebin --- basis/xmode/code2html/code2html-tests.factor | 4 ++++ basis/xmode/marker/marker.factor | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/basis/xmode/code2html/code2html-tests.factor b/basis/xmode/code2html/code2html-tests.factor index 241ab7ff75..a35e6a2194 100644 --- a/basis/xmode/code2html/code2html-tests.factor +++ b/basis/xmode/code2html/code2html-tests.factor @@ -18,4 +18,8 @@ kernel io.streams.string xml.writer ; <" int x = "hi"; /* a comment */ "> htmlize-stream write-xml +] unit-test + +[ ": foo ;" ] [ + { ": foo ;" } "factor" htmlize-lines xml>string ] unit-test \ No newline at end of file diff --git a/basis/xmode/marker/marker.factor b/basis/xmode/marker/marker.factor index f584756f33..98b4f91f86 100755 --- a/basis/xmode/marker/marker.factor +++ b/basis/xmode/marker/marker.factor @@ -84,7 +84,7 @@ M: string-matcher text-matches? ] keep string>> length and ; M: regexp text-matches? - [ >string ] dip re-contains? ; + [ >string ] dip first-match to>> ; : rule-start-matches? ( rule -- match-count/f ) dup start>> tuck swap can-match-here? [