Refactor action peg parser

db4
Chris Double 2008-04-05 18:33:50 +13:00
parent 247bf2137b
commit d93c7958fd
1 changed files with 8 additions and 9 deletions

View File

@ -423,17 +423,16 @@ TUPLE: action-parser p1 quot ;
MATCH-VARS: ?action ;
: action-pattern ( -- quot )
[
?quot dup [
dup ast>> ?action call
>>ast
] when
] ;
: check-action ( result quot -- result )
over [
over ast>> swap call >>ast
] [
drop
] if ; inline
M: action-parser (compile) ( parser -- quot )
[ p1>> compiled-parser ] [ quot>> ] bi
2array { ?quot ?action } action-pattern match-replace ;
[ p1>> compiled-parser 1quotation ] [ quot>> ] bi '[
@ , check-action ] ;
: left-trim-slice ( string -- string )
#! Return a new string without any leading whitespace