fix grouping of repeat0 in ebnf
parent
3372ad8f68
commit
d68a78c4a6
|
@ -64,4 +64,24 @@ IN: temporary
|
||||||
}
|
}
|
||||||
} [
|
} [
|
||||||
"one (two | three)" 'choice' parse parse-result-ast
|
"one (two | three)" 'choice' parse parse-result-ast
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{
|
||||||
|
T{ ebnf-sequence f
|
||||||
|
V{
|
||||||
|
T{ ebnf-non-terminal f "one" }
|
||||||
|
T{ ebnf-repeat0 f
|
||||||
|
T{ ebnf-sequence f
|
||||||
|
V{
|
||||||
|
T{ ebnf-choice f
|
||||||
|
V{ T{ ebnf-non-terminal f "two" } T{ ebnf-non-terminal f "three" } }
|
||||||
|
}
|
||||||
|
T{ ebnf-non-terminal f "four" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} [
|
||||||
|
"one {(two | three) four}" 'choice' parse parse-result-ast
|
||||||
] unit-test
|
] unit-test
|
|
@ -103,8 +103,14 @@ DEFER: 'choice'
|
||||||
")" token sp hide
|
")" token sp hide
|
||||||
3array seq [ first ] action ;
|
3array seq [ first ] action ;
|
||||||
|
|
||||||
|
: 'repeat0' ( -- parser )
|
||||||
|
"{" token sp hide
|
||||||
|
[ 'choice' sp ] delay
|
||||||
|
"}" token sp hide
|
||||||
|
3array seq [ first <ebnf-repeat0> ] action ;
|
||||||
|
|
||||||
: 'sequence' ( -- parser )
|
: 'sequence' ( -- parser )
|
||||||
'element' sp 'group' sp 2array choice
|
'element' sp 'group' sp 'repeat0' sp 3array choice
|
||||||
repeat1 [
|
repeat1 [
|
||||||
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
||||||
] action ;
|
] action ;
|
||||||
|
@ -114,21 +120,13 @@ DEFER: 'choice'
|
||||||
dup length 1 = [ first ] [ <ebnf-choice> ] if
|
dup length 1 = [ first ] [ <ebnf-choice> ] if
|
||||||
] action ;
|
] action ;
|
||||||
|
|
||||||
: 'repeat0' ( -- parser )
|
|
||||||
"{" token sp hide
|
|
||||||
[ 'rhs' sp ] delay
|
|
||||||
"}" token sp hide
|
|
||||||
3array seq [ first <ebnf-repeat0> ] action ;
|
|
||||||
|
|
||||||
: 'action' ( -- parser )
|
: 'action' ( -- parser )
|
||||||
"=>" token hide
|
"=>" token hide
|
||||||
[ blank? ] satisfy ensure-not [ drop t ] satisfy 2array seq [ first ] action repeat1 [ >string ] action sp
|
[ blank? ] satisfy ensure-not [ drop t ] satisfy 2array seq [ first ] action repeat1 [ >string ] action sp
|
||||||
2array seq [ first <ebnf-action> ] action ;
|
2array seq [ first <ebnf-action> ] action ;
|
||||||
|
|
||||||
: 'rhs' ( -- parser )
|
: 'rhs' ( -- parser )
|
||||||
'repeat0'
|
'choice' 'action' sp optional 2array seq ;
|
||||||
'choice'
|
|
||||||
2array choice 'action' sp optional 2array seq ;
|
|
||||||
|
|
||||||
: 'rule' ( -- parser )
|
: 'rule' ( -- parser )
|
||||||
'non-terminal' [ ebnf-non-terminal-symbol ] action
|
'non-terminal' [ ebnf-non-terminal-symbol ] action
|
||||||
|
|
Loading…
Reference in New Issue