Skip to content

Two don't cares ('-') adjacent in a literal is parsed as a comment #529

@ktbarrett

Description

@ktbarrett

The remove_comments(code) function is overly simplistic. It matches any two adjacent - characters until the end of the line. '-' is also used as a "don't care" value for std_logic. If there is an std_logic_vector literal where there are two don't care values in a row (e.g. '----'), it is parsed as a comment and the rest of the line is removed, causing the parse to fail.

vunit/vunit/vhdl_parser.py

Lines 991 to 1007 in 12be973

VHDL_REMOVE_COMMENT_RE = re.compile(r'--[^\n]*')
def _comment_repl(match):
"""
Replace comment with equal amount of whitespace to make
lexical position unaffected
"""
text = match.group(0)
return " " * len(text)
def remove_comments(code):
"""
Return the code with comments removed
"""
return VHDL_REMOVE_COMMENT_RE.sub(_comment_repl, code)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions