   "=" token sp hide 
   'rhs' 
   3array seq [ first2 <ebnf-rule> ] action ;
+
+: 'ebnf' ( -- parser )
+  'rule' sp ";" token sp hide list-of [ <ebnf> ] action ;
+
+: ebnf>quot ( string -- quot )
+  'ebnf' parse [
+     parse-result-ast ebnf-compile  
+   ] [
+    f
+   ] if* ;
TUPLE: ebnf-choice options ;
TUPLE: ebnf-sequence elements ;
TUPLE: ebnf-rule symbol elements ;

C: <ebnf-non-terminal> ebnf-non-terminal
C: <ebnf-terminal> ebnf-terminal
C: <ebnf-choice> ebnf-choice
C: <ebnf-sequence> ebnf-sequence
C: <ebnf-rule> ebnf-rule

GENERIC: ebnf-compile ( ast -- quot )


  [
    dup ebnf-rule-symbol , \ in , \ get , \ create , 
    ebnf-rule-elements ebnf-compile , \ define-compound , 
  ] [ ] make ;

M: ebnf ebnf-compile ( ast -- quot )
  [
    ebnf-rules [
      ebnf-compile %
    ] each 
  ] [ ] make ;

DEFER: 'rhs'
