summaryrefslogtreecommitdiff
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
parent43086af5853a5d1a64ca79395bec8a027755e4d2 (diff)
Error positioning
-rw-r--r--ChangeLog5
-rw-r--r--doc/syntax.txt26
-rw-r--r--pythonpath/lightproof_compile___implname__.py13
-rw-r--r--pythonpath/lightproof_impl___implname__.py9
4 files changed, 44 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index e448a35..12ab0cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
+2012-02-15 Olivier Ronez <dicollecte.org>:
+ - new: error positioning, underline a back reference group instead of the full pattern
+
2012-02-12 Olivier Ronez <dicollecte.org>:
- back references in explanations, eg. # \1 should be...
- - display message without suggestion, eg. # foo -> _ # Message
+ - display message without suggestion, eg. foo -> _ # Message
- function word() returns '' instead of None
- add .gitignore
diff --git a/doc/syntax.txt b/doc/syntax.txt
index afd122c..5679235 100644
--- a/doc/syntax.txt
+++ b/doc/syntax.txt
@@ -166,6 +166,32 @@ E ( |$) # name definition: space or end of sentence
See src/en/en.dat for more examples.
+= Error positioning =
+
+By default, the full pattern will be underlined with blue.
+You can shorten the underlined text aera by specifying a back reference group of the pattern.
+Instead of writing ->, write -n> n being the number of a back reference group.
+Actually, -> is similar to -0>
+
+Example
+(ying) and yang -1> yin # Did you mean:
+
+== Comparison ==
+
+Rule 1:
+ying and yang -> yin and yang # Did you mean:
+
+Rule 2:
+(ying) and yang -1> yin # Did you mean:
+
+With the rule 1, the full pattern is underlined:
+ ying and yang
+ ^^^^^^^^^^^^^
+
+With the rule 2, only the first back reference group is underlined:
+ ying and yang
+ ^^^^
+
= Conditions =
A Lightproof condition is a Python condition with some modifications:
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)