olivier.massot 7 tahun lalu
induk
melakukan
faa1d9370d
6 mengubah file dengan 53 tambahan dan 30 penghapusan
  1. 31 23
      core.py
  2. 3 2
      main.py
  3. 4 1
      test/source/modules/General.bas
  4. 11 0
      test/source/queries/Union.bas
  5. 4 4
      test/source/queries/victoires_par_type.bas
  6. TEMPAT SAMPAH
      test/test.zip

+ 31 - 23
core.py

@@ -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):

+ 3 - 2
main.py

@@ -7,8 +7,9 @@ from PyQt5.Qt import QApplication, QMessageBox
 
 from Viewer import Viewer
 
-# TODO: La sauvegarde lève une RecursionError lorsqu'il y a des references circulaires
-# TODO: editer un objet sur double-clic
+# TODO: editer un objet sur double-clic sur l'item graphique
+# TODO: Permettre de limiter le nombre d'"étages" à afficher
+# TODO: Dans le TreeWidget: aficher la liste des fonctons à la place de celle des modules, sous la forme "Module.fonction"
 
 if __name__ == '__main__':
     app = QApplication(sys.argv)

+ 4 - 1
test/source/modules/General.bas

@@ -2,6 +2,9 @@ Option Compare Database
 
 Public Function count_chevalier()
 
-    count_chevalier = DCount("id", "Chevaliers", "")
+    count_chevalier = DCount("id", "chevaliers", "") 'essai avec une mauvaise casse
+
+    'essai avec deux noms sur une même ligne
+    SQL = "SELECT Chevaliers.nom, tblChateaux.nom FROM tblChateaux LEFT JOIN Chevaliers ON tblChateaux.id = Chevaliers.idChateau;"
 
 End Function

+ 11 - 0
test/source/queries/Union.bas

@@ -0,0 +1,11 @@
+dbMemo "SQL" ="SELECT *  FROM Chevaliers\015\012UNION SELECT * FROM Chevaliers;\015\012"
+dbMemo "Connect" =""
+dbBoolean "ReturnsRecords" ="-1"
+dbInteger "ODBCTimeout" ="60"
+dbBoolean "OrderByOn" ="0"
+dbByte "Orientation" ="0"
+dbByte "DefaultView" ="2"
+dbBoolean "FilterOnLoad" ="0"
+dbBoolean "OrderByOnLoad" ="-1"
+Begin
+End

+ 4 - 4
test/source/queries/victoires_par_type.bas

@@ -63,12 +63,12 @@ Begin
     State =0
     Left =0
     Top =0
-    Right =648
-    Bottom =544
+    Right =1465
+    Bottom =826
     Left =-1
     Top =-1
-    Right =632
-    Bottom =265
+    Right =1449
+    Bottom =248
     Left =0
     Top =0
     ColumnsShown =543

TEMPAT SAMPAH
test/test.zip