Fix precedence between choice/sequence in ebnf
parent
28e9c0e6e0
commit
15b1533f20
|
@ -38,4 +38,17 @@ IN: temporary
|
||||||
}
|
}
|
||||||
} [
|
} [
|
||||||
"digit = '1' '2'" 'rule' parse parse-result-ast
|
"digit = '1' '2'" 'rule' parse parse-result-ast
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{
|
||||||
|
T{ ebnf-choice f
|
||||||
|
V{
|
||||||
|
T{ ebnf-sequence f
|
||||||
|
V{ T{ ebnf-non-terminal f "one" } T{ ebnf-non-terminal f "two" } }
|
||||||
|
}
|
||||||
|
T{ ebnf-non-terminal f "three" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} [
|
||||||
|
"one two | three" 'choice' parse parse-result-ast
|
||||||
] unit-test
|
] unit-test
|
|
@ -97,12 +97,15 @@ DEFER: 'rhs'
|
||||||
|
|
||||||
: 'sequence' ( -- parser )
|
: 'sequence' ( -- parser )
|
||||||
'element' sp
|
'element' sp
|
||||||
"|" token sp ensure-not 2array seq [ first ] action
|
repeat1 [
|
||||||
repeat1 [ <ebnf-sequence> ] action ;
|
dup length 1 = [ first ] [ <ebnf-sequence> ] if
|
||||||
|
] action ;
|
||||||
: 'choice' ( -- parser )
|
|
||||||
'element' sp "|" token sp list-of [ <ebnf-choice> ] action ;
|
|
||||||
|
|
||||||
|
: 'choice' ( -- parser )
|
||||||
|
'sequence' sp "|" token sp list-of [
|
||||||
|
dup length 1 = [ first ] [ <ebnf-choice> ] if
|
||||||
|
] action ;
|
||||||
|
|
||||||
: 'repeat0' ( -- parser )
|
: 'repeat0' ( -- parser )
|
||||||
"{" token sp hide
|
"{" token sp hide
|
||||||
[ 'rhs' sp ] delay
|
[ 'rhs' sp ] delay
|
||||||
|
@ -116,10 +119,8 @@ DEFER: 'rhs'
|
||||||
|
|
||||||
: 'rhs' ( -- parser )
|
: 'rhs' ( -- parser )
|
||||||
'repeat0'
|
'repeat0'
|
||||||
'sequence'
|
|
||||||
'choice'
|
'choice'
|
||||||
'element'
|
2array choice 'action' sp optional 2array seq ;
|
||||||
4array 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