Some ebnf tweaks and tests to do with variables

db4
Chris Double 2008-03-31 14:59:22 +13:00
parent ee2194d1dc
commit 729ac1d6dc
2 changed files with 9 additions and 2 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007 Chris Double. ! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
! !
USING: kernel tools.test peg peg.ebnf words ; USING: kernel tools.test peg peg.ebnf words math math.parser ;
IN: peg.ebnf.tests IN: peg.ebnf.tests
{ T{ ebnf-non-terminal f "abc" } } [ { T{ ebnf-non-terminal f "abc" } } [
@ -160,6 +160,13 @@ IN: peg.ebnf.tests
"1-1" [EBNF foo='1' '+' '1' => [[ drop "foo" ]] | '1' '-' '1' => [[ drop "bar" ]] EBNF] call parse-result-ast "1-1" [EBNF foo='1' '+' '1' => [[ drop "foo" ]] | '1' '-' '1' => [[ drop "bar" ]] EBNF] call parse-result-ast
] unit-test ] unit-test
{ 6 } [
"4+2" [EBNF num=[0-9] => [[ digit> ]] foo=num:x '+' num:y => [[ drop x y + ]] EBNF] call parse-result-ast
] unit-test
{ 6 } [
"4+2" [EBNF foo=[0-9]:x '+' [0-9]:y => [[ drop x digit> y digit> + ]] EBNF] call parse-result-ast
] unit-test
{ V{ V{ 49 } "+" V{ 49 } } } [ { V{ V{ 49 } "+" V{ 49 } } } [
#! Test direct left recursion. #! Test direct left recursion.

View File

@ -283,7 +283,7 @@ M: ebnf-optional (transform) ( ast -- parser )
drop drop
] [ ] [
[ [
"[let* | " % "USING: locals namespaces ; [let* | " %
[ dup % " [ \"" % % "\" get ] " % ] each [ dup % " [ \"" % % "\" get ] " % ] each
" | " % " | " %
% %