SEBA-709 Handle parse errors at end of input

Change-Id: I8209dfc41c48e42ab4016ad6ad4d3e37f9195a3b
diff --git a/VERSION b/VERSION
index 1454f6e..4d54dad 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-4.0.1
+4.0.2
diff --git a/src/plyxproto/parser.py b/src/plyxproto/parser.py
index f96125c..c81e4d1 100755
--- a/src/plyxproto/parser.py
+++ b/src/plyxproto/parser.py
@@ -653,7 +653,12 @@
         p[0] = p[2]
 
     def p_error(self, p):
-        raise ParsingError("Parsing Error", (p.lineno, p.lexpos, len(p.value)))
+        if p is None:
+            # Omitting the closing brace on a message is one way to cause this to happen.
+            # Looking up the call stack implies this might be when the parser hits EOF.
+            raise ParsingError("Parsing Error, unknown token, maybe at end of file", None)
+        else:
+            raise ParsingError("Parsing Error", (p.lineno, p.lexpos, len(p.value)))
 
 
 class ProtobufAnalyzer(object):