X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=convert%2Fautre_parseur.py;h=0f35c27a3a8e92b94b9178e938b2bfb34176e5fb;hb=217a9ce2f303b098ad28d282bb0df2dfeeeed3c2;hp=850b0803faa97d89502b4c00d9cb22e276790b0e;hpb=48ed5b9a4653e74d533ebad34a8a95a1f82b4934;p=tools%2Feficas.git diff --git a/convert/autre_parseur.py b/convert/autre_parseur.py index 850b0803..0f35c27a 100644 --- a/convert/autre_parseur.py +++ b/convert/autre_parseur.py @@ -1,27 +1,39 @@ # -*- coding: utf-8 -*- -# CONFIGURATION MANAGEMENT OF EDF VERSION -# ====================================================================== -# COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG -# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY -# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY -# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR -# (AT YOUR OPTION) ANY LATER VERSION. +# Copyright (C) 2007-2013 EDF R&D # -# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT -# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF -# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU -# GENERAL PUBLIC LICENSE FOR MORE DETAILS. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. # -# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE -# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER, -# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# ====================================================================== -import sys,string,re,tokenize -import cStringIO - -class ENTITE_JDC : +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +from __future__ import absolute_import +from __future__ import print_function +try : + from future import standard_library + standard_library.install_aliases() +except : + pass +try : + from builtins import str +except : + pass +from builtins import object +import sys,re,tokenize +import io + + +class ENTITE_JDC(object) : def __init__(self): self.texte = '' @@ -37,34 +49,34 @@ class COMMENTAIRE(ENTITE_JDC): def __str__(self): """ - Retourne une chaîne de caractères représentant self - sous une forme interprétable par EFICAS + Retourne une chaine de caracteres representant self + sous une forme interpretable par EFICAS """ t=repr(self.texte) - return "COMMENTAIRE("+t+")\n" + return "COMMENTAIRE(u"+t+")\n" def append_text(self,texte): """ - Ajoute texte à self.texte en enlevant le # initial + Ajoute texte a self.texte en enlevant le # initial """ if texte[0] == '#': self.texte = self.texte+texte[1:] else: - # le dièse n'est pas sur le premier caractère - amont,aval = string.split(texte,'#',1) # on découpe suivant la première occurrence de # + # le diese n'est pas sur le premier caractere + amont,aval = texte.split('#',1) # on decoupe suivant la premiere occurrence de # self.texte = self.texte +amont + aval class AFFECTATION(ENTITE_JDC): def append_text(self,texte): """ - Ajoute texte à self.texte en enlevant tout retour chariot et tout point virgule + Ajoute texte a self.texte en enlevant tout retour chariot et tout point virgule """ self.texte = self.texte+texte def __str__(self): """ - Retourne une expression de l'affectation compréhensible par ACCAS + Retourne une expression de l'affectation comprehensible par ACCAS et exploitable par EFICAS """ #t=repr(self.texte) @@ -75,15 +87,15 @@ class COMMANDE_COMMENTARISEE(ENTITE_JDC): def append_text(self,texte): """ - Ajoute texte à self.texte en enlevant les doubles commentaires + Ajoute texte a self.texte en enlevant les doubles commentaires """ - texte = string.strip(texte) - texte = string.strip(texte[2:]) + texte = texte.strip() + texte = texte[2:].strip() self.texte = self.texte+(len(self.texte)>0)*'\n'+texte def __str__(self): """ - Retourne une expression de la commande commentarisée compréhensible par ACCAS + Retourne une expression de la commande commentarisee comprehensible par ACCAS et exploitable par EFICAS """ return "COMMANDE_COMM(texte="+repr(self.texte)+")\n" @@ -98,15 +110,15 @@ next['else'] = next['finally'] = next['def'] = next['class'] = 'end' next['end'] = () start = 'if', 'while', 'for', 'try', 'def', 'class' -class PARSEUR_PYTHON: +class PARSEUR_PYTHON(object): """ - Cette classe sert à créer un objet PARSEUR_PYTHON qui réalise l'analyse d'un texte - représentant un JDC Python en distinguant : + Cette classe sert a creer un objet PARSEUR_PYTHON qui realise l'analyse d'un texte + representant un JDC Python en distinguant : - les commentaires inter commandes - les affectations - les commandes """ - # au moins 1 caractère non blanc ou non tabulation + # au moins 1 caractere non blanc ou non tabulation #pattern_ligne_non_blanche = re.compile(r'^[\w\t]+') pattern_ligne_non_blanche = re.compile(r'[^ \t]+') kwprog = re.compile( @@ -123,7 +135,7 @@ class PARSEUR_PYTHON: def __init__(self,texte): # on verifie que le texte fourni se compile correctement compile(texte,"",'exec') - self.texte = cStringIO.StringIO(texte) + self.texte = io.StringIO(texte) self.line='' self.out="" self.lastcol = 0 @@ -189,7 +201,7 @@ class PARSEUR_PYTHON: try: fn = getattr(self, tokenize.tok_name[ttype]) except AttributeError: - print >>sys.stderr, "No match!", tokenize.tok_name[ttype], tstring + print( "No match!", tokenize.tok_name[ttype], tstring) return if ttype != tokenize.DEDENT and ttype != tokenize.INDENT and self.please_indent: @@ -240,7 +252,7 @@ class PARSEUR_PYTHON: def NL(self, tstring): if self.affectation: if self.paren_level == 0: - # affectation en cours mais complète + # affectation en cours mais complete self.out= self.out+ str(self.affectation_courante) self.affectation_courante=None self.please_indent=1 @@ -270,7 +282,7 @@ class PARSEUR_PYTHON: elif self.paren_level > 0: self.output(tstring) elif self.comment_flag and not self.pattern_ligne_non_blanche.search(before): - # il s'agit d'une commande commentarisée + # il s'agit d'une commande commentarisee if self.objet_courant == None: if not self.buffer:self.buffer_indent=self.indent_list[-1] self.objet_courant=COMMANDE_COMMENTARISEE() @@ -293,14 +305,14 @@ class PARSEUR_PYTHON: else: # On a un commentaire simple - new_line = string.split(self.line,'#')[0] + new_line = self.line.split('#')[0] if self.affectation: # affectation en cours, on ignore pass elif self.paren_level > 0: self.output(tstring) elif self.comment_flag and not self.pattern_ligne_non_blanche.search(new_line): - # commentaire précédé de blancs + # commentaire precede de blancs if self.objet_courant == None: if not self.buffer:self.buffer_indent=self.indent_list[-1] self.objet_courant=COMMENTAIRE() @@ -322,7 +334,7 @@ class PARSEUR_PYTHON: return def ERRORTOKEN(self, tstring): - print "ERRORTOKEN",tstring + print("ERRORTOKEN", tstring) def NAME(self, tstring): if self.buffer: @@ -462,7 +474,7 @@ class PARSEUR_PYTHON: if __name__ == "__main__" : import sys - import cStringIO + import io text=""" # # comment @@ -637,16 +649,6 @@ for k in range(1,5): DS1[k] = CREA_CHAMP( OPERATION='EXTR', TYPE_CHAM='NOEU_DEPL_R', RESULTAT= MODESTA1, NUME_ORDRE=k, NOM_CHAM = 'DEPL'); -if x==1: - print "coucou" -elif x==2: - print "coucou" -elif x==2: - print "coucou" -elif x==2: - print "coucou" -else: - print "coucou" # parse: +affectation ff=23 # parametre bidon @@ -730,7 +732,6 @@ def f(x):return x #comment def f(x): #comment - if a==1:print "coucou" for i in range(10): s=0 #com1 @@ -902,5 +903,5 @@ def POST_GOUJ_ops(self,TABLE): else: t=text txt = PARSEUR_PYTHON(t).get_texte() - print txt + print (txt) compile(txt,"",'exec')