1 # -*- coding: utf-8 -*-
3 from parseur import FactNode
8 #-----------------------------------
9 def inseremotcle(jdc,recepteur,texte):
10 #-----------------------------------
11 # appelle la methode selon la classe
14 if recepteur.__class__.__name__ == "Command" :
15 if debug : print " Ajout de ", texte, "dans la commande : " ,recepteur.name
16 inseremotcleincommand(jdc,recepteur,texte)
20 #--------------------------------------------
21 def inseremotcleincommand(jdc,command,texte):
22 #---------------------------------------------
23 # insere le texte comme 1er mot cle
25 if debug : print "inseremotcle ", texte , " dans ", command.name
26 numcol=chercheDebut1mot(jdc,command)
28 jdc.splitLine(command.lineno,numcol)
29 debut=chercheAlignement(jdc,command)
30 texte=debut+texte+"\n"
31 jdc.addLine(texte,command.lineno)
32 if numcol > 0 : # Les mots clefs etaient sur la même ligne
33 jdc.joinLineandNext(command.lineno)
35 #---------------------------------------------
36 def inseremotcleinfacteur(jdc,facteur,texte):
37 #-------------------------------------------------
38 if debug : print "inseremotcle ", texte , " dans ", facteur.name
39 ancien=jdc.getLine(facteur.lineno )
40 # On va chercher la dernier ) pour ajouter avant
41 # on va verifier s il il y a un , avant
42 ligne,col,boolvirgule=chercheDerniereParenthese(jdc,facteur)
44 jdc.splitLine(ligne,col)
46 jdc.addLine(",\n",ligne)
47 jdc.joinLineandNext(ligne)
48 debut=ancien.find("_F") + 3
50 # enleve les blancs en debut de texte
52 while i < len(texte) :
53 if texte[i] != " " : break
55 texte=aligne+texte+"\n"
56 jdc.addLine(texte,ligne)
57 jdc.joinLineandNext(ligne+1)
59 #---------------------------------------
60 def chercheDerniereParenthese(jdc,facteur):
61 #---------------------------------------
62 ligne=facteur.endline-1
66 while ( trouveParent == 0) :
67 texte=jdc.getLine(ligne)
74 while ( indice > -1 and texte[indice] == " " ):
76 if texte[indice]=="," :
78 return (ligne,col,boolvirgule)
80 #-----------------------------------
81 def chercheDebut1mot(jdc,command):
82 #-----------------------------------
83 # Retourne le numero de colonne si le 1er mot clef est
84 # sur la meme ligne que le mot clef facteur
86 assert (command.childNodes != [])
88 node1=command.childNodes[0]
89 if hasattr(node1,"lineno"):
90 if node1.lineno == command.lineno :
93 debut=chercheDebutfacteur(jdc,command)
94 if debut == -1 and debug : print "attention!!! pb pour trouver le debut dans ", command
97 #-----------------------------------
98 def chercheDebutfacteur(jdc,facteur):
99 #-----------------------------------
101 ligne=jdc.getLines()[facteur.lineno]
102 debut=ligne.find("_F")
103 if debut > -1 : debut=debut + 3
108 #-----------------------------------
109 def chercheAlignement(jdc,command):
110 #-----------------------------------
111 # Retourne le nb de blanc
112 # pour aligner sur le 1er mot clef fils
113 assert (command.childNodes != [])
114 node1=command.childNodes[0]