]> SALOME platform Git repositories - tools/eficas.git/commitdiff
Salome HOME
CCAR: modification pour supprimer les tuples englobant les mots cles
authorChristian Caremoli <>
Wed, 11 Oct 2006 09:28:35 +0000 (09:28 +0000)
committerChristian Caremoli <>
Wed, 11 Oct 2006 09:28:35 +0000 (09:28 +0000)
mais pas ceux en dessous des mots cles

Traducteur/visiteur.py

index 004e512055bdfe04bb7baa7b11b5a60a0cf29989..1b3144e230a39d6a69f45803a8d2587fcb4756e9 100644 (file)
@@ -6,7 +6,8 @@ from compiler import visitor
 class MatchFinder:
     """Visiteur de base : gestion des matches """
     def reset(self,line):
-        self.matches = []
+        self.matches=[]
+        self._matches = []
         self.words = re.split("(\w+)", line) # every other one is a non word
         self.positions = []
         i = 0
@@ -25,7 +26,7 @@ class MatchFinder:
 
     def appendMatch(self,name):
         idx = self.getNextIndexOfWord(name)
-        self.matches.append((idx, name))
+        self._matches.append((idx, name))
 
     def getNextIndexOfWord(self,name):
         return self.positions[self.words.index(name)]
@@ -36,28 +37,26 @@ class KeywordFinder(MatchFinder):
 
     def visitKeyword(self,node):
         idx = self.getNextIndexOfWord(node.name)
-        #self.appendMatch(node.name)
         self.popWordsUpTo(node.name)
-        prevmatches=self.matches
-        self.matches = []
+        prevmatches=self._matches
+        self._matches = []
         for child in node.getChildNodes():
             self.visit(child)
-        prevmatches.append((idx, node.name,self.matches))
-        self.matches=prevmatches
+        prevmatches.append((idx, node.name,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):
         matchlist=[]
         for child in node.getChildNodes():
-            self.matches = []
+            self._matches = []
             self.visit(child)
-            if self.matches:
+            if self._matches:
                 # Pour eviter les tuples et listes ordinaires, 
                 # on ne garde que les visites fructueuses
-                matchlist.append(self.matches)
-        if len(matchlist) == 1:
-            self.matches=matchlist[0]
-        else:
-            self.matches=matchlist
+                matchlist.append(self._matches)
+        self._matches=matchlist
 
     visitList=visitTuple