From 38806885e639e6ca01b3c51bf8c4b0e4a7dc7109 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Wed, 28 Nov 2007 11:07:17 +1300 Subject: [PATCH] Compile ebnf->factor --- extra/peg/ebnf/ebnf.factor | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/extra/peg/ebnf/ebnf.factor b/extra/peg/ebnf/ebnf.factor index 61eb7382c4..bb0e85c45a 100644 --- a/extra/peg/ebnf/ebnf.factor +++ b/extra/peg/ebnf/ebnf.factor @@ -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 )