From 0db0d9cd444eaa920088f172844b4fdbc0f690b7 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Sat, 29 Mar 2008 16:24:13 +1300 Subject: [PATCH] Move towards having ebnf infer --- extra/peg/ebnf/ebnf.factor | 2 +- extra/peg/peg.factor | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/extra/peg/ebnf/ebnf.factor b/extra/peg/ebnf/ebnf.factor index 3efe2d6979..76e851efd3 100644 --- a/extra/peg/ebnf/ebnf.factor +++ b/extra/peg/ebnf/ebnf.factor @@ -282,7 +282,7 @@ M: ebnf-non-terminal (transform) ( ast -- parser ) : ebnf>quot ( string -- hashtable quot ) 'ebnf' parse check-parse-result - parse-result-ast transform dup main swap at compile [ parse ] curry ; + parse-result-ast transform dup main swap at compile [ compiled-parse ] curry ; : [EBNF "EBNF]" parse-multiline-string ebnf>quot nip parsed ; parsing diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 8f7522bda9..be4bba25fc 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -192,7 +192,7 @@ C: peg-head f lrstack set H{ } clone heads set H{ } clone packrat set - ] H{ } make-assoc swap bind ; + ] H{ } make-assoc swap bind ; inline : compiled-parsers ( -- cache ) @@ -236,9 +236,11 @@ GENERIC: (compile) ( parser -- quot ) : compile ( parser -- word ) [ compiled-parser ] with-compilation-unit ; +: compiled-parse ( state word -- result ) + swap [ execute ] with-packrat ; inline + : parse ( state parser -- result ) - dup word? [ compile ] unless - [ execute ] curry with-packrat ; + dup word? [ compile ] unless compiled-parse ;