Salome HOME
*** empty log message ***
[tools/eficas.git] / convert / parseur_python.py
index 07824016f4ad9e9ef7f9f4f1679966e6c4c95a51..68dc89052dcbf0a0aaf3ae7a528d9041a56c4014 100644 (file)
@@ -63,7 +63,8 @@ pattern_comment   = re.compile(r"^\s*#.*")
 #fin de ligne ; suivi d'un nombre quelconque de blancs (pas multiligne)
 pattern_fin   = re.compile(r"; *$")
 #pattern pour supprimer les blancs, tabulations et fins de ligne
-pattern_blancs = re.compile(r"[\s\n]")
+pattern_blancs = re.compile(r"[ \t\r\f\v]")
+#pattern_blancs = re.compile(r"[\s\n]")
 number_kw_pattern=re.compile(r"""
 (
     #groupe nombre decimal
@@ -84,16 +85,22 @@ number_kw_pattern=re.compile(r"""
     #argument keyword
     [a-zA-Z_]\w*=
 )
-""",re.VERBOSE)
+""",re.VERBOSE|re.MULTILINE)
 
 def construit_genea(texte,liste_mc):
-    """Retourne un dictionnaire dont les cles sont des reels et les valeurs sont leurs representations textuelles.
+    """
+       Retourne un dictionnaire dont les cles sont des reels et les valeurs sont leurs representations textuelles.
+
        Realise un filtrage sur les reels :
+
          - Ne garde que les reels pour lesquels str ne donne pas une bonne representation.
          - Ne garde que les reels derriere un argument keyword dont le nom est dans liste_mc
-    >>> s = 'a=+21.3e-5*85,b=-.1234,c=81.6   , d= -8 , e=_F(x=342.67,y=-1), f=+1.1, g=(1.3,-5,1.54E-3)'
-    >>> construit_genea(s,['a','x'])
-    {0.000213: '21.3e-5'}
+
+       >>> s = '''a=+21.3e-5*85,b=-.1234,c=81.6   , d= -8 , e=_F(x=342.67,y=-1), f=+1.1, g=(1.3,-5,1.54E-3),
+       ... #POMPE_PRIMA._BOUCLE_N._2_ELEMENT_NUMERO:0239
+       ... h=_F(x=34.6,y=-1)'''
+       >>> construit_genea(s,['a','x'])
+       {0.000213: '21.3e-5'}
     """
     d={}
     mot=""
@@ -419,7 +426,9 @@ class PARSEUR_PYTHON:
             if commande_courante :
                 #on a une commande en cours. On l'enrichit ou on la termine
                 commande_courante.append_text(ligne)
-                if not linecontinueRE.search(line) and (hangingBraces == emptyHangingBraces) and not hangingComments:
+                if not linecontinueRE.search(line) \
+                   and (hangingBraces == emptyHangingBraces) \
+                   and not hangingComments:
                     #la commande est terminée 
                     #print "fin de commande"
                     self.analyse_reel(commande_courante.texte)
@@ -431,7 +440,9 @@ class PARSEUR_PYTHON:
             if affectation_courante != None :
                 #poursuite d'une affectation
                 affectation_courante.append_text(ligne)
-                if not linecontinueRE.search(line) and (hangingBraces == emptyHangingBraces) and not hangingComments:
+                if not linecontinueRE.search(line) \
+                   and (hangingBraces == emptyHangingBraces) \
+                   and not hangingComments:
                     #L'affectation est terminée
                     affectation_courante=None
                 #on passe à la ligne suivante
@@ -469,7 +480,9 @@ class PARSEUR_PYTHON:
 
                 affectation_courante = AFFECTATION(self)
                 affectation_courante.append_text(text)
-                if not linecontinueRE.search(line) and (hangingBraces == emptyHangingBraces) and not hangingComments:
+                if not linecontinueRE.search(line) \
+                   and (hangingBraces == emptyHangingBraces) \
+                   and not hangingComments:
                     #L'affectation est terminée
                     affectation_courante=None
                 #on passe à la ligne suivante
@@ -481,7 +494,9 @@ class PARSEUR_PYTHON:
                 commande_courante = COMMANDE(self)
                 commande_courante.append_text(ligne)
                 #si la commande est complète, on la termine
-                if not linecontinueRE.search(line) and (hangingBraces == emptyHangingBraces) and not hangingComments:
+                if not linecontinueRE.search(line) \
+                   and (hangingBraces == emptyHangingBraces) \
+                   and not hangingComments:
                     #la commande est terminée 
                     #print "fin de commande"
                     self.analyse_reel(commande_courante.texte)
@@ -594,7 +609,10 @@ class PARSEUR_PYTHON:
            #index=epure1.find("=")
            #epure2=epure1[index+1:len(epure1)].replace("_F(","(")
            #dict_reel_concept=self.construit_genea(epure2)
-           dict_reel_concept=construit_genea(epure2,self.appli.liste_simp_reel)
+           if self.appli:
+             dict_reel_concept=construit_genea(epure2,self.appli.liste_simp_reel)
+           else:
+             dict_reel_concept={}
         if nomConcept !=None :
            if len(dict_reel_concept) != 0:
               self.appli.dict_reels[nomConcept]=dict_reel_concept
@@ -614,6 +632,12 @@ class PARSEUR_PYTHON:
             txt=self.texte
         return txt
 
+def test():
+  import parseur_python
+  import doctest
+  doctest.testmod(parseur_python)
+
+
 if __name__ == "__main__" :
     import time
     #fichier = 'D:/Eficas_dev/Tests/zzzz100a.comm'
@@ -622,6 +646,7 @@ if __name__ == "__main__" :
     fichier = '/local/chris/ASTER/instals/STA8.2/astest/forma12c.comm'
     fichier = 'titi.comm'
     fichier = '../Aster/sdls300a.comm'
+    fichier = '../Aster/az.comm'
     texte = open(fichier,'r').read()
     class appli:
        dict_reels={}