aboutsummaryrefslogtreecommitdiff
path: root/src/interp/pf2sex.boot
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2007-12-08 20:52:48 +0000
committerdos-reis <gdr@axiomatics.org>2007-12-08 20:52:48 +0000
commit8bd29deee2d75510dc62408582ac8449df93a166 (patch)
treecfa9c528b1a66a1a4ae8295c967427ebef4feca0 /src/interp/pf2sex.boot
parent8b3133a5015424ab3b0b90ecc0fb606be000aa2a (diff)
downloadopen-axiom-8bd29deee2d75510dc62408582ac8449df93a166.tar.gz
Add support for quasiquotation.
* compiler.boot (compileQuasiquote): New function. * fnewmeta.lisp (|PARSE-Enclosure|): Parse quasiquotes too. * i-intern.boot (mkAtree3): Don't evaluate arguments to quasiquote. * i-spec1.boot ($specialOps): Register [||]. (up[||]): Handle quasiquotes. * newaux.lisp: Register `[|' and `|]' as new glyphs. * pf2sex.boot ($insideApplication): Now count the nesting level of application forms. ($insideQuasiquote): New. Count nesting level of quasiquotes. (pfFinishApplication): Ensure application form nesting level is properly decreased. (pfApplication2Sex): Use it. (pfQuasiquotation2Sex): Transform quasiquote forms. (pf2Sex1): Use it. * sys-constants.boot ($Syntax): New.
Diffstat (limited to 'src/interp/pf2sex.boot')
-rw-r--r--src/interp/pf2sex.boot45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/interp/pf2sex.boot b/src/interp/pf2sex.boot
index 871d0c77..b4cde2eb 100644
--- a/src/interp/pf2sex.boot
+++ b/src/interp/pf2sex.boot
@@ -38,6 +38,12 @@ import '"ptrees"
$dotdot := INTERN('"..", '"BOOT")
$specificMsgTags := nil
+++ nonzero means we are processing an Application parse form
+$insideApplication := 0
+
+++ nonzero means we are processing a quasiquotation parse form
+$insideQuasiquotation := 0
+
-- Pftree to s-expression translation. Used to interface the new parser
-- technology to the interpreter. The input is a parseTree and the
-- output is an old-parser-style s-expression
@@ -45,8 +51,9 @@ $specificMsgTags := nil
pf2Sex pf ==
intUnsetQuiet()
$insideRule:local := false
- $insideApplication: local := false
+ $insideApplication := 0
$insideSEQ: local := false
+ $insideQuasiquotation := 0
pf2Sex1 pf
pf2Sex1 pf ==
@@ -202,11 +209,19 @@ pfOp2Sex pf ==
op
op
+pfFinishApplication pf ==
+ $insideApplication := $insideApplication - 1
+ pf
+
pfApplication2Sex pf ==
- $insideApplication: local := true
+ -- Assume we are parsing an application, so that we can translate
+ -- (DEF ...) as optional argument specification. That is a weird
+ -- syntax used for example with the drawing package for specifying
+ -- argument to the draw() commands.
+ $insideApplication := $insideApplication + 1
op := pfOp2Sex pfApplicationOp pf
op := opTran op
- op = "->" =>
+ op = "->" => pfFinishApplication
args := pf0TupleParts pfApplicationArg pf
if pfTuple? CAR args then
typeList := [pf2Sex1 arg for arg in pf0TupleParts CAR args]
@@ -215,11 +230,11 @@ pfApplication2Sex pf ==
args := [pf2Sex1 CADR args, :typeList]
["Mapping", :args]
symEqual(op, ":") and $insideRule = 'left =>
- ["multiple", pf2Sex pfApplicationArg pf]
+ pfFinishApplication ["multiple", pf2Sex pfApplicationArg pf]
symEqual(op, "?") and $insideRule = 'left =>
- ["optional", pf2Sex pfApplicationArg pf]
+ pfFinishApplication ["optional", pf2Sex pfApplicationArg pf]
args := pfApplicationArg pf
- pfTuple? args =>
+ pfTuple? args => pfFinishApplication
symEqual(op, "|") and $insideRule = 'left =>
pfSuchThat2Sex args
argSex := rest pf2Sex1 args
@@ -248,15 +263,23 @@ pfApplication2Sex pf ==
val := hasOptArgs? argSex => [op, :val]
[op, :argSex]
op is [qt, realOp] and symEqual(qt, "QUOTE") =>
- ["applyQuote", op, pf2Sex1 args]
- symEqual(op, "braceFromCurly") =>
+ pfFinishApplication ["applyQuote", op, pf2Sex1 args]
+ symEqual(op, "braceFromCurly") => pfFinishApplication
-- ["brace", ["construct", pf2Sex1 args]]
x := pf2Sex1 args
x is ["SEQ", :.] => x
["SEQ", x]
symEqual(op, "by") =>
- ["BY", pf2Sex1 args]
- [op, pf2Sex1 args]
+ pfFinishApplication ["BY", pf2Sex1 args]
+ symEqual(op, "[||]") =>
+ pfFinishApplication pfQuasiquotation2Sex(op, args)
+ pfFinishApplication [op, pf2Sex1 args]
+
+pfQuasiquotation2Sex(op, form) ==
+ $insideQuasiquotation := $insideQuasiquotation + 1
+ form := pf2Sex1 form
+ $insideQuasiquotation := $insideQuasiquotation - 1
+ [op, form]
hasOptArgs? argSex ==
nonOpt := nil
@@ -269,7 +292,7 @@ hasOptArgs? argSex ==
NCONC (nreverse nonOpt, [["construct", :nreverse opt]])
pfDefinition2Sex pf ==
- $insideApplication =>
+ $insideApplication > $insideQuasiquotation =>
["OPTARG", pf2Sex1 CAR pf0DefinitionLhsItems pf,
pf2Sex1 pfDefinitionRhs pf]
idList := [pf2Sex1 x for x in pf0DefinitionLhsItems pf]