Add grouping operators for ebnf
parent
15b1533f20
commit
0ef96c87d9
|
@ -52,3 +52,16 @@ IN: temporary
|
||||||
} [
|
} [
|
||||||
"one two | three" 'choice' parse parse-result-ast
|
"one two | three" 'choice' parse parse-result-ast
|
||||||
] unit-test
|
] 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
|
|
@ -95,8 +95,16 @@ DEFER: 'rhs'
|
||||||
: 'element' ( -- parser )
|
: 'element' ( -- parser )
|
||||||
'non-terminal' 'terminal' 2array choice ;
|
'non-terminal' 'terminal' 2array choice ;
|
||||||
|
|
||||||
|
DEFER: 'choice'
|
||||||
|
|
||||||
|
: 'group' ( -- parser )
|
||||||
|
"(" token sp hide
|
||||||
|
[ 'choice' sp ] delay
|
||||||
|
")" token sp hide
|
||||||
|
3array seq [ first ] action ;
|
||||||
|
|
||||||
: 'sequence' ( -- parser )
|
: 'sequence' ( -- parser )
|
||||||
'element' sp
|
'element' sp 'group' sp 2array choice
|
||||||
repeat1 [
|
repeat1 [
|
||||||
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
||||||
] action ;
|
] action ;
|
||||||
|
|
Loading…
Reference in New Issue