Changeset

2946:ad306c5ae689

tools/erlparse: Report the line number when showing a syntax error in the input file
author Matthew Wild <mwild1@gmail.com>
date Thu, 25 Mar 2010 19:34:05 +0000
parents 2945:475dee08b400
children 2947:ff7f6668b34f
files tools/erlparse.lua
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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)