diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-09-12 06:48:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-09-12 06:48:23 -0700 |
commit | 75fde7a377a5d09cf7ace633057359a0f5ec2c68 (patch) | |
tree | 2baf52a22da7760200bb0cef5a051fa847ee0a35 /share | |
parent | b2ef30979b89bc0e8fa5f90b8bfc7d09ed3e16c2 (diff) | |
download | txr-75fde7a377a5d09cf7ace633057359a0f5ec2c68.tar.gz txr-75fde7a377a5d09cf7ace633057359a0f5ec2c68.tar.bz2 txr-75fde7a377a5d09cf7ace633057359a0f5ec2c68.zip |
awk macro: revise how implicit block works, and name.
* share/txr/stdlib/awk.tl (sys:awk-expander): Check
that :name designates a symbol, and that it isn't nil.
(awk): Move the implicit block to the outermost scope
so it encloses all of the clauses. Default to the
name awk for the block, rather than nil.
* txr.1: Document that the implicit awk block is
called awk by default, and that nil is not allowed
as a block name.
Diffstat (limited to 'share')
-rw-r--r-- | share/txr/stdlib/awk.tl | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index 77d47703..45a655bd 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -131,6 +131,12 @@ (when (or (atom actions) (cdr actions)) (throwf 'eval-error "awk: bad :name syntax")) + (unless (car actions) + (throwf 'eval-error + "awk: null :name not permitted")) + (unless (symbolp (car actions)) + (throwf 'eval-error + "awk: :name must be a symbol")) (set awc.name (car actions))) (:let (push actions awc.lets)) (:begin (push actions awc.begin-actions)) @@ -198,33 +204,33 @@ ^(sys:awk-let ,awc ,aws-sym ,*p-actions-xform-unex) e))) - ^(let* (,*awc.lets ,awk-retval) - (sys:awk-let ,awc ,aws-sym - (let* ((,aws-sym (new sys:awk-state - ,*(if awc.inputs ^(inputs (list ,*awc.inputs))) - ,*(if awc.output ^(output ,awc.output)) - rng-n (macro-time (qref ,awc nranges)))) - (*stdout* (qref ,aws-sym output)) - ,*(if awc.begin-file-actions - ^((,awk-begf-fun (lambda (,aws-sym) - ,*awc.begin-file-actions)))) - ,*(if awc.end-file-actions - ^((,awk-endf-fun (lambda (,aws-sym) - ,*awc.end-file-actions)))) - (,awk-fun (lambda (,aws-sym) - ,(if awc.rng-exprs - ^(let* ,(nreverse - (zip awc.rng-expr-temps - awc.rng-exprs)) - ,p-actions-xform) - p-actions-xform)))) - ,*awc.begin-actions - (block ,awc.name - (unwind-protect - (qref ,aws-sym (loop ,awk-fun - ,(if awc.begin-file-actions - awk-begf-fun) - ,(if awc.end-file-actions - awk-endf-fun))) - (set ,awk-retval (progn ,*awc.end-actions))) - ,awk-retval)))))))) + ^(block ,(or awc.name 'awk) + (let* (,*awc.lets ,awk-retval) + (sys:awk-let ,awc ,aws-sym + (let* ((,aws-sym (new sys:awk-state + ,*(if awc.inputs ^(inputs (list ,*awc.inputs))) + ,*(if awc.output ^(output ,awc.output)) + rng-n (macro-time (qref ,awc nranges)))) + (*stdout* (qref ,aws-sym output)) + ,*(if awc.begin-file-actions + ^((,awk-begf-fun (lambda (,aws-sym) + ,*awc.begin-file-actions)))) + ,*(if awc.end-file-actions + ^((,awk-endf-fun (lambda (,aws-sym) + ,*awc.end-file-actions)))) + (,awk-fun (lambda (,aws-sym) + ,(if awc.rng-exprs + ^(let* ,(nreverse + (zip awc.rng-expr-temps + awc.rng-exprs)) + ,p-actions-xform) + p-actions-xform)))) + ,*awc.begin-actions + (unwind-protect + (qref ,aws-sym (loop ,awk-fun + ,(if awc.begin-file-actions + awk-begf-fun) + ,(if awc.end-file-actions + awk-endf-fun))) + (set ,awk-retval (progn ,*awc.end-actions))) + ,awk-retval)))))))) |