/usr/share/pyshared/Traducteur/visiteur.py is in eficas 6.4.0-1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | # -*- coding: utf-8 -*-
import re
from compiler import visitor
class MatchFinder:
"""Visiteur de base : gestion des matches """
def reset(self,line):
self.matches=[]
self._matches = []
self.words = re.split("(\w+)", line) # every other one is a non word
self.positions = []
i = 0
for word in self.words:
self.positions.append(i)
i+=len(word)
self.index = 0
def popWordsUpTo(self, word):
if word == "*":
return # won't be able to find this
posInWords = self.words.index(word)
idx = self.positions[posInWords]
self.words = self.words[posInWords+1:]
self.positions = self.positions[posInWords+1:]
def appendMatch(self,name):
idx = self.getNextIndexOfWord(name)
self._matches.append((idx, name))
def getNextIndexOfWord(self,name):
return self.positions[self.words.index(name)]
class KeywordFinder(MatchFinder):
"""Visiteur pour les keywords d'une commande """
def visitKeyword(self,node):
idx = self.getNextIndexOfWord(node.name)
self.popWordsUpTo(node.name)
prevmatches=self._matches
self._matches = []
for child in node.getChildNodes():
self.visit(child)
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.visit(child)
if self._matches:
# Pour eviter les tuples et listes ordinaires,
# on ne garde que les visites fructueuses
matchlist.append(self._matches)
self._matches=matchlist
visitList=visitTuple
def visitName(self,node):
self.popWordsUpTo(node.name)
def visitAssName(self,node):
self.popWordsUpTo(node.name)
|