 : ebnf>quot ( string -- hashtable quot )
   'ebnf' parse check-parse-result 
   parse-result-ast transform dup dup parser [ main swap at compile ] with-variable
-  [ compiled-parse ] curry ;
+  [ compiled-parse ] curry [ with-scope ] curry ;
 
 : [EBNF "EBNF]" parse-multiline-string ebnf>quot nip parsed ; parsing
 

M: ebnf-optional (transform) ( ast -- parser )
  transform-group optional ;

M: ebnf-action (transform) ( ast -- parser )
  [ parser>> (transform) ] keep
  code>> string-lines [ parse-lines ] with-compilation-unit action ;

M: ebnf-var (transform) ( ast -- parser )
  parser>> (transform) ;

M: ebnf-terminal (transform) ( ast -- parser )
  symbol>> token sp ;

USING: kernel compiler.units parser words arrays strings math.parser sequences 
       quotations vectors namespaces math assocs continuations peg
       peg.parsers unicode.categories multiline combinators.lib 
       splitting accessors effects sequences.deep ;
IN: peg.ebnf

TUPLE: ebnf-non-terminal symbol ;
