Remove need for '.' to terminate rule lines in EBNF

db4
Chris Double 2008-03-19 18:07:25 +13:00
parent 9403d97e22
commit eef6ae7827
1 changed files with 14 additions and 5 deletions

View File

@ -145,10 +145,17 @@ DEFER: 'rhs'
'identifier' [ <ebnf-terminal> ] action ; 'identifier' [ <ebnf-terminal> ] action ;
: 'element' ( -- parser ) : 'element' ( -- parser )
[ #! An element of a rule. It can be a terminal or a
'non-terminal' , #! non-terminal but must not be followed by a "=".
'terminal' , #! The latter indicates that it is the beginning of a
] choice* ; #! new rule.
[
[
'non-terminal' ,
'terminal' ,
] choice* ,
"=" syntax ensure-not ,
] seq* [ first ] action ;
DEFER: 'choice' DEFER: 'choice'
@ -168,6 +175,8 @@ DEFER: 'choice'
"[" [ <ebnf-optional> ] "]" grouped ; "[" [ <ebnf-optional> ] "]" grouped ;
: 'sequence' ( -- parser ) : 'sequence' ( -- parser )
#! A sequence of terminals and non-terminals, including
#! groupings of those.
[ [
'element' sp , 'element' sp ,
'group' sp , 'group' sp ,
@ -205,7 +214,7 @@ DEFER: 'choice'
] seq* [ first2 <ebnf-rule> ] action ; ] seq* [ first2 <ebnf-rule> ] action ;
: 'ebnf' ( -- parser ) : 'ebnf' ( -- parser )
'rule' sp "." syntax list-of [ <ebnf> ] action ; 'rule' sp repeat1 [ <ebnf> ] action ;
: ebnf>quot ( string -- quot ) : ebnf>quot ( string -- quot )
'ebnf' parse [ 'ebnf' parse [