Change ordering of [[ ... ]]
parent
39c228db6d
commit
c1f69f01be
|
@ -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 compiler.units ;
|
USING: kernel parser words tools.test peg peg.ebnf compiler.units ;
|
||||||
IN: peg.ebnf.tests
|
IN: peg.ebnf.tests
|
||||||
|
|
||||||
{ T{ ebnf-non-terminal f "abc" } } [
|
{ T{ ebnf-non-terminal f "abc" } } [
|
||||||
|
@ -109,37 +109,37 @@ IN: peg.ebnf.tests
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ V{ "a" "b" } } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ V{ 1 "b" } } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ V{ 1 2 } } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ CHAR: A } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ CHAR: Z } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ f } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ CHAR: 0 } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ f } [
|
{ 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
|
] unit-test
|
||||||
|
|
||||||
{ f } [
|
{ 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
|
] unit-test
|
|
@ -172,7 +172,7 @@ DEFER: 'rhs'
|
||||||
: 'range-parser' ( -- parser )
|
: 'range-parser' ( -- parser )
|
||||||
#! Match the syntax for declaring character ranges
|
#! Match the syntax for declaring character ranges
|
||||||
[
|
[
|
||||||
"[" syntax ,
|
[ "[" syntax , "[" token ensure-not , ] seq* hide ,
|
||||||
[ CHAR: ] = not ] satisfy repeat1 ,
|
[ CHAR: ] = not ] satisfy repeat1 ,
|
||||||
"]" syntax ,
|
"]" syntax ,
|
||||||
] seq* [ first >string <ebnf-range> ] action ;
|
] 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 ,
|
||||||
"?" token sp ensure-not ,
|
"?" token sp ensure-not ,
|
||||||
"[[" token sp ensure-not ,
|
|
||||||
] seq* hide grouped ;
|
] seq* hide grouped ;
|
||||||
|
|
||||||
: 'repeat0' ( -- parser )
|
: 'repeat0' ( -- parser )
|
||||||
|
@ -226,13 +225,6 @@ DEFER: 'choice'
|
||||||
[ drop t ] satisfy ,
|
[ drop t ] satisfy ,
|
||||||
] seq* [ first ] action repeat0 [ >string ] action ;
|
] 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 )
|
: 'ensure-not' ( -- parser )
|
||||||
#! Parses the '!' syntax to ensure that
|
#! Parses the '!' syntax to ensure that
|
||||||
#! something that matches the following elements do
|
#! something that matches the following elements do
|
||||||
|
@ -242,7 +234,7 @@ DEFER: 'choice'
|
||||||
'group' sp ,
|
'group' sp ,
|
||||||
] seq* [ first <ebnf-ensure-not> ] action ;
|
] seq* [ first <ebnf-ensure-not> ] action ;
|
||||||
|
|
||||||
: 'sequence' ( -- parser )
|
: ('sequence') ( -- parser )
|
||||||
#! A sequence of terminals and non-terminals, including
|
#! A sequence of terminals and non-terminals, including
|
||||||
#! groupings of those.
|
#! groupings of those.
|
||||||
[
|
[
|
||||||
|
@ -252,11 +244,21 @@ DEFER: 'choice'
|
||||||
'repeat0' sp ,
|
'repeat0' sp ,
|
||||||
'repeat1' sp ,
|
'repeat1' sp ,
|
||||||
'optional' 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 [
|
] choice* repeat1 [
|
||||||
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
||||||
] action ;
|
] action ;
|
||||||
|
|
||||||
: 'choice' ( -- parser )
|
: 'choice' ( -- parser )
|
||||||
'sequence' sp "|" token sp list-of [
|
'sequence' sp "|" token sp list-of [
|
||||||
dup length 1 = [ first ] [ <ebnf-choice> ] if
|
dup length 1 = [ first ] [ <ebnf-choice> ] if
|
||||||
|
|
|
@ -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.expr multiline sequences ;
|
USING: kernel tools.test peg peg.expr multiline sequences ;
|
||||||
IN: temporary
|
IN: temporary
|
||||||
|
|
||||||
{ 5 } [
|
{ 5 } [
|
||||||
|
|
|
@ -26,4 +26,5 @@ expr = sum
|
||||||
EBNF>
|
EBNF>
|
||||||
|
|
||||||
: eval-expr ( string -- number )
|
: eval-expr ( string -- number )
|
||||||
expr parse parse-result-ast ;
|
expr parse parse-result-ast ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue