WPS的VBA在这里下载:http://bbs.wps.cn/forum.php?mod=viewthread&tid=22347925
语法高亮是参考Word的,这篇文章:http://blog.csdn.net/colin719/article/details/1555526
WPS的VBA代码:
'script to high light code In document Private Function isKeyword(w) As Boolean Dim keys As New Collection With keys .Add "CASE": .Add "COMPONENT": .Add "CONFIGURATION": .Add "CONSTANT": .Add "DISCONNECT": .Add "DOWNTO": .Add "ELSE": .Add "ELSIF": .Add "END": .Add "ENTITY": .Add "EXIT": .Add "FILE": .Add "FOR": .Add "FUNCTION": .Add "GENERATE": .Add "GENERIC": .Add "GROUP": .Add "GUARDED": .Add "IF": .Add "IMPURE": .Add "IN": .Add "INERTIAL": .Add "INOUT": .Add "IS": .Add "LABEL": .Add "LIBRARY": .Add "LINKAGE": .Add "LITERAL": .Add "LOOP": .Add "MAP": .Add "MOD": .Add "NAND": .Add "NEW": .Add "NEXT": .Add "NOR": .Add "NOT": .Add "NULL": .Add "OF": .Add "ON": .Add "OPEN": .Add "OR": .Add "OTHERS": .Add "OUT": .Add "PACKAGE": .Add "PORT": .Add "POSTPONED": .Add "PROCEDURE": .Add "PROCESS": .Add "PURE": .Add "RANGE": .Add "RECORD": .Add "REGISTER": .Add "REJECT": .Add "REM": .Add "REPORT": .Add "RETURN": .Add "ROL": .Add "ROR": .Add "SELECT": .Add "SEVERITY": .Add "SIGNAL": .Add "SHARED": .Add "SLA": .Add "SLL": .Add "SRA": .Add "SRL": .Add "SUBTYPE": .Add "THEN": .Add "TO": .Add "TRANSPORT": .Add "TYPE": .Add "UNAFFECTED": .Add "UNITS": .Add "UNTIL": .Add "USE": .Add "VARIABLE": .Add "WAIT": .Add "WHEN": .Add "WHILE": .Add "WITH": .Add "XNOR": .Add "XOR": .Add "AGGREGATE": .Add "ALLOCATOR": .Add "BIT": .Add "BIT_VECTOR": .Add "BOOLEAN": .Add "CHARACTER": .Add "COMPOSITE": .Add "CONCATENATION": .Add "DELAY": .Add "DRIVER": .Add "ENUMERATION": .Add "EVENT": .Add "EXPRESSION": .Add "IDENTIFIER": .Add "INTEGER": .Add "NAME": .Add "OPERATORS": .Add "PHYSICAL": .Add "RESOLUTION": .Add "RESUME": .Add "SCALAR": .Add "SLICE": .Add "STANDARD": .Add "STABLE": .Add "STD_LOGIC": .Add "STD_LOGIC_1164": .Add "STD_LOGIC_VECTOR": .Add "STRING": .Add "SUSPEND": .Add "TESTBENCH": .Add "VECTOR": .Add "VITAL": .Add "WAVEFORM": .Add "AND": End With w = UCase(w) isKeyword = isSpecial(w, keys) End Function Private Function isSpecial(ByVal w As String, ByRef col As Collection) As Boolean For Each i In col If w = i Then isSpecial = True Exit Function End If Next isspeical = False End Function Sub SyntaxHighlightVHDL() Dim wordCount As Integer Dim d As Integer d = 0 wordCount = Selection.End - Selection.Start 'MsgBox wordCount Selection.StartOf wpsWord While d < wordCount t = Selection.MoveRight(wpsWord, 1, wpsExtend) w = Selection.Text d = d + Selection.End - Selection.Start ' MsgBox d If isKeyword(Trim(w)) = True Then Selection.Font.Bold = True End If 'move the start of selection to next word Selection.MoveStart wpsWord Wend Selection.MoveLeft wpsCharacter, wordCount, wpsExtend MsgBox "ok" End Sub
其中,提取关键词的Python代码:
import sys,string print sys.argv[1] fp1=file(sys.argv[1],"r") fp2=file("d:/out.txt","w") while 1: for i in range(0,10): s=fp1.readline() s=string.strip(s) print s if s=="":break s='''.Add "%s":'''%(s) fp2.write(s) if s=="":break fp2.write(" ") fp1.close() fp2.close() print "ok" raw_input("")
VHDL关键词:
CASE
COMPONENT
CONFIGURATION
CONSTANT
DISCONNECT
DOWNTO
ELSE
ELSIF
END
ENTITY
EXIT
FILE
FOR
FUNCTION
GENERATE
GENERIC
GROUP
GUARDED
IF
IMPURE
IN
INERTIAL
INOUT
IS
LABEL
LIBRARY
LINKAGE
LITERAL
LOOP
MAP
MOD
NAND
NEW
NEXT
NOR
NOT
NULL
OF
ON
OPEN
OR
OTHERS
OUT
PACKAGE
PORT
POSTPONED
PROCEDURE
PROCESS
PURE
RANGE
RECORD
REGISTER
REJECT
REM
REPORT
RETURN
ROL
ROR
SELECT
SEVERITY
SIGNAL
SHARED
SLA
SLL
SRA
SRL
SUBTYPE
THEN
TO
TRANSPORT
TYPE
UNAFFECTED
UNITS
UNTIL
USE
VARIABLE
WAIT
WHEN
WHILE
WITH
XNOR
XOR
AGGREGATE
ALLOCATOR
BIT
BIT_VECTOR
BOOLEAN
CHARACTER
COMPOSITE
CONCATENATION
DELAY
DRIVER
ENUMERATION
EVENT
EXPRESSION
IDENTIFIER
INTEGER
NAME
OPERATORS
PHYSICAL
RESOLUTION
RESUME
SCALAR
SLICE
STANDARD
STABLE
STD_LOGIC
STD_LOGIC_1164
STD_LOGIC_VECTOR
STRING
SUSPEND
TESTBENCH
VECTOR
VITAL
WAVEFORM