Use stack effect literals instead of <effect> in PEG, and don't use smart combinators

db4
Slava Pestov 2008-12-05 23:53:16 -06:00
parent 6ee523f48f
commit 3673a3e7c7
1 changed files with 6 additions and 6 deletions

View File

@ -4,8 +4,7 @@ USING: kernel sequences strings fry namespaces make math assocs
debugger io vectors arrays math.parser math.order debugger io vectors arrays math.parser math.order
vectors combinators classes sets unicode.categories vectors combinators classes sets unicode.categories
compiler.units parser words quotations effects memoize accessors compiler.units parser words quotations effects memoize accessors
locals effects splitting combinators.short-circuit locals effects splitting combinators.short-circuit generalizations ;
combinators.short-circuit.smart generalizations ;
IN: peg IN: peg
USE: prettyprint USE: prettyprint
@ -278,7 +277,8 @@ GENERIC: (compile) ( peg -- quot )
: parser-body ( parser -- quot ) : parser-body ( parser -- quot )
#! Return the body of the word that is the compiled version #! Return the body of the word that is the compiled version
#! of the parser. #! of the parser.
gensym 2dup swap peg>> (compile) 0 1 <effect> define-declared swap dupd id>> "peg-id" set-word-prop gensym 2dup swap peg>> (compile) (( -- result )) define-declared
swap dupd id>> "peg-id" set-word-prop
[ execute-parser ] curry ; [ execute-parser ] curry ;
: preset-parser-word ( parser -- parser word ) : preset-parser-word ( parser -- parser word )
@ -306,7 +306,7 @@ SYMBOL: delayed
#! Work through all delayed parsers and recompile their #! Work through all delayed parsers and recompile their
#! words to have the correct bodies. #! words to have the correct bodies.
delayed get [ delayed get [
call compile-parser 1quotation 0 1 <effect> define-declared call compile-parser 1quotation (( -- result )) define-declared
] assoc-each ; ] assoc-each ;
: compile ( parser -- word ) : compile ( parser -- word )
@ -421,7 +421,7 @@ M: seq-parser (compile) ( peg -- quot )
[ [
parsers>> unclip compile-parser 1quotation [ parse-seq-element ] curry , parsers>> unclip compile-parser 1quotation [ parse-seq-element ] curry ,
[ compile-parser 1quotation [ merge-errors ] compose [ parse-seq-element ] curry , ] each [ compile-parser 1quotation [ merge-errors ] compose [ parse-seq-element ] curry , ] each
] { } make , \ && , ] { } make , \ 1&& ,
] [ ] make ; ] [ ] make ;
TUPLE: choice-parser parsers ; TUPLE: choice-parser parsers ;
@ -431,7 +431,7 @@ M: choice-parser (compile) ( peg -- quot )
[ [
parsers>> [ compile-parser ] map parsers>> [ compile-parser ] map
unclip 1quotation , [ 1quotation [ merge-errors ] compose , ] each unclip 1quotation , [ 1quotation [ merge-errors ] compose , ] each
] { } make , \ || , ] { } make , \ 0|| ,
] [ ] make ; ] [ ] make ;
TUPLE: repeat0-parser p1 ; TUPLE: repeat0-parser p1 ;