compiled pegs infer
parent
ce8ab6356b
commit
5f37b4fc72
|
@ -65,7 +65,7 @@ C: <head> peg-head
|
||||||
] [
|
] [
|
||||||
pos set
|
pos set
|
||||||
fail
|
fail
|
||||||
] if* ;
|
] if* ; inline
|
||||||
|
|
||||||
: memo ( pos rule -- memo-entry )
|
: memo ( pos rule -- memo-entry )
|
||||||
#! Return the result from the memo cache.
|
#! Return the result from the memo cache.
|
||||||
|
@ -85,14 +85,14 @@ C: <head> peg-head
|
||||||
m (>>ans)
|
m (>>ans)
|
||||||
pos get m (>>pos)
|
pos get m (>>pos)
|
||||||
r p m h (grow-lr)
|
r p m h (grow-lr)
|
||||||
] if ;
|
] if ; inline
|
||||||
|
|
||||||
:: grow-lr ( r p m h -- ast )
|
:: grow-lr ( r p m h -- ast )
|
||||||
h p heads get set-at
|
h p heads get set-at
|
||||||
r p m h (grow-lr)
|
r p m h (grow-lr)
|
||||||
p heads get delete-at
|
p heads get delete-at
|
||||||
m pos>> pos set m ans>>
|
m pos>> pos set m ans>>
|
||||||
;
|
; inline
|
||||||
|
|
||||||
:: (setup-lr) ( r l s -- )
|
:: (setup-lr) ( r l s -- )
|
||||||
s head>> l head>> eq? [
|
s head>> l head>> eq? [
|
||||||
|
@ -121,7 +121,7 @@ C: <head> peg-head
|
||||||
] [
|
] [
|
||||||
m ans>> seed>>
|
m ans>> seed>>
|
||||||
] if
|
] if
|
||||||
] ;
|
] ; inline
|
||||||
|
|
||||||
:: recall ( r p -- memo-entry )
|
:: recall ( r p -- memo-entry )
|
||||||
[let* |
|
[let* |
|
||||||
|
@ -145,7 +145,7 @@ C: <head> peg-head
|
||||||
] [
|
] [
|
||||||
m
|
m
|
||||||
] if
|
] if
|
||||||
] ;
|
] ; inline
|
||||||
|
|
||||||
:: apply-non-memo-rule ( r p -- ast )
|
:: apply-non-memo-rule ( r p -- ast )
|
||||||
[let* |
|
[let* |
|
||||||
|
@ -162,7 +162,7 @@ C: <head> peg-head
|
||||||
ans m (>>ans)
|
ans m (>>ans)
|
||||||
ans
|
ans
|
||||||
] if
|
] if
|
||||||
] ;
|
] ; inline
|
||||||
|
|
||||||
:: apply-memo-rule ( r m -- ast )
|
:: apply-memo-rule ( r m -- ast )
|
||||||
m pos>> pos set
|
m pos>> pos set
|
||||||
|
@ -182,7 +182,7 @@ C: <head> peg-head
|
||||||
] [
|
] [
|
||||||
r p apply-non-memo-rule
|
r p apply-non-memo-rule
|
||||||
] if
|
] if
|
||||||
] ;
|
] ; inline
|
||||||
|
|
||||||
: with-packrat ( input quot -- result )
|
: with-packrat ( input quot -- result )
|
||||||
#! Run the quotation with a packrat cache active.
|
#! Run the quotation with a packrat cache active.
|
||||||
|
|
Loading…
Reference in New Issue