# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
from Traducteur import parseur
from Traducteur.mocles import parseKeywords
-import sets
-jdcSet=sets.Set()
+jdcSet=set()
class JDCTrad:
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
def initialise(flog=None):
if flog == None :
- MonHome=os.path.expanduser("~")
+ MonHome=os.path.join(os.path.expanduser("~")
MaDir=MonHome+"/Eficas_install"
try :
os.mkdir(MaDir)
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-import compiler
+#import compiler
+import ast
import types
from Traducteur.parseur import Keyword, FactNode, lastParen, lastParen2,maskStringsAndComments
-from Traducteur.visiteur import KeywordFinder, visitor
+from Traducteur.visiteur import KeywordFinder, NodeVisitor
from Traducteur.utils import indexToCoordinates, lineToDict, dictToLine
debug=0
#------------------------
submatch=match[2]
lastpar=match[0]+lastParen(c.src[match[0]:])
- if type(submatch[0][0]) ==types.IntType:
+ #if type(submatch[0][0]) ==types.IntType:
+ if isinstance(submatch[0][0], int) :
#mot cle facteur isole
no=FactNode()
kw.addChild(no)
"""A partir d'un arbre contenant des commandes, ajoute les noeuds
fils correspondant aux mocles de la commande
"""
- #print "parseKeywords"
#traceback.print_stack(limit=5)
matchFinder=KeywordFinder()
for c in root.childNodes:
+ if debug : print ('parse -------------- ', c.name)
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())
+ #ast=compiler.parse(c.src.lstrip())
#print ast
+ monAst=ast.parse(c.src.lstrip())
+ if debug : print (ast.dump(monAst))
#Ne pas supprimer les blancs du debut pour avoir les bons numeros de colonne
matchFinder.reset(maskedsrc)
- visitor.walk(ast, matchFinder)
- #print matchFinder.matches
+ matchFinder.visit(monAst)
+ if debug : print ("matchFinder.matches", matchFinder.matches)
if len(matchFinder.matches) > 1:
# plusieurs mocles trouves :
# un mocle commence au debut du keyword (matchFinder.matches[i][0])
# et finit juste avant le keyword suivant
# (matchFinder.matches[i+1][0]])
for i in range(len(matchFinder.matches)-1):
- if debug:print "texte:",c.src[matchFinder.matches[i][0]:matchFinder.matches[i+1][0]]
+ if debug:print ("texte:",c.src[matchFinder.matches[i][0]:matchFinder.matches[i+1][0]])
x,y=indexToCoordinates(c.src,matchFinder.matches[i][0])
lineno=y+c.lineno
colno=x
x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0])
endline=y+c.lineno
endcol=x
- if debug:print matchFinder.matches[i][0],matchFinder.matches[i][1],lineno,colno,endline,endcol
+ if debug:print (matchFinder.matches[i][0],matchFinder.matches[i][1],lineno,colno,endline,endcol)
kw=Keyword(matchFinder.matches[i][1],lineno,colno,endline,endcol)
c.addChild(kw)
submatch= matchFinder.matches[i][2]
# (matchFinder.matches[i+1][0]) et
# finit avant la parenthese fermante de la commande (c.lastParen)
- if debug:print "texte:",c.src[matchFinder.matches[i+1][0]:c.lastParen]
+ if debug:print ("texte:",c.src[matchFinder.matches[i+1][0]:c.lastParen])
x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0])
lineno=y+c.lineno
colno=x
x,y=indexToCoordinates(c.src,c.lastParen)
endline=y+c.lineno
endcol=x
- if debug:print matchFinder.matches[i+1][0],matchFinder.matches[i+1][1],lineno,colno,endline,endcol
+ if debug:print (matchFinder.matches[i+1][0],matchFinder.matches[i+1][1],lineno,colno,endline,endcol)
kw=Keyword(matchFinder.matches[i+1][1],lineno,colno,endline,endcol)
c.addChild(kw)
submatch= matchFinder.matches[i+1][2]
# il commence au debut du keyword (matchFinder.matches[0][0]) et
# finit juste avant la parenthese fermante de la
# commande (c.lastParen)
- if debug:print "texte:",c.src[matchFinder.matches[0][0]:c.lastParen]
+ if debug:print ("texte:",c.src[matchFinder.matches[0][0]:c.lastParen])
x,y=indexToCoordinates(c.src,matchFinder.matches[0][0])
lineno=y+c.lineno
colno=x
x,y=indexToCoordinates(c.src,c.lastParen)
endline=y+c.lineno
endcol=x
- if debug:print matchFinder.matches[0][0],matchFinder.matches[0][1],lineno,colno,endline,endcol
+ if debug:print ( matchFinder.matches[0][0],matchFinder.matches[0][1],lineno,colno,endline,endcol)
kw=Keyword(matchFinder.matches[0][1],lineno,colno,endline,endcol)
c.addChild(kw)
submatch= matchFinder.matches[0][2]
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
if n.name != mocle:continue
# test boolchange_c :il faut le faire une seule fois par commande sinon duplication du mot clé
if boolchange_c != 0 :continue
- if debug : print "Changement de place :", n.name, n.lineno, n.colno
+ if debug : print ("Changement de place :", n.name, n.lineno, n.colno)
MonTexte=n.getText(jdc);
boolChange=1
boolchange_c=1
def moveMotCleFromFactToFact(jdc,oper,factsource,mocle,factcible):
#----------------------------------------------------------------------------
if oper not in jdcSet : return
- if debug : print "moveMotCleFromFactToFact pour " ,oper,factsource,mocle,factcible
+ if debug : print ("moveMotCleFromFactToFact pour " ,oper,factsource,mocle,factcible)
boolChange=0
commands= jdc.root.childNodes[:]
commands.reverse()
cible=mc
break
if cible==None :
- if debug : print "Pas de changement pour ", oper, " ", factsource, " ",mocle, "cible non trouvée"
+ if debug : print ("Pas de changement pour ", oper, " ", factsource, " ",mocle, "cible non trouvée")
continue
for mc in c.childNodes:
source=mc
break
if source==None :
- if debug : print "Pas de changement pour ", oper, " ", factsource, " ",mocle, "source non trouvée"
+ if debug : print ("Pas de changement pour ", oper, " ", factsource, " ",mocle, "source non trouvée")
continue
- if debug : print "Changement pour ", oper, " ", factsource, " ",mocle, "cible et source trouvées"
+ if debug : print ("Changement pour ", oper, " ", factsource, " ",mocle, "cible et source trouvées")
l=source.childNodes[:]
for ll in l:
for n in ll.childNodes:
# Attention le cas type est THETA_OLD dans calc_G
if oper not in jdcSet : return
- if debug : print "movemocleinoper pour " ,oper,mocle,factcible
+ if debug : print ( "movemocleinoper pour " ,oper,mocle,factcible)
boolChange=9
commands= jdc.root.childNodes[:]
commands.reverse()
cible=mc
break
if cible==None :
- if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
+ if debug : print ("Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée")
continue
source=None
source=mc
break
if source==None :
- if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
+ if debug : print ("Pas de changement pour ", oper, " ", mocle, " source non trouvée")
continue
MonTexte=source.getText(jdc);
boolChange=1
#------------------------------------------------------
if oper not in jdcSet : return
- if debug : print "movemocleinoper pour " ,oper,mocle,factcible
+ if debug : print ("movemocleinoper pour " ,oper,mocle,factcible)
boolChange=9
commands= jdc.root.childNodes[:]
commands.reverse()
cible=mc
break
if cible==None :
- if debug : print "Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée"
+ if debug : print ("Pas de changement pour ", oper, " ", factcible, " ", "cible non trouvée")
continue
source=None
source=mc
break
if source==None :
- if debug : print "Pas de changement pour ", oper, " ", mocle, " source non trouvée"
+ if debug : print ("Pas de changement pour ", oper, " ", mocle, " source non trouvée")
continue
MonTexte=source.getText(jdc);
boolChange=1
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
import re,string
-import compiler
debug=0
escapedQuotesRE = re.compile(r"(\\\\|\\\"|\\\')")
stringsAndCommentsRE = \
re.compile("(\"\"\".*?\"\"\"|'''.*?'''|\"[^\"]*\"|\'[^\']*\'|#.*?\n)", re.DOTALL)
-allchars = string.maketrans("", "")
-allcharsExceptNewline = allchars[: allchars.index('\n')]+allchars[allchars.index('\n')+1:]
-allcharsExceptNewlineTranstable = string.maketrans(allcharsExceptNewline, '*'*len(allcharsExceptNewline))
+
+import six
+if six.PY2 :
+ allchars = string.maketrans(u"", "")
+ allcharsExceptNewline = allchars[: allchars.index('\n')]+allchars[allchars.index('\n')+1:]
+ allcharsExceptNewlineTranstable = string.maketrans(allcharsExceptNewline, '*'*len(allcharsExceptNewline))
+else :
+ allchars=bytes.maketrans(b"",b"")
+ allcharsExceptNewline = allchars[: allchars.index(b'\n')]+allchars[allchars.index(b'\n')+1:]
+ allcharsExceptNewlineTranstable = bytes.maketrans(allcharsExceptNewline, b'*'*len(allcharsExceptNewline))
+
#------------------------------
def maskStringsAndComments(src):
src = escapedQuotesRE.sub("**", src)
allstrings = stringsAndCommentsRE.split(src)
# every odd element is a string or comment
- for i in xrange(1, len(allstrings), 2):
+ for i in range(1, len(allstrings), 2):
if allstrings[i].startswith("'''")or allstrings[i].startswith('"""'):
allstrings[i] = allstrings[i][:3]+ \
allstrings[i][3:-3].translate(allcharsExceptNewlineTranstable)+ \
def printNode(node):
#-------------------
if hasattr(node,'name'):
- print node.name
+ print (node.name)
else:
- print "pas de nom pour:",node
+ print ("pas de nom pour:",node)
for c in node.childNodes:
printNode(c)
lineno=0
for line in maskedLines:
lineno=lineno+1
- if debug:print "line",lineno,":",line
+ if debug:print ("line",lineno,":",line)
m=pattern_proc.match(line)
if m and (m.group(1) in atraiter):
- if debug:print m.start(3),m.end(3),m.start(4)
+ if debug:print (m.start(3),m.end(3),m.start(4))
root.addChild(Command(m.group(1),lineno,m.start(1),m.end(3)))
else:
m=pattern_oper.match(line)
lineno=c.lineno
colno=c.colno # debut de la commande
while linenum < lineno:
- line=iterlines.next()
+ line=iterlines.__next__()
linenum=linenum+1
if linenum != lineno:
- if debug:print "line %s:"%linenum, line
+ if debug:print ("line %s:"%linenum, line)
tmp = []
hangingBraces = list(emptyHangingBraces)
hangingComments = 0
c.endline=linenum
decal=len(line)-line.rindex(')')
c.lastParen=len(src)-decal
- if debug:print "logical line %s %s:" % (c.lineno,c.endline),src
+ if debug:print ("logical line %s %s:" % (c.lineno,c.endline),src)
break
- line=iterlines.next()
+ line=iterlines.__next__()
linenum=linenum+1
return root
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
class existeMCFParmi :
#---------------------
"""
- Existance du mot-clé facteur parmi la liste
+ Existence du mot-clé facteur parmi la liste
"""
def __init__(self, list_arg):
self.listeMCF = list_arg
class nexistepasMCFParmi(existeMCFParmi) :
#---------------------
"""
- Existance du mot-clé facteur parmi la liste
+ Existence du mot-clé facteur parmi la liste
"""
def __init__(self, list_arg):
self.listeMCF = list_arg
class existeMCsousMCF :
#----------------------
"""
- Existance du mot-clé simple sous le mot-clé facteur
+ Existence du mot-clé simple sous le mot-clé facteur
"""
def __init__(self, list_arg):
self.liste = list_arg
class existeMCsousMCFcourant :
#----------------------
"""
- Existance du mot-clé simple sous le mot-clé facteur courant
+ Existence du mot-clé simple sous le mot-clé facteur courant
"""
def __init__(self, list_arg):
self.liste = list_arg
class existe :
#--------------
"""
- Existance du mot-clé simple
+ Existence du mot-clé simple
"""
def __init__(self, list_arg):
self.genea = list_arg
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
#---------------------------------
def removeMC(jdc,c,mc):
#---------------------------------
- if debug : print "Suppression de:",c.name,mc.name,mc.lineno,mc.colno,mc.endline,mc.endcol
+ if debug : print ("Suppression de:",c.name,mc.name,mc.lineno,mc.colno,mc.endline,mc.endcol)
logging.info("Suppression de %s dans %s ligne %d",mc.name,c.name,mc.lineno)
if mc.endline > mc.lineno:
- if debug:print "mocle sur plusieurs lignes--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:]
+ if debug: print ("mocle sur plusieurs lignes--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:])
jdc.getLines()[mc.lineno-1]=jdc.getLines()[mc.lineno-1][:mc.colno]
jdc.getLines()[mc.endline-1]=jdc.getLines()[mc.endline-1][mc.endcol:]
#attention : supprimer les lignes a la fin
jdc.getLines()[mc.lineno:mc.endline-1]=[]
else:
- if debug:print "mocle sur une ligne--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:mc.endcol]
+ if debug: print( "mocle sur une ligne--%s--" % jdc.getLines()[mc.lineno-1][mc.colno:mc.endcol])
s=jdc.getLines()[mc.lineno-1]
jdc.getLines()[mc.lineno-1]=s[:mc.colno]+s[mc.endcol:]
fusionne(jdc,mc.lineno-1)
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
if mc.name != mocle:continue
if ensemble.verif(c) == 0 : continue
boolChange=1
- if debug:print "Renommage de:",c.name,mc.name,mc.lineno,mc.colno
+ if debug: print ("Renommage de:",c.name,mc.name,mc.lineno,mc.colno)
if erreur :
ecritErreur((command,mocle),c.lineno)
else :
boolChange=0
for c in jdc.root.childNodes:
if c.name != command:continue
- if debug:print "Renommage de:",c.name,c.lineno,c.colno
+ if debug: print ("Renommage de:",c.name,c.lineno,c.colno)
logging.info("Renommage de: %s ligne %d en %s",c.name,c.lineno,new_name)
boolChange=1
s=jdc.getLines()[c.lineno-1]
if c.name != command:continue
if ensemble.verif(c) == 0 : continue
boolChange=1
- if debug:print "Renommage de:",c.name,new_name ,c.lineno,c.colno
+ if debug: print ("Renommage de:",c.name,new_name ,c.lineno,c.colno)
logging.info("Renommage de: %s ligne %d en %s",c.name,c.lineno,new_name)
s=jdc.getLines()[c.lineno-1]
jdc.getLines()[c.lineno-1]=s[:c.colno]+new_name+s[c.colno+len(command):]
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2021 EDF R&D
+# Copyright (C) 2007-2017 EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
#
import re
-from compiler import visitor
+from ast import NodeVisitor
+debug=0
-class MatchFinder:
+class MatchFinder (NodeVisitor):
"""Visiteur de base : gestion des matches """
def reset(self,line):
self.matches=[]
self.positions.append(i)
i+=len(word)
self.index = 0
+ if debug : print ('fin reset', self.words)
def popWordsUpTo(self, word):
if word == "*":
class KeywordFinder(MatchFinder):
"""Visiteur pour les keywords d'une commande """
- def visitKeyword(self,node):
- idx = self.getNextIndexOfWord(node.name)
- self.popWordsUpTo(node.name)
+ def visit_keyword(self,node):
+ if debug : print (' visit_keyword', node.arg)
+ idx = self.getNextIndexOfWord(node.arg)
+ self.popWordsUpTo(node.arg)
prevmatches=self._matches
self._matches = []
- for child in node.getChildNodes():
- self.visit(child)
- prevmatches.append((idx, node.name,self._matches))
+ #for child in node.getChildNodes():
+ # self.visit(child)
+ self.generic_visit(node)
+ prevmatches.append((idx, node.arg,self._matches))
self._matches=prevmatches
#on ne garde que les matches du niveau Keyword le plus haut
self.matches=self._matches
- def visitTuple(self,node):
+ def visit_Tuple(self,node):
matchlist=[]
+ # Pour eviter les tuples et listes ordinaires,
+ if not hasattr(node,'getChildNodes') : return
+ print ('*********************************************************************')
+ print ("_____________ visit_Tuple", node)
for child in node.getChildNodes():
self._matches = []
self.visit(child)
# on ne garde que les visites fructueuses
matchlist.append(self._matches)
self._matches=matchlist
+ #self.generic_visit(node)
- visitList=visitTuple
+ visit_List=visit_Tuple
- def visitName(self,node):
- self.popWordsUpTo(node.name)
+ def visit_Name(self,node):
+ if debug : print ('visit_Name', node.id)
+ self.popWordsUpTo(node.id)
+ self.generic_visit(node)
- def visitAssName(self,node):
- self.popWordsUpTo(node.name)
+ def visit_AssName(self,node):
+ if debug : print ('visit_AssName', node.id)
+ self.popWordsUpTo(node.id)
+ self.generic_visit(node)