1 # -*- coding: utf-8 -*-
4 from compiler import visitor
7 """Visiteur de base : gestion des matches """
10 self.words = re.split("(\w+)", line) # every other one is a non word
13 for word in self.words:
14 self.positions.append(i)
18 def popWordsUpTo(self, word):
20 return # won't be able to find this
21 posInWords = self.words.index(word)
22 idx = self.positions[posInWords]
23 self.words = self.words[posInWords+1:]
24 self.positions = self.positions[posInWords+1:]
26 def appendMatch(self,name):
27 idx = self.getNextIndexOfWord(name)
28 self.matches.append((idx, name))
30 def getNextIndexOfWord(self,name):
31 return self.positions[self.words.index(name)]
34 class KeywordFinder(MatchFinder):
35 """Visiteur pour les keywords d'une commande """
37 def visitKeyword(self,node):
38 idx = self.getNextIndexOfWord(node.name)
39 #self.appendMatch(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
48 def visitTuple(self,node):
50 for child in node.getChildNodes():
54 #Pour eviter les tuples et listes ordinaires, on ne garde que les visites fructueuses
55 matchlist.append(self.matches)
56 self.matches=matchlist
60 def visitName(self,node):
61 self.popWordsUpTo(node.name)
62 def visitAssName(self,node):
63 self.popWordsUpTo(node.name)