summaryrefslogtreecommitdiff
path: root/pythonpath
diff options
context:
space:
mode:
authorOlivier R <dicollecte@free.fr>2012-02-15 10:25:48 +0100
committerLászló Németh <nemeth@numbertext.org>2012-02-15 10:25:48 +0100
commit0c7e053f2ca4b73154630ea7599236c87a6e1985 (patch)
tree628f3601f847d164e34595ef3ff9bd8d5ec6f3d7 /pythonpath
parent43086af5853a5d1a64ca79395bec8a027755e4d2 (diff)
Error positioning
Diffstat (limited to 'pythonpath')
-rw-r--r--pythonpath/lightproof_compile___implname__.py13
-rw-r--r--pythonpath/lightproof_impl___implname__.py9
2 files changed, 14 insertions, 8 deletions
diff --git a/pythonpath/lightproof_compile___implname__.py b/pythonpath/lightproof_compile___implname__.py
index 376f040..3e9e598 100644
--- a/pythonpath/lightproof_compile___implname__.py
+++ b/pythonpath/lightproof_compile___implname__.py
@@ -36,6 +36,7 @@ def mysplit(s, line, oldline, debug):
dec = 0
exprep = 0 # replacement is a Python expression (beginning with sign =)
condition = False
+ ngroup = 0 # back reference group number that will be used for error positioning
# description
c = re.search("\s#\s", s)
com = u""
@@ -49,7 +50,7 @@ def mysplit(s, line, oldline, debug):
com = prepare_for_eval(com)
s = s[:c]
m1 = re.search("<-", s)
- m2 = re.search("->", s)
+ m2 = re.search("-\d*>", s)
if m1 and m2:
condition = prepare_for_eval(s[m1.end(0): m2.start(0)].strip())
s = s[0:m1.start(0)] + s[m2.start(0):]
@@ -61,7 +62,7 @@ def mysplit(s, line, oldline, debug):
s1 = s[1:pos+1]
s2 = s[pos+2:].strip()
else:
- m = re.compile("->").search(s)
+ m = re.compile("-\d*>").search(s)
if not m:
m = re.compile("[_a-zA-Z][_a-zA-Z0-9]*").match(s)
if not m:
@@ -83,9 +84,11 @@ def mysplit(s, line, oldline, debug):
tests += [[s1[5:].strip(), s[m.end(0):].strip(), oldline]]
return None
s2 = s[m.start(0):].strip()
- m = re.compile("->").match(s2)
+ m = re.compile("-(\d*)>").match(s2)
if dec!= 1 and m:
s2 = s2[m.end(0):].strip()
+ if m.group(1):
+ ngroup = int(m.group(1))
elif dec!=1:
# syntax error
return oldline
@@ -170,8 +173,8 @@ def mysplit(s, line, oldline, debug):
except Exception as e:
raise Exception(str(e), oldline)
if debug:
- return [s1, s2, com, condition, oldline]
- return [s1, s2, com, condition]
+ return [s1, s2, com, condition, ngroup, oldline]
+ return [s1, s2, com, condition, ngroup]
# group renum (<groupname> -> <groupname_1> etc.)
def renum(regex, s1, beg):
diff --git a/pythonpath/lightproof_impl___implname__.py b/pythonpath/lightproof_impl___implname__.py
index 6e572d6..9dd70fc 100644
--- a/pythonpath/lightproof_impl___implname__.py
+++ b/pythonpath/lightproof_impl___implname__.py
@@ -150,13 +150,16 @@ def proofread( nDocId, TEXT, LOCALE, nStartOfSentencePos, nSuggestedSentenceEndP
aErrs = []
s = TEXT[nStartOfSentencePos:nSuggestedSentenceEndPos]
for i in get_rule(LOCALE).dic:
+ # 0: regex, 1: replacement, 2: message, 3: condition, 4: ngroup, (5: oldline), 6: case sensitive ?
if i[0] and not str(i[0]) in ignore:
for m in i[0].finditer(s):
try:
if not i[3] or eval(i[3]):
aErr = uno.createUnoStruct( "com.sun.star.linguistic2.SingleProofreadingError" )
aErr.nErrorStart = nStartOfSentencePos + m.start(0) # nStartOfSentencePos
- aErr.nErrorLength = m.end(0) - m.start(0)
+ aErr.nErrorLength = m.end(i[4]) - m.start(i[4])
+ if i[4]:
+ aErr.nErrorStart += m.start(i[4])
aErr.nErrorType = PROOFREADING
aErr.aRuleIdentifier = str(i[0])
iscap = (i[-1] and m.group(0)[0:1].isupper())
@@ -183,8 +186,8 @@ def proofread( nDocId, TEXT, LOCALE, nStartOfSentencePos, nSuggestedSentenceEndP
aErr.aProperties = ()
aErrs = aErrs + [aErr]
except Exception as e:
- if len(i) == 6:
- raise Exception(str(e), i[4])
+ if len(i) == 7:
+ raise Exception(str(e), i[5])
raise
return tuple(aErrs)