factor/extra/peg/ebnf/ebnf-tests.factor

41 lines
795 B
Factor
Raw Normal View History

2007-11-27 00:13:36 -05:00
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
!
USING: kernel tools.test peg peg.ebnf ;
IN: temporary
{ T{ ebnf-non-terminal f "abc" } } [
"abc" 'non-terminal' parse parse-result-ast
] unit-test
{ T{ ebnf-terminal f "55" } } [
2007-11-27 19:05:53 -05:00
"'55'" 'terminal' parse parse-result-ast
2007-11-27 00:13:36 -05:00
] unit-test
2007-11-27 16:28:28 -05:00
{
T{ ebnf-rule f
2007-11-27 19:05:53 -05:00
"digit"
V{
T{ ebnf-choice f
V{ T{ ebnf-terminal f "1" } T{ ebnf-terminal f "2" } }
}
f
2007-11-27 16:28:28 -05:00
}
}
} [
2007-11-27 19:05:53 -05:00
"digit = '1' | '2'" 'rule' parse parse-result-ast
2007-11-27 16:28:28 -05:00
] unit-test
{
T{ ebnf-rule f
"digit"
2007-11-27 19:05:53 -05:00
V{
T{ ebnf-sequence f
V{ T{ ebnf-terminal f "1" } T{ ebnf-terminal f "2" } }
}
f
2007-11-27 16:28:28 -05:00
}
2007-11-27 19:05:53 -05:00
}
2007-11-27 16:28:28 -05:00
} [
2007-11-27 19:05:53 -05:00
"digit = '1' '2'" 'rule' parse parse-result-ast
2007-11-27 16:28:28 -05:00
] unit-test