~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/syntax/_verilog.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###############################################################################
 
2
# Name: verilog.py                                                            #
 
3
# Purpose: Configuration module for Verilog HDL language                      #
 
4
# Author: Cody Precord <cprecord@editra.org>                                  #
 
5
# Copyright: (c) 2008 Cody Precord <staff@editra.org>                         #
 
6
# License: wxWindows License                                                  #
 
7
###############################################################################
 
8
 
 
9
"""
 
10
FILE: verilog.py
 
11
AUTHOR: Cody Precord
 
12
@summary: Lexer configuration module for Verilog Hardware Description Language
 
13
          and System Verilog programming languages. Much help in creating this
 
14
          module from Tim Corcoran.
 
15
 
 
16
"""
 
17
 
 
18
__author__ = "Cody Precord <cprecord@editra.org>"
 
19
__svnid__ = "$Id: _verilog.py 68798 2011-08-20 17:17:05Z CJP $"
 
20
__revision__ = "$Revision: 68798 $"
 
21
 
 
22
#-----------------------------------------------------------------------------#
 
23
# Imports
 
24
import wx.stc as stc
 
25
 
 
26
# Local Imports
 
27
import synglob
 
28
import syndata
 
29
 
 
30
#-----------------------------------------------------------------------------#
 
31
#TODO: What to do with preprocessors?
 
32
#TODO: What to do with standard methods?
 
33
 
 
34
#---- Keyword Definitions ----#
 
35
 
 
36
#==============================================================================
 
37
# IEEE 1364-1995 Verilog
 
38
#==============================================================================
 
39
# IEEE 1364-1995 Verilog Preprocessors
 
40
V_1364_1995_PREPROCESSORS = (
 
41
    # 1364-1995 Section 14
 
42
    "`celldefine `default_nettype `define `else `endcelldefine `endif `ifdef "
 
43
    "`include `nounconnected_drive `resetall `timescale `unconnected_drive "
 
44
    "`undef "
 
45
    # 1364-1995 Annex G
 
46
    "`default_decay_time `default_trireg_strength `delay_mode_distributed "
 
47
    "`delay_mode_path `delay_mode_unit `delay_mode_zero "
 
48
    #1364-1995 Verilog Preprocessor Commercial Extensions
 
49
    "`accelerate `autoexpand_vectornets `disable_portfaults `enable_portfaults "
 
50
    "`endprotect `endprotected `expand_vectornets `noaccelerate "
 
51
    "`noexpand_vectornets `noremove_gatenames `noremove_netnames "
 
52
    "`nosuppress_faults `portcoerce `protect `protected "
 
53
    "`remove_gatenames `remove_netnames `suppress_faults "
 
54
)
 
55
 
 
56
# IEEE 1364-1995 Verilog Keywords (NOT USED: attribute endattribute signed unsigned)
 
57
V_1364_1995_KEYWORDS = (
 
58
    "always assign begin case casex casez deassign default defparam disable "
 
59
    "edge else end endcase endfunction endmodule endprimitive endspecify "
 
60
    "endtable endtask for force forever fork function if ifnone initial "
 
61
    "inout input join macromodule module negedge output parameter posedge "
 
62
    "primitive release repeat scalared specify specparam strength table task "
 
63
    "vectored wait while"
 
64
)
 
65
 
 
66
# IEEE 1364-1995 Verilog Types (NOT USED: xbuf)
 
67
V_1364_1995_TYPES = (
 
68
    "and buf bufif0 bufif1 cmos event highz0 highz1 integer large medium nand "
 
69
    "nmos nor not notif0 notif1 or pmos pull0 pull1 pulldown pullup rcmos real "
 
70
    "realtime reg rnmos rpmos rtran rtranif0 rtranif1 small strong0 strong1 "
 
71
    "supply0 supply1 time tran tranif0 tranif1 tri tri0 tri1 triand trior "
 
72
    "trireg wand weak0 weak1 wire wor xnor xor"
 
73
)
 
74
 
 
75
# IEEE 1364-1995 Verilog System Tasks and Functions
 
