Skip to content

Commit

Permalink
merge hdl#10
Browse files Browse the repository at this point in the history
  • Loading branch information
iDoka committed Feb 20, 2024
1 parent e1153ac commit 216ce76
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions hdlparse/verilog_parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright © 2017 Kevin Thibedeau
# Distributed under the terms of the MIT license

"""Verilog documentation parser"""
import io
import os
from collections import OrderedDict
from .minilexer import MiniLexer

from hdlparse.minilexer import MiniLexer

"""Verilog documentation parser"""

verilog_tokens = {
# state
Expand All @@ -22,10 +22,10 @@
'module': [
(r'parameter\s*(signed|integer|realtime|real|time)?\s*(\[[^]]+\])?', 'parameter_start', 'parameters'),
(
r'^[\(\s]*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor)?'
r'^[\(\s]*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor|logic)?'
r'\s*(signed)?\s*((\[[^]]+\])+)?',
'module_port_start', 'module_port'),
(r'endmodule', 'end_module', '#pop'),
(r'\bendmodule\b', 'end_module', '#pop'),
(r'/\*', 'block_comment', 'block_comment'),
(r'//#\s*{{(.*)}}\n', 'section_meta'),
(r'//.*\n', None),
Expand All @@ -40,7 +40,7 @@
],
'module_port': [
(
r'\s*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor)?'
r'\s*(input|inout|output)\s+(reg|supply0|supply1|tri|triand|trior|tri0|tri1|wire|wand|wor|logic)?'
r'\s*(signed)?\s*((\[[^]]+\])+)?',
'module_port_start'),
(r'\s*(\w+)\s*,?', 'port_param'),
Expand Down Expand Up @@ -114,7 +114,7 @@ def parse_verilog_file(fname):
Returns:
List of parsed objects.
"""
with open(fname, 'rt') as fh:
with open(fname, 'rt', encoding='UTF-8') as fh:
text = fh.read()
return parse_verilog(text)

Expand All @@ -130,25 +130,25 @@ def parse_verilog(text):
lex = VerilogLexer

name = None
kind = None
saved_type = None
#kind = None
#saved_type = None
mode = 'input'
port_type = 'wire'
param_type = ''

metacomments = []
parameters = []
#parameters = []

generics = []
ports = OrderedDict()
sections = []
port_param_index = 0
last_item = None
array_range_start_pos = 0
#array_range_start_pos = 0

objects = []

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

elif action == 'module':
kind = 'module'
#kind = 'module'
name = groups[0]
generics = []
ports = OrderedDict()
Expand Down Expand Up @@ -226,7 +226,7 @@ def is_verilog(fname):
Returns:
True when file has a Verilog extension.
"""
return os.path.splitext(fname)[1].lower() in ('.vlog', '.v')
return os.path.splitext(fname)[1].lower() in ('.vlog', '.v', '.sv')


class VerilogExtractor:
Expand Down

0 comments on commit 216ce76

Please sign in to comment.