Change ordering of [[ ... ]]

db4
Chris Double 2008-03-20 14:57:12 +13:00
parent 39c228db6d
commit c1f69f01be
4 changed files with 28 additions and 25 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
!
USING: kernel tools.test peg peg.ebnf compiler.units ;
USING: kernel parser words tools.test peg peg.ebnf compiler.units ;
IN: peg.ebnf.tests
{ T{ ebnf-non-terminal f "abc" } } [
@ -109,37 +109,37 @@ IN: peg.ebnf.tests
] unit-test
{ V{ "a" "b" } } [
"foo='a' 'b'" ebnf>quot with-compilation-unit "ab" foo parse parse-result-ast
"foo='a' 'b'" ebnf>quot with-compilation-unit "ab" "foo" search execute parse parse-result-ast
] unit-test
{ V{ 1 "b" } } [
"foo=('a')[[ drop 1 ]] 'b'" ebnf>quot with-compilation-unit "ab" foo parse parse-result-ast
"foo=('a')[[ drop 1 ]] 'b'" ebnf>quot with-compilation-unit "ab" "foo" search execute parse parse-result-ast
] unit-test
{ V{ 1 2 } } [
"foo=('a') [[ drop 1 ]] ('b') [[ drop 2 ]]" ebnf>quot with-compilation-unit "ab" foo parse parse-result-ast
"foo=('a') [[ drop 1 ]] ('b') [[ drop 2 ]]" ebnf>quot with-compilation-unit "ab" "foo" search execute parse parse-result-ast
] unit-test
{ CHAR: A } [
"foo=[A-Z]" ebnf>quot with-compilation-unit "A" foo parse parse-result-ast
"foo=[A-Z]" ebnf>quot with-compilation-unit "A" "foo" search execute parse parse-result-ast
] unit-test
{ CHAR: Z } [
"foo=[A-Z]" ebnf>quot with-compilation-unit "Z" foo parse parse-result-ast
"foo=[A-Z]" ebnf>quot with-compilation-unit "Z" "foo" search execute parse parse-result-ast
] unit-test
{ f } [
"foo=[A-Z]" ebnf>quot with-compilation-unit "0" foo parse
"foo=[A-Z]" ebnf>quot with-compilation-unit "0" "foo" search execute parse
] unit-test
{ CHAR: 0 } [
"foo=[^A-Z]" ebnf>quot with-compilation-unit "0" foo parse parse-result-ast
"foo=[^A-Z]" ebnf>quot with-compilation-unit "0" "foo" search execute parse parse-result-ast
] unit-test
{ f } [
"foo=[^A-Z]" ebnf>quot with-compilation-unit "A" foo parse
"foo=[^A-Z]" ebnf>quot with-compilation-unit "A" "foo" search execute parse
] unit-test
{ f } [
"foo=[^A-Z]" ebnf>quot with-compilation-unit "Z" foo parse
"foo=[^A-Z]" ebnf>quot with-compilation-unit "Z" "foo" search execute parse
] unit-test

View File

@ -172,7 +172,7 @@ DEFER: 'rhs'
: 'range-parser' ( -- parser )
#! Match the syntax for declaring character ranges
[
"[" syntax ,
[ "[" syntax , "[" token ensure-not , ] seq* hide ,
[ CHAR: ] = not ] satisfy repeat1 ,
"]" syntax ,
] seq* [ first >string <ebnf-range> ] action ;
@ -208,7 +208,6 @@ DEFER: 'choice'
"*" token sp ensure-not ,
"+" token sp ensure-not ,
"?" token sp ensure-not ,
"[[" token sp ensure-not ,
] seq* hide grouped ;
: 'repeat0' ( -- parser )
@ -226,13 +225,6 @@ DEFER: 'choice'
[ drop t ] satisfy ,
] seq* [ first ] action repeat0 [ >string ] action ;
: 'action' ( -- parser )
[
"(" [ 'choice' sp ] delay ")" syntax-pack ,
"[[" 'factor-code' "]]" syntax-pack ,
] seq* [ first2 <ebnf-action> ] action ;
: 'ensure-not' ( -- parser )
#! Parses the '!' syntax to ensure that
#! something that matches the following elements do
@ -242,7 +234,7 @@ DEFER: 'choice'
'group' sp ,
] seq* [ first <ebnf-ensure-not> ] action ;
: 'sequence' ( -- parser )
: ('sequence') ( -- parser )
#! A sequence of terminals and non-terminals, including
#! groupings of those.
[
@ -252,7 +244,17 @@ DEFER: 'choice'
'repeat0' sp ,
'repeat1' sp ,
'optional' sp ,
'action' sp ,
] choice* ;
: 'sequence' ( -- parser )
#! A sequence of terminals and non-terminals, including
#! groupings of those.
[
[
('sequence') ,
"[[" 'factor-code' "]]" syntax-pack ,
] seq* [ first2 <ebnf-action> ] action ,
('sequence') ,
] choice* repeat1 [
dup length 1 = [ first ] [ <ebnf-sequence> ] if
] action ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
!
USING: kernel tools.test peg.expr multiline sequences ;
USING: kernel tools.test peg peg.expr multiline sequences ;
IN: temporary
{ 5 } [

View File

@ -27,3 +27,4 @@ EBNF>
: eval-expr ( string -- number )
expr parse parse-result-ast ;