76
V_1364_1995_TASKS = (
 
77
    # 1364-1995 Section 14
 
78
    "$async$and$array $async$and$plane $async$nand$array $async$nand$plane "
 
79
    "$async$nor$array $async$nor$plane $async$or$array $async$or$plane "
 
80
    "$bitstoreal $display $displayb $displayh $displayo $dist_chi_square "
 
81
    "$dist_erlang $dist_exponential $dist_normal $dist_poisson $dist_t "
 
82
    "$dist_uniform $dumpall $dumpfile $dumpflush $dumplimit $dumpoff $dumpon "
 
83
    "$dumpvars $fclose $fdisplay $fdisplayb $fdisplayh $fdisplayo $finish "
 
84
    "$fmonitor $fmonitorb $fmonitorh $fmonitoro $fopen $fstrobe $fstrobeb "
 
85
    "$fstrobeh $fstrobeo $fwrite $fwriteb $fwriteh $fwriteo $hold $itor "
 
86
    "$monitor $monitorb $monitorh $monitoro $monitoroff $monitoron $nochange "
 
87
    "$period $printtimescale $q_add $q_exam $q_full $q_initialize $q_remove "
 
88
    "$random $readmemb $readmemh $realtime $realtobits $recovery $rtoi $setup "
 
89
    "$setuphold $skew $stime $stop $strobe $strobeb $strobeh $strobeo "
 
90
    "$sync$and$array $sync$and$plane $sync$nand$array $sync$nand$plane "
 
91
    "$sync$nor$array $sync$nor$plane $sync$or$array $sync$or$plane $time "
 
92
    "$timeformat $width $write $writeb $writeh $writeo "
 
93
    # 1364-1995 Annex F
 
94
    "$countdrivers $getpattern $incsave $input $key $list $log $nokey $nolog "
 
95
    "$reset $reset_count $reset_value $restart $save $scale $scope $showscopes "
 
96
    "$showvars $sreadmemb $sreadmemh"
 
97
)
 
98
 
 
99
#==============================================================================
 
100
# IEEE 1364-2001 Verilog
 
101
#==============================================================================
 
102
# IEEE 1364-2001 Verilog Preprocessors
 
103
V_1364_2001_PREPROCESSORS = (
 
104
    "`elsif `ifndef `line"
 
105
)
 
106
 
 
107
# IEEE 1364-2001 Verilog Keywords
 
108
V_1364_2001_KEYWORDS = (
 
109
    "automatic cell config design endconfig endgenerate generate genvar incdir "
 
110
    "include instance liblist library localparam noshowcancelled "
 
111
    "pulsestyle_ondetect pulsestyle_onevent showcancelled signed unsigned use"
 
112
)
 
113
 
 
114
# IEEE 1364-2001 Verilog Types
 
115
V_1364_2001_TYPES = (
 
116
    ""
 
117
)
 
118
 
 
119
# IEEE 1364-2001 Verilog System Tasks and Functions
 
120
V_1364_2001_TASKS = (
 
121
    "$dumpports $dumpportsall $dumpportsflush $dumpportslimit $dumpportsoff "
 
122
    "$dumpportson $ferror $fflush $fgetc $fgets $fread $fscanf $fseek $ftell "
 
123
    "$rewind $sdf_annotate $sformat $signed $sscanf $swrite $swriteb $swriteh "
 
124
    "$swriteo $test$plusargs $ungetc $unsigned $value$plusargs"
 
125
)
 
126
 
 
127
#==============================================================================
 
128
# IEEE 1364-2005 Verilog
 
129
#==============================================================================
 
130
# IEEE 1364-2005 Verilog Preprocessors
 
131
V_1364_2005_PREPROCESSORS = (
 
132
    "`pragma"
 
133
)
 
134
 
 
135
# IEEE 1364-2005 Verilog Keywords (NONE)
 
136
V_1364_2005_KEYWORDS = (
 
137
    ""
 
138
)
 
139
 
 
140
# IEEE 1364-2005 Verilog Types
 
141
V_1364_2005_TYPES = (
 
142
    "uwire"
 
143
)
 
144
 
 
145
# IEEE 1364-2005 Verilog System Tasks and Functions (NONE)
 
146
V_1364_2005_TASKS = (
 
147
    ""
 
148
)
 
149
 
 
150
#VERILOG_PREPROCESSORS = " ".join([V_1364_1995_PREPROCESSORS, V_1364_2001_PREPROCESSORS, V_1364_2005_PREPROCESSORS])
 
151
#VERILOG_KEYWORDS      = " ".join([V_1364_1995_KEYWORDS,      V_1364_2001_KEYWORDS,      V_1364_2005_KEYWORDS     ])
 
152
#VERILOG_TYPES         = " ".join([V_1364_1995_TYPES,         V_1364_2001_TYPES,         V_1364_2005_TYPES        ])
 
153
#VERILOG_TASKS         = " ".join([V_1364_1995_TASKS,         V_1364_2001_TASKS,         V_1364_2005_TASKS        ])
 
