Compile ebnf->factor

release
Chris Double 2007-11-28 11:07:17 +13:00
parent ed359b6623
commit 38806885e6
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel arrays strings math.parser sequences namespaces peg ;
USING: kernel parser words arrays strings math.parser sequences namespaces peg ;
IN: peg.ebnf
TUPLE: ebnf-non-terminal symbol ;
@ -22,6 +22,11 @@ M: ebnf-terminal ebnf-compile ( ast -- quot )
ebnf-terminal-symbol , \ token ,
] [ ] make ;
M: ebnf-non-terminal ebnf-compile ( ast -- quot )
[
ebnf-non-terminal-symbol in get lookup ,
] [ ] make ;
M: ebnf-choice ebnf-compile ( ast -- quot )
[
[
@ -42,6 +47,12 @@ M: ebnf-sequence ebnf-compile ( ast -- quot )
[ call ] , \ map , \ seq ,
] [ ] make ;
M: ebnf-rule ebnf-compile ( ast -- quot )
[
dup ebnf-rule-symbol , \ in , \ get , \ create ,
ebnf-rule-elements ebnf-compile , \ define-compound ,
] [ ] make ;
DEFER: 'rhs'
: 'non-terminal' ( -- parser )