tools/erlparse: Report the line number when showing a syntax error in the input file

Thu, 25 Mar 2010 19:34:05 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 25 Mar 2010 19:34:05 +0000
changeset 2946
ad306c5ae689
parent 2945
475dee08b400
child 2947
ff7f6668b34f

tools/erlparse: Report the line number when showing a syntax error in the input file

tools/erlparse.lua file | annotate | diff | comparison | revisions
--- a/tools/erlparse.lua	Thu Mar 25 19:32:35 2010 +0000
+++ b/tools/erlparse.lua	Thu Mar 25 19:34:05 2010 +0000
@@ -12,12 +12,16 @@
 
 local file = nil;
 local last = nil;
+local line = 1;
 local function read(expected)
 	local ch;
 	if last then
 		ch = last; last = nil;
-	else ch = file:read(1); end
-	if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end
+	else
+		ch = file:read(1);
+		if ch == "\n" then line = line + 1; end
+	end
+	if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil").." on line "..line); end
 	return ch;
 end
 local function pushback(ch)

mercurial