154
 
 
155
# ---\/----- Overkill maybe? -----\/---
 
156
VERILOG_PREPROCESSORS = " ".join( [V_1364_1995_PREPROCESSORS,
 
157
                                   V_1364_2001_PREPROCESSORS,
 
158
                                   V_1364_2005_PREPROCESSORS] ).split()
 
159
VERILOG_PREPROCESSORS.sort()
 
160
VERILOG_PREPROCESSORS = " ".join( VERILOG_PREPROCESSORS )
 
161
 
 
162
VERILOG_KEYWORDS = " ".join( [V_1364_1995_KEYWORDS,
 
163
                              V_1364_2001_KEYWORDS,
 
164
                              V_1364_2005_KEYWORDS] ).split()
 
165
VERILOG_KEYWORDS.sort()
 
166
VERILOG_KEYWORDS = " ".join( VERILOG_KEYWORDS )
 
167
 
 
168
VERILOG_TYPES = " ".join( [V_1364_1995_TYPES,
 
169
                           V_1364_2001_TYPES, 
 
170
                           V_1364_2005_TYPES] ).split()
 
171
VERILOG_TYPES.sort()
 
172
VERILOG_TYPES = " ".join( VERILOG_TYPES )
 
173
 
 
174
VERILOG_TASKS = " ".join( [V_1364_1995_TASKS, 
 
175
                           V_1364_2001_TASKS, 
 
176
                           V_1364_2005_TASKS] ).split()
 
177
VERILOG_TASKS.sort()
 
178
VERILOG_TASKS = " ".join( VERILOG_TASKS )
 
179
# ---/\----- Overkill maybe? -----/\---
 
180
 
 
181
#---- System Verilog Extensions ----#
 
182
 
 
183
#==============================================================================
 
184
# IEEE 1800-2005 SystemVerilog
 
185
#==============================================================================
 
186
# IEEE 1800-2005 SystemVerilog Preprocessors
 
187
SV_1800_2005_PREPROCESSORS = (
 
188
    # One of "1800-2009" "1800-2005" "1364-2005" "1364-2001" "1364-2001-noconfig" "1364-1995"
 
189
    "`begin_keywords `end_keywords"
 
190
)
 
191
 
 
192
# IEEE 1800-2005 SystemVerilog Keywords
 
193
SV_1800_2005_KEYWORDS = (
 
194
    "alias always_comb always_ff always_latch assert assume before bind "
 
195
    "bins binsof bit break constraint covergroup coverpoint class clocking const"
 
196
    "context continue cover cross dist do endclass endclocking endgroup endinterface "
 
197
    "endpackage endprogram endproperty endsequence expect export extends extern "
 
198
    "final first_match foreach forkjoin iff ignore_bins illegal_bins import "
 
199
    "inside interface intersect join_any join_none modport new null package "
 
200
    "priority process program property pure randcase randsequence ref return "
 
201
    "sequence solve super this throughout timeprecision timeunit type unique "
 
202
    "wait_order wildcard with within "
 
203
    "local packed protected static struct tagged typedef union virtual"
 
204
)
 
205
 
 
206
# IEEE 1800-2005 SystemVerilog Types
 
207
SV_1800_2005_TYPES = (
 
208
    "byte chandle enum int logic longint rand randc shortint shortreal std "
 
209
    "string var void"
 
210
    # Moved to keywords
 
211
#   "local packed protected static struct tagged typedef union virtual"
 
212
)
 
213
 
 
214
# IEEE 1800-2005 SystemVerilog System Tasks and Functions
 
215
SV_1800_2005_TASKS = (
 
216
    "$assertkill $assertoff $asserton $bits $countones $coverage_control "
 
217
    "$coverage_get $coverage_get_max $coverage_merge $coverage_save "
 
218
    "$dimensions $error $exit $fatal $fell $high $increment $info $isunbounded "
 
219
    "$isunknown $left $low $onehot $onehot0 $psprintf $right $rose $sampled "
 
220
    "$size $stable $typename $unpacked_dimensions $warning"
 
221
)
 
222
 
 
223
# IEEE 1800-2005 SystemVerilog Standard Methods
 
224
SV_1800_2005_METHODS = (
 
225
    "and atobin atohex atoi atooct atoreal await back bintoa clear compare data "
 
226
    "delete empty eq erase erase_range exists find find_first find_first_index "
 
227
    "find_index find_last find_last_index finish first front get getc hextoa "
 
228
    "icompare index insert insert_range itoa kill last len max min name neq new "
 
229
    "next num octtoa or peek pop_back pop_front prev product purge push_back "
 
230
    "push_front put putc rand_mode realtoa resume reverse rsort self set shuffle "
 
231
    "size sort start status stop substr sum suspend swap tolower toupper try_get "
 
232
    "try_peek try_put unique unique_index xor"
 
233
)
 
234
 
 
235
#==============================================================================
 
236
# IEEE 1800-2009 SystemVerilog
 
237
#==============================================================================
 
238
SV_1800_2009_PREPROCESSORS = (
 
239
    "`__FILE__ `__LINE__ `undefineall"
 
240
)
 
241
 
 
242
# IEEE 1800-2009 SystemVerilog Keywords
 
243
SV_1800_2009_KEYWORDS = (
 
244
    "accept_on checker endchecker eventually global implies let matches nexttime "
 
245
    "reject_on restrict s_always s_eventually s_nexttime s_until s_until_with "
 
246
    "sync_accept_on sync_reject_on unique0 until until_with untyped weak "
 
247
    # 34.4 Protect pragma directives
 
248
    "protect "
 
249
    "author author_info begin_protected comment data_block data_decrypt_key "
 
250
    "data_keyname data_keyowner data_method data_public_key decrypt_license "
 
251
    "digest_block digest_decrypt_key digest_key_method digest_keyname "
 
252
    "digest_keyowner digest_method digest_public_key encoding encrypt_agent "
 
253
    "encrypt_agent_info encrypt_license end_protected key_block key_keyname "
 
254
    "key_keyowner key_method key_public_key reset runtime_license viewport"
 
255
)
 
256
 
 
257
# IEEE 1800-2009 SystemVerilog Types
 
258
SV_1800_2009_TYPES = (
 
259
    # TODO: Are there new types?
 
260
    ""
 
261
)
 
262
 
 
263
# IEEE 1800-2009 SystemVerilog System Tasks and Functions
 
264
SV_1800_2009_TASKS = (
 
265
    # Section 20.1 General
 
266
    "$acos $acosh $asin $asinh $assertfailoff $assertfailon $assertnonvacuouson "
 
267
    "$assertpassoff $assertpasson $assertvacuousoff $atan $atan2 $atanh "
 
268
    "$bitstoshortreal $cast $ceil $changed $changed_gclk $changing_gclk $clog2 "
 
269
    "$cos $cosh $exp $falling_gclk $fell_gclk $floor $future_gclk $get_coverage "
 
270
    "$hypot $ln $load_coverage_db $log10 $past $past_gclk $pow $rising_gclk "
 
271
    "$rose_gclk $set_coverage_db_name $sformatf $shortrealtobits $sin $sinh "
 
272
    "$sqrt $stable_gclk $steady_gclk $system $tan $tanh"
 
273
)
 
274
 
 
275
# IEEE 1800-2009 SystemVerilog Standard Methods
 
276
SV_1800_2009_METHODS = (
 
277
    # TODO: Add new methods
 
278
    ""
 
279
)
 
280
 
 
281
#SYSTEMVERILOG_PREPROCESSORS = " ".join( [VERILOG_PREPROCESSORS, SV_1800_2005_PREPROCESSORS, SV_1800_2009_PREPROCESSORS] )
 
282
#SYSTEMVERILOG_KEYWORDS      = " ".join( [VERILOG_KEYWORDS,      SV_1800_2005_KEYWORDS,      SV_1800_2009_KEYWORDS     ] )
 
283
#SYSTEMVERILOG_TYPES         = " ".join( [VERILOG_TYPES,         SV_1800_2005_TYPES,         SV_1800_2009_TYPES        ] )
 
284
#SYSTEMVERILOG_TASKS         = " ".join( [VERILOG_TASKS,         SV_1800_2005_TASKS,         SV_1800_2009_TASKS        ] )
 
285
 
 
286
# ---\/----- Overkill maybe? -----\/---
 
287
SYSTEMVERILOG_PREPROCESSORS = " ".join( [VERILOG_PREPROCESSORS, 
 
288
                                         SV_1800_2005_PREPROCESSORS, 
 
289
                                         SV_1800_2009_PREPROCESSORS] ).split()
 
290
SYSTEMVERILOG_PREPROCESSORS.sort()
 
291
SYSTEMVERILOG_PREPROCESSORS = " ".join( SYSTEMVERILOG_PREPROCESSORS )
 
292
 
 
293
SYSTEMVERILOG_KEYWORDS = " ".join( [VERILOG_KEYWORDS, 
 
294
                                    SV_1800_2005_KEYWORDS, 
 
295
                                    SV_1800_2009_KEYWORDS] ).split()
 
