Hi, I would like to post a begining of the script that rename signals in VHDL without replacing signal names of inferior entities in port mapping.
# script refactoring_VHDL.py# -*- coding: iso-8859-15 -*- # indispensable à cause des accents# Auteur : mm.tsuchi# je veux creer un exemple de refactoring dans les fichiers VHDL# cad remplacer le nom du signal partout dans le fichier , SAUF dans le mappage des entités subordonnées# ATTENTION ! : script en version ALPHA (pas de contrôle d'erreur)# A FAIRE:# test si le fichier courant est VHDL# --- FAIT : NE remplacer QUE les mots entiers # --- FAIT : remplacer si le nom NE se trouve PAS à gauche de "=>" (sans les guillemets) : ce qui correspond à un mappage de port lors d'instanciations.# NE PAS remplacer si c'est compris dans le nom d'une entité : mot-cles ENTITY ou GENERIC MAP ou PORT MAP#*** IMPORTS ***# from Npp import *# import re,stringimportre# import os, sys# notepad.messageBox('Hello world')# vérifie si le fichier est VHDLifnotepad.getCurrentLang()=="VHDL":# if 1==1:# First we'll start an undo action, then Ctrl-Z will undo the actions of the whole scripteditor.beginUndoAction()# **** demande a l'utilisateur le nom a renommertext_to_rename=notepad.prompt("Nom a renommer","Refactoring...",editor.getSelText())# affiche dans la consoleiftext_to_rename==None:console.write("rien a remplacer")# exitelse:console.write("text_to_rename : "+text_to_rename+"\n")# **** demande a l'utilisateur le nom a renommertext_renamed=notepad.prompt("Nouveau nom","Refactoring...",text_to_rename)console.write("text_renamed : "+text_renamed+"\n")# **** remplacement dans le fichier courant de text_to_rename par text_renamed# test : gauche => gauche, -- blabla# test : if gauche = '1' then# test gauche# test gauche# test gauches# test -- gauche# on recharche tous les textes qui ne contiennent pas de "=>" après le text_to_rename# ATTENTION : on utilise les regular expression de Python (pas de notepad++)pattern_to_replace=r"\b"+text_to_rename+r"\b( *[^=]*[^>]*)$"console.write("pattern_to_replace : "+pattern_to_replace+"\n")# on écrit la chaine de remplacementpattern_replaced=r""+text_renamed+r"\1"console.write("pattern_replaced : "+pattern_replaced+"\n")# on remplaceeditor.pyreplace(pattern_to_replace,pattern_replaced,0,re.IGNORECASE)editor.pyreplace(r"--(.*)\b"+text_to_rename+r"\b",r"--\1"+text_renamed,0,re.IGNORECASE)# remplacement dans commentaires# End the undo action, so Ctrl-Z will undo the above actionseditor.endUndoAction()
Be Aware that this script is a first exemple (alpha stage) : may be incomplete, no error control, no check of reserved words, no check of end of line…
Any amelioration will be wonderful.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I would like to post a begining of the script that rename signals in VHDL without replacing signal names of inferior entities in port mapping.
Be Aware that this script is a first exemple (alpha stage) : may be incomplete, no error control, no check of reserved words, no check of end of line…
Any amelioration will be wonderful.