1 # -*- coding: utf-8 -*-
4 from compiler import visitor
7 """Visiteur de base : gestion des matches """
11 self.words = re.split("(\w+)", line) # every other one is a non word
14 for word in self.words:
15 self.positions.append(i)
19 def popWordsUpTo(self, word):
21 return # won't be able to find this
22 posInWords = self.words.index(word)
23 idx = self.positions[posInWords]
24 self.words = self.words[posInWords+1:]
25 self.positions = self.positions[posInWords+1:]
27 def appendMatch(self,name):
28 idx = self.getNextIndexOfWord(name)
29 self._matches.append((idx, name))
31 def getNextIndexOfWord(self,name):
32 return self.positions[self.words.index(name)]
35 class KeywordFinder(MatchFinder):
36 """Visiteur pour les keywords d'une commande """
38 def visitKeyword(self,node):
39 idx = self.getNextIndexOfWord(node.name)
40 self.popWordsUpTo(node.name)
41 prevmatches=self._matches
43 for child in node.getChildNodes():
45 prevmatches.append((idx, node.name,self._matches))
46 self._matches=prevmatches
47 #on ne garde que les matches du niveau Keyword le plus haut
48 self.matches=self._matches
50 def visitTuple(self,node):
52 for child in node.getChildNodes():
56 # Pour eviter les tuples et listes ordinaires,
57 # on ne garde que les visites fructueuses
58 matchlist.append(self._matches)
59 self._matches=matchlist
63 def visitName(self,node):
64 self.popWordsUpTo(node.name)
66 def visitAssName(self,node):
67 self.popWordsUpTo(node.name)