Fix ebnf foreign call breakage and add tests
parent
a5719e3397
commit
fea65df1df
|
@ -2,7 +2,7 @@
|
||||||
! 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 math math.parser
|
USING: kernel tools.test peg peg.ebnf words math math.parser
|
||||||
sequences accessors ;
|
sequences accessors peg.parsers ;
|
||||||
IN: peg.ebnf.tests
|
IN: peg.ebnf.tests
|
||||||
|
|
||||||
{ T{ ebnf-non-terminal f "abc" } } [
|
{ T{ ebnf-non-terminal f "abc" } } [
|
||||||
|
@ -397,4 +397,38 @@ main = Primary
|
||||||
|
|
||||||
{ t } [
|
{ t } [
|
||||||
"number=digit+:n 'a'" 'ebnf' parse remaining>> length zero?
|
"number=digit+:n 'a'" 'ebnf' parse remaining>> length zero?
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
<<
|
||||||
|
EBNF: parser1
|
||||||
|
foo='a'
|
||||||
|
;EBNF
|
||||||
|
>>
|
||||||
|
|
||||||
|
EBNF: parser2
|
||||||
|
foo=<foreign parser1 foo> 'b'
|
||||||
|
;EBNF
|
||||||
|
|
||||||
|
EBNF: parser3
|
||||||
|
foo=<foreign parser1> 'c'
|
||||||
|
;EBNF
|
||||||
|
|
||||||
|
EBNF: parser4
|
||||||
|
foo=<foreign any-char> '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
|
] unit-test
|
|
@ -415,11 +415,11 @@ M: ebnf-terminal (transform) ( ast -- parser )
|
||||||
M: ebnf-foreign (transform) ( ast -- parser )
|
M: ebnf-foreign (transform) ( ast -- parser )
|
||||||
dup word>> search
|
dup word>> search
|
||||||
[ "Foreign word " swap word>> append " not found" append throw ] unless*
|
[ "Foreign word " swap word>> append " not found" append throw ] unless*
|
||||||
swap rule>> dup [
|
swap rule>> [ main ] unless* dupd swap rule [
|
||||||
swap rule
|
nip
|
||||||
] [
|
] [
|
||||||
execute
|
execute
|
||||||
] if ;
|
] if* ;
|
||||||
|
|
||||||
: parser-not-found ( name -- * )
|
: parser-not-found ( name -- * )
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue