1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from compiler import visitor
25 """Visiteur de base : gestion des matches """
29 self.words = re.split("(\w+)", line) # every other one is a non word
32 for word in self.words:
33 self.positions.append(i)
37 def popWordsUpTo(self, word):
39 return # won't be able to find this
40 posInWords = self.words.index(word)
41 idx = self.positions[posInWords]
42 self.words = self.words[posInWords+1:]
43 self.positions = self.positions[posInWords+1:]
45 def appendMatch(self,name):
46 idx = self.getNextIndexOfWord(name)
47 self._matches.append((idx, name))
49 def getNextIndexOfWord(self,name):
50 return self.positions[self.words.index(name)]
53 class KeywordFinder(MatchFinder):
54 """Visiteur pour les keywords d'une commande """
56 def visitKeyword(self,node):
57 idx = self.getNextIndexOfWord(node.name)
58 self.popWordsUpTo(node.name)
59 prevmatches=self._matches
61 for child in node.getChildNodes():
63 prevmatches.append((idx, node.name,self._matches))
64 self._matches=prevmatches
65 #on ne garde que les matches du niveau Keyword le plus haut
66 self.matches=self._matches
68 def visitTuple(self,node):
70 for child in node.getChildNodes():
74 # Pour eviter les tuples et listes ordinaires,
75 # on ne garde que les visites fructueuses
76 matchlist.append(self._matches)
77 self._matches=matchlist
81 def visitName(self,node):
82 self.popWordsUpTo(node.name)
84 def visitAssName(self,node):
85 self.popWordsUpTo(node.name)