Permalink
Browse files

format output message

  • Loading branch information...
xiaoganghan committed Jan 25, 2014
1 parent c8c4b85 commit 81dd1c0ca93cc774a46a22b82d7689608aa71caa
Showing with 13 additions and 9 deletions.
  1. +11 −7 checker.py
  2. +2 −2 style-check.py
View
@@ -19,7 +19,6 @@ def get_rules():
expression, reason = line.split('%')
expression = expression.rstrip()
reason = reason.strip()
- # expression, reason = map(str.strip, line.split('%'))
if reason:
check_type = reason.split()[0]
if check_type == 'syntax':
@@ -42,18 +41,23 @@ def get_rules():
def match(censored_phrases, text):
problems = []
+ characters = 128
for ind, line in enumerate(text.split('\n')):
- for k, v in censored_phrases.items():
- m = k.search(line)
+ for regex, reason in censored_phrases.items():
+ m = regex.search(line)
if m:
- problems.append((m.group(), ind+1, m.span(), k.pattern, v))
- problems = sorted(problems, key=lambda x: x[1])
+ extra = int((characters - (m.end() - m.start())) / 2)
+ context = line[m.start() - extra: m.end() + extra]
+ problems.append((ind+1, m.span(), context, regex.pattern, reason))
+ problems = sorted(problems, key=lambda x: x[0])
+ problems = ['L%d[%d:%d]:\t%s\t(%s)' % (p[0], p[1][0], p[1][1], p[2], p[4]) for p in problems]
return problems
if __name__ == '__main__':
text = """
hello the the book is very good in order to utilize
- hello the the book is very good in order to utilize
"""
- print(match(get_rules(), text))
+ problems = match(get_rules(), text)
+ for problem in problems:
+ print(problem)
View
@@ -1,4 +1,5 @@
# Check English writing style
+
import os
import sublime, sublime_plugin, urllib.request, urllib.parse, re
from .checker import get_rules, match
@@ -22,6 +23,5 @@ def correct(self, text):
for problem in problems:
print(problem)
- fix = '%s -> [%s]' % (text, text)
- return fix
+ return ''

0 comments on commit 81dd1c0

Please sign in to comment.