From fea65df1dfeb1f56bf40fb232aae99c430b2d731 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Wed, 18 Jun 2008 23:07:26 +1200 Subject: [PATCH] Fix ebnf foreign call breakage and add tests --- extra/peg/ebnf/ebnf-tests.factor | 36 +++++++++++++++++++++++++++++++- extra/peg/ebnf/ebnf.factor | 6 +++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/extra/peg/ebnf/ebnf-tests.factor b/extra/peg/ebnf/ebnf-tests.factor index 04cc01c9d0..73db626685 100644 --- a/extra/peg/ebnf/ebnf-tests.factor +++ b/extra/peg/ebnf/ebnf-tests.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. ! USING: kernel tools.test peg peg.ebnf words math math.parser - sequences accessors ; + sequences accessors peg.parsers ; IN: peg.ebnf.tests { T{ ebnf-non-terminal f "abc" } } [ @@ -397,4 +397,38 @@ main = Primary { t } [ "number=digit+:n 'a'" 'ebnf' parse remaining>> length zero? +] unit-test + +<< +EBNF: parser1 +foo='a' +;EBNF +>> + +EBNF: parser2 +foo= 'b' +;EBNF + +EBNF: parser3 +foo= 'c' +;EBNF + +EBNF: parser4 +foo= 'd' +;EBNF + +{ "a" } [ + "a" parser1 ast>> +] unit-test + +{ V{ "a" "b" } } [ + "ab" parser2 ast>> +] unit-test + +{ V{ "a" "c" } } [ + "ac" parser3 ast>> +] unit-test + +{ V{ CHAR: a "d" } } [ + "ad" parser4 ast>> ] unit-test \ No newline at end of file diff --git a/extra/peg/ebnf/ebnf.factor b/extra/peg/ebnf/ebnf.factor index 36b3742b64..2ee0958051 100644 --- a/extra/peg/ebnf/ebnf.factor +++ b/extra/peg/ebnf/ebnf.factor @@ -415,11 +415,11 @@ M: ebnf-terminal (transform) ( ast -- parser ) M: ebnf-foreign (transform) ( ast -- parser ) dup word>> search [ "Foreign word " swap word>> append " not found" append throw ] unless* - swap rule>> dup [ - swap rule + swap rule>> [ main ] unless* dupd swap rule [ + nip ] [ execute - ] if ; + ] if* ; : parser-not-found ( name -- * ) [