Rewrite ReportError() and change EParse to report columns in chars.

ReportError() needed to account for terminal encodings that don't support the characters being printed. It was also reporting an inaccurate column number and its corresponding marker position, because the count was in bytes, not in characters, so that has been fixed.

Now EParse.__init__() calls a new function GetErrLineCol() that calculates the line and column corresponding to an error position.

The algorithm for finding the start of the line has also been changed in both ReportError() and EParse.__init__(); as a result, function fieldpos() has been removed.

The exception's lno and cno fields have been changed to be 1-based, rather than 0-based.

Thanks to @Jomik for the report. Fixes #5.
This commit is contained in:
Sei Lisa 2017-10-02 00:40:59 +02:00
parent 08c69eee0f
commit c544b51e37
3 changed files with 35 additions and 24 deletions

View file

@ -21,7 +21,7 @@
from lslopt.lslparse import parser,EParseSyntax,EParseUEOF,EParseAlreadyDefined,\
EParseUndefined,EParseTypeMismatch,EParseReturnShouldBeEmpty,EParseReturnIsEmpty,\
EParseInvalidField,EParseFunctionMismatch,EParseDeclarationScope,\
EParseDuplicateLabel,EParseCantChangeState,EParseCodePathWithoutRet,fieldpos
EParseDuplicateLabel,EParseCantChangeState,EParseCodePathWithoutRet
from lslopt.lsloutput import outscript
from lslopt.lsloptimizer import optimizer
from lslopt import lslfuncs
@ -217,7 +217,6 @@ class Test02_Parser(UnitTestCase):
))
print self.parser.scopeindex
self.assertEqual(fieldpos("a,b", ",", 3), -1)
self.assertEqual(self.outscript.Value2LSL(lslfuncs.Key(u'')), '((key)"")')
self.assertRaises(AssertionError, self.outscript.Value2LSL, '')
@ -528,7 +527,7 @@ class Test03_Optimizer(UnitTestCase):
self.assertFalse(True)
except EParseSyntax as e:
# should err before first closing brace
self.assertEqual(e.cno, 27)
self.assertEqual(e.cno, 28)
except:
# should raise no other exception
self.assertFalse(True)