Skip to content

Commit 216ce76

Browse files
committed
merge hdl#10
1 parent e1153ac commit 216ce76

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

hdlparse/verilog_parser.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# -*- coding: utf-8 -*-
22
# Copyright © 2017 Kevin Thibedeau
33
# Distributed under the terms of the MIT license
4+
5+
"""Verilog documentation parser"""
46
import io
57
import os
68
from collections import OrderedDict
9+
from .minilexer import MiniLexer
710

8-
from hdlparse.minilexer import MiniLexer
9-
10-
"""Verilog documentation parser"""
1111

1212
verilog_tokens = {
1313
# state
@@ -22,10 +22,10 @@
2222
'module': [
2323
(r'parameter\s*(signed|integer|realtime|real|time)?\s*(\[[^]]+\])?', 'parameter_start', 'parameters'),
2424
(
25-
r'^[\(\s]*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor)?'
25+
r'^[\(\s]*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor|logic)?'
2626
r'\s*(signed)?\s*((\[[^]]+\])+)?',
2727
'module_port_start', 'module_port'),
28-
(r'endmodule', 'end_module', '#pop'),
28+
(r'\bendmodule\b', 'end_module', '#pop'),
2929
(r'/\*', 'block_comment', 'block_comment'),
3030
(r'//#\s*{{(.*)}}\n', 'section_meta'),
3131
(r'//.*\n', None),
@@ -40,7 +40,7 @@
4040
],
4141
'module_port': [
4242
(
43-
r'\s*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor)?'
43+
r'\s*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor|logic)?'
4444
r'\s*(signed)?\s*((\[[^]]+\])+)?',
4545
'module_port_start'),
4646
(r'\s*(\w+)\s*,?', 'port_param'),
@@ -114,7 +114,7 @@ def parse_verilog_file(fname):
114114
Returns:
115115
List of parsed objects.
116116
"""
117-
with open(fname, 'rt') as fh:
117+
with open(fname, 'rt', encoding='UTF-8') as fh:
118118
text = fh.read()
119119
return parse_verilog(text)
120120

@@ -130,25 +130,25 @@ def parse_verilog(text):
130130
lex = VerilogLexer
131131

132132
name = None
133-
kind = None
134-
saved_type = None
133+
#kind = None
134+
#saved_type = None
135135
mode = 'input'
136136
port_type = 'wire'
137137
param_type = ''
138138

139139
metacomments = []
140-
parameters = []
140+
#parameters = []
141141

142142
generics = []
143143
ports = OrderedDict()
144144
sections = []
145145
port_param_index = 0
146146
last_item = None
147-
array_range_start_pos = 0
147+
#array_range_start_pos = 0
148148

149149
objects = []
150150

151-
for pos, action, groups in lex.run(text):
151+
for _, action, groups in lex.run(text):
152152
if action == 'metacomment':
153153
comment = groups[0].strip()
154154
if last_item is None:
@@ -160,7 +160,7 @@ def parse_verilog(text):
160160
sections.append((port_param_index, groups[0]))
161161

162162
elif action == 'module':
163-
kind = 'module'
163+
#kind = 'module'
164164
name = groups[0]
165165
generics = []
166166
ports = OrderedDict()
@@ -226,7 +226,7 @@ def is_verilog(fname):
226226
Returns:
227227
True when file has a Verilog extension.
228228
"""
229-
return os.path.splitext(fname)[1].lower() in ('.vlog', '.v')
229+
return os.path.splitext(fname)[1].lower() in ('.vlog', '.v', '.sv')
230230

231231

232232
class VerilogExtractor:

0 commit comments

Comments
 (0)