Fixed line/column reporting.
h3rald h3rald@h3rald.com
Sun, 30 Nov 2014 21:05:14 +0100
4 files changed,
17 insertions(+),
18 deletions(-)
M
interpreter.nim
→
interpreter.nim
@@ -40,7 +40,7 @@
proc newMinInterpreter*(debugging = false): TMinInterpreter = var s:TMinStack = newSeq[TMinValue](0) var p:TMinParser - var i:TMinInterpreter = TMinInterpreter(filename: "input", parser: p, stack: s, debugging: debugging, currSym: TMinValue(first: 0, last: 0, line: 0, kind: minSymbol, symVal: "")) + var i:TMinInterpreter = TMinInterpreter(filename: "input", parser: p, stack: s, debugging: debugging, currSym: TMinValue(column: 1, line: 1, kind: minSymbol, symVal: "")) return i proc error*(i: TMinInterpreter, status: TMinError, message = "") =@@ -48,7 +48,7 @@ var msg = if message == "": ERRORS[status] else: message
if i.filename == "": stderr.writeln("`$1`: Error - $2" %[i.currSym.symVal, msg]) else: - stderr.writeln("$1[$2,$3] `$4`: Error - $5" %[i.filename, $i.currSym.line, $i.currSym.last, i.currSym.symVal, msg]) + stderr.writeln("$1 [$2,$3] `$4`: Error - $5" %[i.filename, $i.currSym.line, $i.currSym.column, i.currSym.symVal, msg]) quit(int(status)) proc open*(i: var TMinInterpreter, stream:PStream, filename: string) =
M
minim.nim
→
minim.nim
@@ -7,7 +7,7 @@ var debugging = false
var repl = false const prelude = "prelude.min".slurp.strip -let usage* = " MiNiM v" & version & " - a tiny concatenative programming language" & """ +let usage* = " MiNiM v" & version & " - a tiny concatenative system programming language" & """ (c) 2014 Fabio Cevasco@@ -24,11 +24,11 @@ -i, --interactive Starts MiNiM's Read Evel Print Loop"""
proc minimStream(s: PStream, filename: string) = var i = newMinInterpreter(debugging) + i.eval prelude i.open(s, filename) discard i.parser.getToken() i.interpret() i.close() - proc handleReplCtrlC() {.noconv.}= echo "\n-> Exiting..."
M
parser.nim
→
parser.nim
@@ -21,9 +21,8 @@ minString,
minSymbol, minBool TMinValue* = object - first*: int - last*: int - line*: int + line*: int + column*: int case kind*: TMinKind of minInt: intVal*: int of minFloat: floatVal*: float@@ -399,20 +398,20 @@ proc parseMinValue*(p: var TMinParser): TMinValue =
#echo p.a, " (", p.token, ")" case p.token of tkTrue: - result = TMinValue(kind: minBool, boolVal: true, first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minBool, boolVal: true, column: p.getColumn, line: p.lineNumber) discard getToken(p) of tkFalse: - result = TMinValue(kind: minBool, boolVal: false, first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minBool, boolVal: false, column: p.getColumn, line: p.lineNumber) discard getToken(p) of tkString: - result = TMinValue(kind: minString, strVal: p.a, first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minString, strVal: p.a, column: p.getColumn, line: p.lineNumber) p.a = "" discard getToken(p) of tkInt: - result = TMinValue(kind: minInt, intVal: parseint(p.a), first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minInt, intVal: parseint(p.a), column: p.getColumn, line: p.lineNumber) discard getToken(p) of tkFloat: - result = TMinValue(kind: minFloat, floatVal: parseFloat(p.a), first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minFloat, floatVal: parseFloat(p.a), column: p.getColumn, line: p.lineNumber) discard getToken(p) of tkBracketLe: var q = newSeq[TMinValue](0)@@ -420,9 +419,9 @@ discard getToken(p)
while p.token != tkBracketRi: q.add parseMinValue(p) eat(p, tkBracketRi) - result = TMinValue(kind: minQuotation, qVal: q, first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minQuotation, qVal: q, column: p.getColumn, line: p.lineNumber) of tkSymbol: - result = TMinValue(kind: minSymbol, symVal: p.a, first: p.bufpos-p.a.len, last: p.bufpos, line: p.lineNumber) + result = TMinValue(kind: minSymbol, symVal: p.a, column: p.getColumn, line: p.lineNumber) p.a = "" discard getToken(p) else:
M
primitives.nim
→
primitives.nim
@@ -305,13 +305,13 @@ if q1.isQuotation and q2.isQuotation:
if q1.qVal.len == 1 and q1.qVal[0].kind == minSymbol: minsym q1.qVal[0].symVal: i.evaluating = true - for item in q2.qVal: - i.push item + echo q2 + i.push q2.qVal i.evaluating = false else: - i.error(errIncorrect, "The top quotation must contain only one symbol value") + i.error errIncorrect, "The top quotation must contain only one symbol value" else: - i.error(errIncorrect, "Two quotations or two strings is required on the stack") + i.error errIncorrect, "Two quotations are required on the stack" minsym "eval": let s = i.pop