From: Christian Caremoli <> Date: Mon, 11 Sep 2006 06:36:44 +0000 (+0000) Subject: CCAR: correction de 2 bugs du parseur (masquage des commentaires X-Git-Tag: CC_param_poursuite~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=051872b503158f57d2e2f9958ca0cc76bd595f5d;p=tools%2Feficas.git CCAR: correction de 2 bugs du parseur (masquage des commentaires 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 --- diff --git a/Traducteur/jdcparser.py b/Traducteur/jdcparser.py index e1a201fe..7df70bdb 100644 --- a/Traducteur/jdcparser.py +++ b/Traducteur/jdcparser.py @@ -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() + diff --git a/Traducteur/mocles.py b/Traducteur/mocles.py index 0898c8c7..6e304bc7 100644 --- a/Traducteur/mocles.py +++ b/Traducteur/mocles.py @@ -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: