@@ -251,9 +251,9 @@ { if( lex.empty ) throw genex!UnexpectedEOF(currentPosition(), "Reached EOF when tried to parse an expression"); - auto pos = lex.front.pos; + auto pos = currentPosition(); if( lex.front.quoted ) { scope(exit) lex.popFront; return new Str(pos, lex.front.str); @@ -324,14 +324,14 @@ // let pmVar = pmExpr in (... let pmTryFirst = ... in pmTryFirst()) AST pmExpr = E(0); string pmVar = freshVarName(); string pmTryFirst = freshVarName(); - AST pmBody = parsePatternMatchCases(pmVar, pmTryFirst, + AST pmBody = parsePatternMatchCases(pos, pmVar, pmTryFirst, new App(pos, new Var(pos, pmTryFirst))); return new Let(pos, pmVar, [], pmExpr, pmBody); } - AST parsePatternMatchCases(string pmVar, string tryThisBranchVar, AST thenDoThis) + AST parsePatternMatchCases(LexPosition casePos, string pmVar, string tryThisBranchVar, AST thenDoThis) { // when pat: cBody //==> // ... let failBranchVar = ... in @@ -346,19 +346,18 @@ AST cBody = E(0); AST judgement = new App(pos, new Var(pos, "if"), ppTest(pmVar, pr), new Fun(pos,[],ppBind(pmVar, pr, cBody)), new Var(pos, failBranchVar)); - return parsePatternMatchCases(pmVar, failBranchVar, + return parsePatternMatchCases(casePos, pmVar, failBranchVar, new Let(pos, tryThisBranchVar, [], new Fun(pos,[],judgement), thenDoThis) ); } else { - auto pos = currentPosition(); - AST doNothing = new Fun(pos,[], - new Str(pos, sprintf!"(pattern match failure:%s)"(pos))); - return new Let(currentPosition(), tryThisBranchVar, [], doNothing, thenDoThis); + AST doNothing = new Fun(casePos,[], + new Str(casePos, sprintf!"(pattern match failure:%s)"(casePos))); + return new Let(casePos, tryThisBranchVar, [], doNothing, thenDoThis); } } // hageshiku tenuki @@ -558,9 +557,9 @@ } LexPosition currentPosition() { - return lex.empty ? null : lex.front.pos; + return lex.empty ? new LexPosition("EOF",0,0) : lex.front.pos; } } unittest