From 1d14cb1ad8d4d98ea19daa2d5ab6ded59d58553a Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 30 Aug 2012 22:55:32 +0200 Subject: next steps towards term rewriting macros; simple examples work --- compiler/patterns.nim | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'compiler/patterns.nim') diff --git a/compiler/patterns.nim b/compiler/patterns.nim index 51bb1fb69..7109d9975 100644 --- a/compiler/patterns.nim +++ b/compiler/patterns.nim @@ -92,7 +92,15 @@ proc matches(c: PPatternContext, p, n: PNode): bool = of nkCharLit..nkInt64Lit: result = p.intVal == n.intVal of nkFloatLit..nkFloat64Lit: result = p.floatVal == n.floatVal of nkStrLit..nkTripleStrLit: result = p.strVal == n.strVal - of nkEmpty, nkNilLit, nkType: result = true + of nkEmpty, nkNilLit, nkType: + result = true + # of nkStmtList: + # both are statement lists; we need to ignore comment statements and + # 'nil' statements and check whether p <: n which is however trivially + # checked as 'applyRule' is checked after every created statement + # already; We need to ensure that the matching span is passed to the + # macro and NOT simply 'n'! + # XXX else: if sonsLen(p) == sonsLen(n): for i in countup(0, sonsLen(p) - 1): @@ -121,8 +129,6 @@ proc applyRule*(c: PContext, s: PSym, n: PNode): PNode = let param = params.sons[i].sym let x = IdNodeTableGetLazy(ctx.mapping, param) # couldn't bind parameter: - if isNil(x): - echo "couldn't bind ", param.name.s - return nil + if isNil(x): return nil result.add(x) - + markUsed(n, s) -- cgit 1.4.1-2-gfad0