tools/erlparse: Report the line number when showing a syntax error in the input file
authorMatthew Wild <mwild1@gmail.com>
Thu, 25 Mar 2010 19:34:05 +0000 (19:34 +0000)
committerMatthew Wild <mwild1@gmail.com>
Thu, 25 Mar 2010 19:34:05 +0000 (19:34 +0000)
tools/erlparse.lua

index fdef7e8c6de8afe8c991e54e689f2b287b6f56f4..a5cef46480a30c832db521fdba7bae8c2bcc4e07 100644 (file)
@@ -12,12 +12,16 @@ local type, tonumber, tostring = type, tonumber, tostring;
 
 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)