X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Traducteur%2Fmocles.py;h=809a3fe9e1b2b88ab79be3120bdd692a3f0d1b19;hb=9f4ff7ed9afd87c96e11d61e442e39e5511f60d1;hp=f9429ad8157ee0ec5450f66f34f5f54927fd8138;hpb=48ed5b9a4653e74d533ebad34a8a95a1f82b4934;p=tools%2Feficas.git diff --git a/Traducteur/mocles.py b/Traducteur/mocles.py index f9429ad8..809a3fe9 100644 --- a/Traducteur/mocles.py +++ b/Traducteur/mocles.py @@ -1,14 +1,34 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2007-2013 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 +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# import compiler import types -from parseur import Keyword,FactNode,lastparen,lastparen2 -from visiteur import KeywordFinder,visitor -from utils import indexToCoordinates +from Traducteur.parseur import Keyword, FactNode, lastparen, lastparen2,maskStringsAndComments +from Traducteur.visiteur import KeywordFinder, visitor +from Traducteur.utils import indexToCoordinates, lineToDict, DictToLine debug=0 +#------------------------ def parseFact(match,c,kw): +#------------------------ submatch=match[2] lastpar=match[0]+lastparen(c.src[match[0]:]) if type(submatch[0][0]) ==types.IntType: @@ -61,21 +81,32 @@ def parseFact(match,c,kw): no.addChild(Keyword(e[1],lineno,colno,endline,endcol)) +#----------------------- def parseKeywords(root): - """A partir d'un arbre contenant des commandes, ajoute les noeuds fils correspondant aux mocles - de la commande +#----------------------- + """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: - 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: - #plusieurs mocles trouvés : un mocle commence au début du keyword (matchFinder.matches[i][0]) - # et finit juste avant le keyword suivant (matchFinder.matches[i+1][0]]) + # plusieurs mocles trouvés : + # un mocle commence au début 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]] x,y=indexToCoordinates(c.src,matchFinder.matches[i][0]) @@ -90,8 +121,12 @@ def parseKeywords(root): submatch= matchFinder.matches[i][2] if submatch: parseFact(matchFinder.matches[i],c,kw) - #dernier mocle : il commence au debut du dernier keyword (matchFinder.matches[i+1][0]) et - #finit avant la parenthese fermante de la commande (c.lastparen) + + # dernier mocle : + # il commence au debut du dernier keyword + # (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] x,y=indexToCoordinates(c.src,matchFinder.matches[i+1][0]) lineno=y+c.lineno @@ -107,8 +142,10 @@ def parseKeywords(root): parseFact(matchFinder.matches[i+1],c,kw) elif len(matchFinder.matches) == 1: - #un seul mocle trouve : il commence au début du keyword (matchFinder.matches[0][0]) et - #finit juste avant la parenthese fermante de la commande (c.lastparen) + #un seul mocle trouve : + # il commence au début 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] x,y=indexToCoordinates(c.src,matchFinder.matches[0][0]) lineno=y+c.lineno