]> SALOME platform Git repositories - tools/eficas.git/commitdiff
Salome HOME
CCAR: correction de 2 bugs du parseur (masquage des commentaires
authorChristian Caremoli <>
Mon, 11 Sep 2006 06:36:44 +0000 (06:36 +0000)
committerChristian Caremoli <>
Mon, 11 Sep 2006 06:36:44 +0000 (06:36 +0000)
et décalage en première colonne du texte d'une commande à compiler)
Ajout de paramètres infile et outfile en ligne de commande de jdcparser.py

Traducteur/jdcparser.py
Traducteur/mocles.py

index e1a201fe36df7baf04359c5438ae48a0ea285ee1..7df70bdbdf6ea0bfbd2eb8916ee63e714e219b74 100644 (file)
@@ -1,6 +1,14 @@
+#!/usr/bin/env python
 # -*- coding: utf-8 -*-
+"""
+"""
+usage="""usage: %prog [options]
+Typical use is:
+  python jdcparser.py --infile=xxxx --outfile=yyyy
+"""
 
 import log
+import optparse
 
 from load import getJDC
 from mocles import parseKeywords
@@ -13,83 +21,97 @@ atraiter=("IMPR_GENE","CALC_FONCTION", "DEFI_MATERIAU","STAT_NON_LINE",
           "CALC_G_LOCAL_T","CALC_G_THETA_T","CALC_G",
         )
 
-
 #atraiter=("CALC_FONCTION","IMPR_GENE","STAT_NON_LINE","DEFI_MATERIAU",
 #          "CALC_G_LOCAL_T","CALC_G_THETA_T","CALC_G",)
 #atraiter=( "CALC_G_LOCAL_T","CALC_G_THETA_T","CALC_G",)
 #atraiter=( "IMPR_GENE",)
-filename="toto.comm"
-jdc=getJDC(filename,atraiter)
-root=jdc.root
-
-#Parse les mocles des commandes
-parseKeywords(root)
-
-
-#removemocle.removeMotCleInFact(jdc,"AFFE_MATERIAU","AFFE","TOUT")
-#removemocle.removeMotCle(jdc,"STAT_NONLINE","SOLVEUR")
-#renamemocle.renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","PHENOMENE","TOTO")
-#renamemocle.renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","MODELISATION","TITI")
-#renamemocle.renameMotCleInFact(jdc,"DEFI_GROUP","CREA_GROUP_NO","GROUP_MA","TUTU")
-#removemocle.removeMotCle(jdc,"LIRE_MAILLAGE","INFO")
-#removemocle.removeMotCle(jdc,"LIRE_MAILLAGE","UNITE")
-#renamemocle.renameMotCle(jdc,"DEFI_MATERIAU","ELAS","ELASTIC")
-#renamemocle.renameMotCle(jdc,"AFFE_MATERIAU","MAILLAGE","MAILL")
-#removemocle.removeMotCleInFact(jdc,"STAT_NONLINE","SOLV","METHOD")
-#removemocle.removeMotCle(jdc,"STAT_NONLINE","AFFE")
-#renamemocle.renameCommande(jdc,"AFFE_CHAR_MECA","AFFE_CHAR_MECA_PN")
-#renamemocle.renameCommande(jdc,"DEBUT","DEBUT_PN")
-
-#  A decommenter a partir d ici
-#          les arguments sont jdc,ancien-nom-de-commande,nouveau-nom-de-commande
-renamemocle.renameCommande(jdc,"CALC_FONCTION","INFO_FONCTION")
-
-#          Les arguments sont  - jdc,
-#                             - nom de la procedure (pas teste avec autre chose)
-#                             - nom du mot clef facteur contenant, 
-#                             - nom du mot cle simple
-#          Attention ne fonctionne pas pour l instant avec +sieurs occurences du mot cle à déplacer
-movemocle.moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","UNITE")
-movemocle.moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","FORMAT")
-
-#          Les arguments sont  - jdc
-#                             - nom de l operateur (pas teste avec autre chose)
-#                             - nom du mot clef facteur source, 
-#                             - nom du mot cle simple
-#                             - liste de  mots clef facteur arrivée possible
-#          Attention ne fonctionne pas pour l instant avec +sieurs occurences du mot cle à déplacer
-movemocle.moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","RESI_INTE_RELA",("COMP_INCR","COMP_ELAS"))
-
-
-renamemocle.renameMotCle(jdc,"DEFI_MATERIAU","LEMAITRE","LEMAITRE_IRRA")
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","QSR_K",("LEMAITRE_IRRA",))
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","BETA",("LEMAITRE_IRRA",))
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","PHI_ZERO",("LEMAITRE_IRRA",))
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","L",("LEMAITRE_IRRA",))
-removemocle.removeMotCle(jdc,"DEFI_MATERIAU","FLU_IRRA")
-
-renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","A","GRAN_A")
-renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","B","GRAN_B")
-renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","S","GRAN_S")
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_A",("LEMAITRE_IRRA",))
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_B",("LEMAITRE_IRRA",))
-movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_S",("LEMAITRE_IRRA",))
-removemocle.removeMotCle(jdc,"DEFI_MATERIAU","GRAN_IRRA")
-
-#renamemocle.renameOper(jdc,"CALC_G_LOCAL_T","CALC_G")
-renamemocle.renameOper(jdc,"CALC_G_THETA_T","CALC_G")
-renamemocle.renameMotCle(jdc,"CALC_G","THETA","THETA_OLD")
-inseremocle.chercheOperInsereFacteur(jdc,"CALC_G","THETA")
-
-movemocle.moveMotClefInOperToFact(jdc,"CALC_G","THETA_OLD","THETA")
-renamemocle.renameMotCleInFact(jdc,"CALC_G","THETA","THETA_OLD","THETA")
-movemocle.moveMotClefInOperToFact(jdc,"CALC_G","FOND_FISS","THETA")
-movemocle.moveMotClefInOperToFact(jdc,"CALC_G","R_INF_FO","THETA")
-movemocle.moveMotClefInOperToFact(jdc,"CALC_G","R_SUP_FO","THETA")
-inseremocle.chercheOperInsereFacteurSiRegle(jdc,"CALC_G","LISSAGE",((("DEGRE",),"existe"),))
-movemocle.moveMotClefInOperToFact(jdc,"CALC_G","DEGRE","LISSAGE")
-
-
-f=open("tutu.comm",'w')
-f.write(jdc.getSource())
-f.close()
+
+def traduc(infile,outfile):
+    jdc=getJDC(infile,atraiter)
+    root=jdc.root
+
+    #Parse les mocles des commandes
+    parseKeywords(root)
+
+    #removemocle.removeMotCleInFact(jdc,"AFFE_MATERIAU","AFFE","TOUT")
+    removemocle.removeMotCle(jdc,"STAT_NON_LINE","MODELE")
+    #removemocle.removeMotCle(jdc,"STAT_NONLINE","SOLVEUR")
+    #renamemocle.renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","PHENOMENE","TOTO")
+    #renamemocle.renameMotCleInFact(jdc,"AFFE_MODELE","AFFE","MODELISATION","TITI")
+    #renamemocle.renameMotCleInFact(jdc,"DEFI_GROUP","CREA_GROUP_NO","GROUP_MA","TUTU")
+    #removemocle.removeMotCle(jdc,"LIRE_MAILLAGE","INFO")
+    #removemocle.removeMotCle(jdc,"LIRE_MAILLAGE","UNITE")
+    #renamemocle.renameMotCle(jdc,"DEFI_MATERIAU","ELAS","ELASTIC")
+    #renamemocle.renameMotCle(jdc,"AFFE_MATERIAU","MAILLAGE","MAILL")
+    #removemocle.removeMotCleInFact(jdc,"STAT_NONLINE","SOLV","METHOD")
+    #removemocle.removeMotCle(jdc,"STAT_NONLINE","AFFE")
+    #renamemocle.renameCommande(jdc,"AFFE_CHAR_MECA","AFFE_CHAR_MECA_PN")
+    #renamemocle.renameCommande(jdc,"DEBUT","DEBUT_PN")
+    
+    #  A decommenter a partir d ici
+    #          les arguments sont jdc,ancien-nom-de-commande,nouveau-nom-de-commande
+    renamemocle.renameCommande(jdc,"CALC_FONCTION","INFO_FONCTION")
+
+    #          Les arguments sont  - jdc,
+    #                         - nom de la procedure (pas teste avec autre chose)
+    #                         - nom du mot clef facteur contenant, 
+    #                         - nom du mot cle simple
+    #          Attention ne fonctionne pas pour l instant avec +sieurs occurences du mot cle à déplacer
+    movemocle.moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","UNITE")
+    movemocle.moveMotCleFromFactToFather(jdc,"IMPR_GENE","GENE","FORMAT")
+
+    #          Les arguments sont  - jdc
+    #                         - nom de l operateur (pas teste avec autre chose)
+    #                         - nom du mot clef facteur source, 
+    #                         - nom du mot cle simple
+    #                         - liste de  mots clef facteur arrivée possible
+    #          Attention ne fonctionne pas pour l instant avec +sieurs occurences du mot cle à déplacer
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"STAT_NON_LINE","CONVERGENCE","RESI_INTE_RELA",("COMP_INCR","COMP_ELAS"))
+
+
+    renamemocle.renameMotCle(jdc,"DEFI_MATERIAU","LEMAITRE","LEMAITRE_IRRA")
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","QSR_K",("LEMAITRE_IRRA",))
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","BETA",("LEMAITRE_IRRA",))
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","PHI_ZERO",("LEMAITRE_IRRA",))
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","FLU_IRRA","L",("LEMAITRE_IRRA",))
+    removemocle.removeMotCle(jdc,"DEFI_MATERIAU","FLU_IRRA")
+
+    renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","A","GRAN_A")
+    renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","B","GRAN_B")
+    renamemocle.renameMotCleInFact(jdc,"DEFI_MATERIAU","GRAN_IRRA","S","GRAN_S")
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_A",("LEMAITRE_IRRA",))
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_B",("LEMAITRE_IRRA",))
+    movemocle.moveMotCleFromFactToFactMulti(jdc,"DEFI_MATERIAU","GRAN_IRRA","GRAN_S",("LEMAITRE_IRRA",))
+    removemocle.removeMotCle(jdc,"DEFI_MATERIAU","GRAN_IRRA")
+
+    #renamemocle.renameOper(jdc,"CALC_G_LOCAL_T","CALC_G")
+    renamemocle.renameOper(jdc,"CALC_G_THETA_T","CALC_G")
+    renamemocle.renameMotCle(jdc,"CALC_G","THETA","THETA_OLD")
+    inseremocle.chercheOperInsereFacteur(jdc,"CALC_G","THETA")
+
+    movemocle.moveMotClefInOperToFact(jdc,"CALC_G","THETA_OLD","THETA")
+    renamemocle.renameMotCleInFact(jdc,"CALC_G","THETA","THETA_OLD","THETA")
+    movemocle.moveMotClefInOperToFact(jdc,"CALC_G","FOND_FISS","THETA")
+    movemocle.moveMotClefInOperToFact(jdc,"CALC_G","R_INF_FO","THETA")
+    movemocle.moveMotClefInOperToFact(jdc,"CALC_G","R_SUP_FO","THETA")
+    inseremocle.chercheOperInsereFacteurSiRegle(jdc,"CALC_G","LISSAGE",((("DEGRE",),"existe"),))
+    movemocle.moveMotClefInOperToFact(jdc,"CALC_G","DEGRE","LISSAGE")
+
+    f=open(outfile,'w')
+    f.write(jdc.getSource())
+    f.close()
+
+def main():
+    parser = optparse.OptionParser(usage=usage)
+
+    parser.add_option('--infile', dest="infile", default='toto.comm',
+        help="Le fichier à traduire")
+    parser.add_option('--outfile', dest="outfile", default='tutu.comm',
+        help="Le fichier traduit")
+
+    options, args = parser.parse_args()
+    traduc(options.infile,options.outfile)
+
+if __name__ == '__main__':
+    main()
+
index 0898c8c716846b55408b789af79d483457306af5..6e304bc73d1118e0b8e216b75fe3fe6d35254636 100644 (file)
@@ -2,7 +2,7 @@
 
 import compiler
 import types
-from parseur  import Keyword, FactNode, lastparen, lastparen2
+from parseur  import Keyword, FactNode, lastparen, lastparen2,maskStringsAndComments
 from visiteur import KeywordFinder, visitor
 from utils    import indexToCoordinates
 
@@ -72,9 +72,13 @@ def parseKeywords(root):
     matchFinder=KeywordFinder()
 
     for c in root.childNodes:
-        ast=compiler.parse(c.src)
+        maskedsrc=maskStringsAndComments(c.src)
+        #on supprime seulement les blancs du debut pour pouvoir compiler
+        #meme si la commande est sur plusieurs lignes seul le debut compte
+        ast=compiler.parse(c.src.lstrip())
         #print ast
-        matchFinder.reset(c.src)
+        #Ne pas supprimer les blancs du debut pour avoir les bons numeros de colonne
+        matchFinder.reset(maskedsrc)
         visitor.walk(ast, matchFinder)
         #print matchFinder.matches
         if len(matchFinder.matches) > 1: