|
|
@@ -4,9 +4,10 @@
|
|
|
import pickle
|
|
|
import re
|
|
|
|
|
|
-from _regex_core import MULTILINE
|
|
|
+from _regex_core import MULTILINE, IGNORECASE, VERBOSE
|
|
|
from path import Path
|
|
|
|
|
|
+
|
|
|
here = Path(__file__).parent.abspath()
|
|
|
|
|
|
def recurse(acc_obj):
|
|
|
@@ -134,7 +135,7 @@ class RelationObject(AccessObject):
|
|
|
|
|
|
class Analyse():
|
|
|
objects = []
|
|
|
- index = {}
|
|
|
+ glossary = {}
|
|
|
|
|
|
@classmethod
|
|
|
def report(cls, current, total, msg=""):
|
|
|
@@ -154,27 +155,29 @@ class Analyse():
|
|
|
cls.objects = []
|
|
|
with open(filepath, 'rb') as f:
|
|
|
cls.objects = pickle.load(f)
|
|
|
- cls.update_index()
|
|
|
+ cls.build_glossary()
|
|
|
|
|
|
@classmethod
|
|
|
- def update_index(cls):
|
|
|
- cls.index = {}
|
|
|
+ def build_glossary(cls):
|
|
|
+ cls.glossary.clear()
|
|
|
+
|
|
|
for obj in cls.objects:
|
|
|
- if not obj.name_ in cls.index:
|
|
|
- cls.index[obj.name_] = []
|
|
|
- cls.index[obj.name_].append(obj)
|
|
|
+ if not obj.name_.lower() in cls.glossary:
|
|
|
+ cls.glossary[obj.name_.lower()] = []
|
|
|
+
|
|
|
+ cls.glossary[obj.name_.lower()].append(obj)
|
|
|
+
|
|
|
if type(obj) is ModuleObject:
|
|
|
for fname in obj.functions:
|
|
|
- if not fname in cls.index:
|
|
|
- cls.index[fname] = []
|
|
|
- cls.index[fname].append(obj)
|
|
|
+ if not fname.lower() in cls.glossary:
|
|
|
+ cls.glossary[fname.lower()] = []
|
|
|
+ cls.glossary[fname.lower()].append(obj)
|
|
|
|
|
|
@classmethod
|
|
|
def load_objects(cls, source_dir):
|
|
|
source_dir = Path(source_dir)
|
|
|
|
|
|
cls.objects = []
|
|
|
- cls.index = {}
|
|
|
|
|
|
sourcemap = {
|
|
|
"tables": TableObject,
|
|
|
@@ -197,35 +200,40 @@ class Analyse():
|
|
|
print("Ignored unrecognized file: {}".format(file))
|
|
|
|
|
|
cls.objects.sort(key=lambda x: (x._order, x.name_))
|
|
|
- cls.update_index()
|
|
|
+ cls.build_glossary()
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
def parse_source(cls, subject):
|
|
|
|
|
|
# On cherche le nom de chaque autre objet, ainsi que le nom des fonctions issues des modules
|
|
|
- look_for = [obj.name_ for obj in cls.objects if obj is not subject and type(object) is not ModuleObject] + list(sum([obj.functions for obj in cls.objects if obj is not subject], []))
|
|
|
+ look_for = {obj.name_ for obj in cls.objects if obj is not subject and type(object) is not ModuleObject} | set(sum([obj.functions for obj in cls.objects if obj is not subject], []))
|
|
|
|
|
|
- names = "|".join(list(set(look_for)))
|
|
|
+ names = "|".join(list(look_for))
|
|
|
+ seps = "|".join(("\t", " ", "\[", "\]", "&", "\(", "\)", "\.", "!", "'", "\"", r"\\015", r"\\012")) # Note: Les separateurs possibles incluent \015 et \012 qui sont les hexadecimaux pour \n et \r
|
|
|
|
|
|
- rx = re.compile("""(.*(?:^|\t| |\[|\]|&|\(|\)|\.|!|"|')({})(?:$|\t| |\[|\]|&|\(|\)|\.|!|"|').*)""".format(names), MULTILINE)
|
|
|
+ rstr = """(?:^|{seps})({names})(?:$|{seps})""".format(seps=seps, names=names)
|
|
|
+
|
|
|
+ rx = re.compile(rstr, MULTILINE | IGNORECASE | VERBOSE)
|
|
|
|
|
|
# Indexe la position des lignes
|
|
|
- line_ends = [m.end() for m in re.finditer('.*\n', subject.sourcecode)]
|
|
|
+ line_matches = list(re.finditer('.*\n', subject.sourcecode))
|
|
|
|
|
|
for match in rx.finditer(subject.sourcecode):
|
|
|
- line = next(i for i in range(len(line_ends)) if line_ends[i] > match.start(1)) + 1
|
|
|
- quote = match.group(1).replace("\r", "").replace("\n", "").strip()
|
|
|
- objname = match.group(2)
|
|
|
+ line_number, line = next((i + 1, line) for i, line in enumerate(line_matches) if line.end() > match.start(1))
|
|
|
+
|
|
|
+ quote = line.group(0).replace("\r", "").replace("\n", "").strip()
|
|
|
+
|
|
|
+ objname = match.group(1)
|
|
|
warnings = []
|
|
|
|
|
|
if objname == subject.name_:
|
|
|
obj = subject
|
|
|
warnings.append(WarnRefItself())
|
|
|
else:
|
|
|
- obj = cls.index[objname][0]
|
|
|
+ obj = cls.glossary[objname.lower()][0]
|
|
|
|
|
|
- if len(cls.index[objname]) > 1:
|
|
|
+ if len(cls.glossary[objname.lower()]) > 1:
|
|
|
warnings.append(WarnDuplicate())
|
|
|
|
|
|
if type(subject) is ModuleObject:
|
|
|
@@ -236,7 +244,7 @@ class Analyse():
|
|
|
if re.match(r"Caption =\".*{}.*\"".format(objname), quote):
|
|
|
warnings.append(WarnCaption())
|
|
|
|
|
|
- subject.mentions.append(Mention(line, objname, quote, obj, warnings))
|
|
|
+ subject.mentions.append(Mention(line_number, objname, quote, obj, warnings))
|
|
|
|
|
|
@classmethod
|
|
|
def parse_all(cls):
|