296
SYSTEMVERILOG_KEYWORDS.sort()
 
297
SYSTEMVERILOG_KEYWORDS = " ".join( SYSTEMVERILOG_KEYWORDS )
 
298
 
 
299
SYSTEMVERILOG_TYPES = " ".join( [VERILOG_TYPES, 
 
300
                                 SV_1800_2005_TYPES, 
 
301
                                 SV_1800_2009_TYPES] ).split()
 
302
SYSTEMVERILOG_TYPES.sort()
 
303
SYSTEMVERILOG_TYPES = " ".join( SYSTEMVERILOG_TYPES )
 
304
 
 
305
SYSTEMVERILOG_TASKS = " ".join( [VERILOG_TASKS, 
 
306
                                 SV_1800_2005_TASKS, 
 
307
                                 SV_1800_2009_TASKS] ).split()
 
308
SYSTEMVERILOG_TASKS.sort()
 
309
SYSTEMVERILOG_TASKS = " ".join( SYSTEMVERILOG_TASKS )
 
310
# ---/\----- Overkill maybe? -----/\---
 
311
 
 
312
#---- End System Verilog Extensions ----#
 
313
 
 
314
USER_KW = ( 3, "" )
 
315
 
 
316
#---- End Keyword Definitions ----#
 
317
 
 
318
#---- Syntax Style Specs ----#
 
319
SYNTAX_ITEMS = [
 
320
    (stc.STC_V_COMMENT,         'comment_style'  ),
 
321
    (stc.STC_V_COMMENTLINE,     'comment_style'  ),
 
322
    (stc.STC_V_COMMENTLINEBANG, 'comment_style'  ),
 
323
    (stc.STC_V_DEFAULT,         'default_style'  ),
 
324
    (stc.STC_V_IDENTIFIER,      'default_style'  ),
 
325
    (stc.STC_V_NUMBER,          'number_style'   ),
 
326
    (stc.STC_V_OPERATOR,        'operator_style' ),
 
327
    (stc.STC_V_PREPROCESSOR,    'pre_style'      ),
 
328
    (stc.STC_V_STRING,          'string_style'   ),
 
329
    (stc.STC_V_STRINGEOL,       'stringeol_style'),
 
330
    (stc.STC_V_USER,            'default_style'  ),
 
331
    (stc.STC_V_WORD,            'keyword_style'  ),
 
332
    (stc.STC_V_WORD2,           'keyword2_style' ),
 
333
    (stc.STC_V_WORD3,           'scalar_style'   )
 
334
]
 
335
 
 
336
#---- Extra Properties ----#
 
337
FOLD      = ("fold",               "1")
 
338
FOLD_CMT  = ("fold.comment",       "1")
 
339
FOLD_PRE  = ("fold.preprocessor",  "1")
 
340
FOLD_COMP = ("fold.compact",       "1")
 
341
FOLD_ELSE = ("fold.at.else",       "0")
 
342
FOLD_MOD  = ("fold.verilog.flags", "0")
 
343
 
 
344
#-----------------------------------------------------------------------------#
 
345
 
 
346
class SyntaxData(syndata.SyntaxDataBase):
 
347
    """SyntaxData object for Verilog and SysVerilog"""
 
348
    def __init__(self, langid):
 
349
        super(SyntaxData, self).__init__(langid)
 
350
 
 
351
        # Setup
 
352
        self.SetLexer(stc.STC_LEX_VERILOG)
 
353
 
 
354
    def GetKeywords(self):
 
355
        """Returns Specified Keywords List """
 
356
        if self.LangId == synglob.ID_LANG_VERILOG:
 
357
            return [(0, VERILOG_KEYWORDS),
 
358
                    (1, VERILOG_TYPES),
 
359
                    (2, VERILOG_TASKS)]
 
360
        else:
 
361
            return [(0, SYSTEMVERILOG_KEYWORDS),
 
362
                    (1, SYSTEMVERILOG_TYPES),
 
363
                    (2, SYSTEMVERILOG_TASKS)]
 
364
 
 
365
    def GetSyntaxSpec(self):
 
366
        """Syntax Specifications """
 
367
        return SYNTAX_ITEMS
 
368
 
 
369
    def GetProperties(self):
 
370
        """Returns a list of Extra Properties to set """
 
371
        return [FOLD]
 
372
 
 
373
    def GetCommentPattern(self):
 
374
        """Returns a list of characters used to comment a block of code """
 
375
        return [u'//']