Add grouping operators for ebnf

release
Chris Double 2007-11-28 15:26:25 +13:00
parent 15b1533f20
commit 0ef96c87d9
2 changed files with 22 additions and 1 deletions

View File

@ -51,4 +51,17 @@ IN: temporary
}
} [
"one two | three" 'choice' parse parse-result-ast
] unit-test
{
T{ ebnf-sequence f
V{
T{ ebnf-non-terminal f "one" }
T{ ebnf-choice f
V{ T{ ebnf-non-terminal f "two" } T{ ebnf-non-terminal f "three" } }
}
}
}
} [
"one (two | three)" 'choice' parse parse-result-ast
] unit-test

View File

@ -95,8 +95,16 @@ DEFER: 'rhs'
: 'element' ( -- parser )
'non-terminal' 'terminal' 2array choice ;
DEFER: 'choice'
: 'group' ( -- parser )
"(" token sp hide
[ 'choice' sp ] delay
")" token sp hide
3array seq [ first ] action ;
: 'sequence' ( -- parser )
'element' sp
'element' sp 'group' sp 2array choice
repeat1 [
dup length 1 = [ first ] [ <ebnf-sequence> ] if
] action ;