   "=" 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* ;

M: ebnf-non-terminal ebnf-compile ( ast -- quot )
  [
    ebnf-non-terminal-symbol in get lookup ,
  ] [ ] make ;

M: ebnf-choice ebnf-compile ( ast -- quot )

TUPLE: ebnf-choice options ;
TUPLE: ebnf-sequence elements ;
TUPLE: ebnf-rule symbol elements ;
TUPLE: ebnf rules ;

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
C: <ebnf> ebnf

GENERIC: ebnf-compile ( ast -- quot )

