From f0644f047962c94c5742cc2e260e3dd7da7e946d Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 6 Aug 2015 14:59:20 -0400 Subject: [PATCH] lib/sepx: provide location to each parsed node Signed-off-by: Jean Privat --- lib/sexp.nit | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/sexp.nit b/lib/sexp.nit index 491abdc..fa7c513 100644 --- a/lib/sexp.nit +++ b/lib/sexp.nit @@ -99,9 +99,8 @@ class SExpProcessor var srclen = src.length var delims = once ['(', ')', '"'] ignore_whitespaces - if pos >= srclen then return new SExpError("Empty S-Expression", location = new Location(line, line_offset)) + if pos >= srclen then return new SExpError(new Location(line, line_offset), "Empty S-Expression") var c = src[pos] - if pos >= srclen then return new SExpError("Empty S-Expression") if c == '(' then var cnt = new SExp var loc = new Location(line, line_offset) @@ -116,30 +115,32 @@ class SExpProcessor pos += 1 return cnt else - return new SExpError("Incomplete S-Expression", location = loc) + return new SExpError(loc, "Incomplete S-Expression") end else if c == '"' then var stdq = pos + var loc = new Location(line, line_offset) pos += 1 ignore_until("\"") pos += 1 var endq = pos - return new SExpDQString(src.substring(stdq, endq - stdq)) + return new SExpDQString(loc, src.substring(stdq, endq - stdq)) else var stid = pos + var loc = new Location(line, line_offset) while pos < srclen and not c.is_whitespace and not delims.has(c) do c = src[pos] pos += 1 end if delims.has(c) or c.is_whitespace then pos -= 1 - if pos >= srclen then return new SExpError("Invalid S-Expression") + if pos >= srclen then return new SExpError(loc, "Invalid S-Expression") var endid = pos var cntstr = src.substring(stid, endid - stid) var cnt: SExpEntity if cntstr.is_numeric then - cnt = new SExpFloat(cntstr.to_f) + cnt = new SExpFloat(loc, cntstr.to_f) else - cnt = new SExpId(cntstr) + cnt = new SExpId(loc, cntstr) end return cnt end -- 1.7.9.5