Merge remote-tracking branch 'origin/master' into issue-1503

This commit is contained in:
JHertz5 2026-05-23 17:35:55 +01:00
commit d8e5ff06e7
10 changed files with 151 additions and 230 deletions

View File

@ -22,28 +22,14 @@ VHDL Style Guide (VSG)
Announcements
-------------
Update 01/01/2025
Update 11/09/2025
The regex definitions for camelCase and PascalCase are going to be changing for release 3.30.0 to better align with industry "standards".
Where has Jeremy been?
The current regex allows for an unlimited number of uppercase characters in a row:
Just wanted to let everyone know that I have not abandoned this project.
There was a family emergency I had to handle and now work is taking a significant amount of my time.
.. code-block:: bash
myFIFO
MyFIFO
A more strict version of camelCase and PascalCase will be implemented to limit the number of consecutive uppercase characters to 2.
.. code-block:: bash
myFIfo
MyFIfo
The original regex definition for camelCase will be moved to relaxedCamelCase.
The original regex definition for PascalCase will be moved to RelaxedPascalCase.
If you have a strong opinion on how the regex is defined, your feedback would be appreciated on issue #1202.
I plan to start working on this again in December.
Regards,

View File

@ -33,8 +33,8 @@ Rules Enforcing Case Rule Group
* `attribute_specification_501 <../attribute_specification_rules.html#attribute-specification-501>`_
* `attribute_specification_502 <../attribute_specification_rules.html#attribute-specification-502>`_
* `attribute_specification_503 <../attribute_specification_rules.html#attribute-specification-503>`_
* `bit_string_literal_500 <bit_string_literal_rules.html#bit-string-literal-500>`_
* `bit_string_literal_501 <bit_string_literal_rules.html#bit-string-literal-501>`_
* `bit_string_literal_500 <../bit_string_literal_rules.html#bit-string-literal-500>`_
* `bit_string_literal_501 <../bit_string_literal_rules.html#bit-string-literal-501>`_
* `block_500 <../block_rules.html#block-500>`_
* `block_501 <../block_rules.html#block-501>`_
* `block_502 <../block_rules.html#block-502>`_

View File

@ -47,6 +47,9 @@ begin
others => 'X'
);
variable v_result : string(1 to
2);
begin
end process;

View File

@ -38,6 +38,9 @@ begin
others => 'X'
);
variable v_result : string(1 to
2);
begin
end process;

View File

@ -72,12 +72,10 @@ def load_rules():
Returns: (rule object list)
"""
lRules = []
for name, oPackage in inspect.getmembers(importlib.import_module("vsg.rules")):
if inspect.ismodule(oPackage):
for name, oRule in inspect.getmembers(oPackage):
if inspect.isclass(oRule) and name.startswith("rule_"):
lRules.append(oRule())
for _, oPackage in inspect.getmembers(importlib.import_module("vsg.rules"), inspect.ismodule):
for rule_name, oRule in inspect.getmembers(oPackage, inspect.isclass):
if rule_name.startswith("rule_"):
lRules.append(oRule())
return lRules

View File

@ -4,7 +4,7 @@ from vsg.rules import multiline_structure as Rule
from vsg.token import variable_declaration as token
lTokenPairs = []
lTokenPairs.append([token.variable_keyword, token.semicolon])
lTokenPairs.append([token.assignment_operator, token.semicolon])
class rule_403(Rule):

View File

@ -22,12 +22,14 @@ class New:
return []
def get_token_indexes_between_indexes(self, oToken, iStart, iEnd):
lReturn = []
lIndexes = self.get_token_indexes(oToken)
for iIndex in lIndexes:
if iIndex > iStart and iIndex < iEnd:
lReturn.append(iIndex)
return lReturn
if not lIndexes:
return []
# Use a binary search to get the first index > the start.
iLowIndex = bisect.bisect_right(lIndexes, iStart)
# Use a binary search to get the last index < the end.
iHighIndex = bisect.bisect_left(lIndexes, iEnd)
return lIndexes[iLowIndex:iHighIndex]
def get_line_number_of_index(self, iIndex):
iLine = bisect.bisect_left(self.dMap["parser"]["carriage_return"], iIndex) + 1
@ -246,12 +248,13 @@ def extract_pairs(lStartIndexes, lEndIndexes):
def extract_closest_pair(iStart, lEndIndexes, lPair, iMin):
for iEnd in lEndIndexes:
if iStart > iEnd:
continue
if iEnd - iStart < iMin:
lPair = [iStart, iEnd]
iMin = iEnd - iStart
# The list of end indexes is assumed to be sorted. Get the first end >= start via binary search.
iPos = bisect.bisect_left(lEndIndexes, iStart)
if iPos == len(lEndIndexes):
return lPair
iEnd = lEndIndexes[iPos]
if iEnd - iStart < iMin:
lPair = [iStart, iEnd]
return lPair

View File

@ -1,11 +1,26 @@
# -*- coding: utf-8 -*-
lSingleCharacterSymbols = [",", ":", "(", ")", "'", '"', "+", "&", "-", "*", "/", "<", ">", ";", "=", "[", "]", "?"]
lTwoCharacterSymbols = ["=>", "**", ":=", "/=", ">=", "<=", "<>", "??", "?=", "?<", "?>", "<<", ">>", "--", "/*", "*/"]
lThreeCharacterSymbols = ["?/=", "?<=", "?>="]
lFourCharacterSymbols = ["\\?=\\"]
lSingleCharacterSymbols = {",", ":", "(", ")", "'", '"', "+", "&", "-", "*", "/", "<", ">", ";", "=", "[", "]", "?"}
lTwoCharacterSymbols = {"=>", "**", ":=", "/=", ">=", "<=", "<>", "??", "?=", "?<", "?>", "<<", ">>", "--", "/*", "*/"}
lThreeCharacterSymbols = {"?/=", "?<=", "?>="}
lMultiCharacterSymbols = lTwoCharacterSymbols | lThreeCharacterSymbols
lStopChars = [" ", "(", ";"]
lStopChars = {" ", "(", ";"}
def build_symbol_prefix_tree(lSymbols):
dPrefixTree = {}
for sSymbol in lSymbols:
dNode = dPrefixTree
for oChar in sSymbol:
# Return the branch of the prefix tree for this character, or create an empty branch if there isn't one.
dNode = dNode.setdefault(oChar, {})
# Use $ as the marker for the end of a branch.
dNode["$"] = sSymbol
return dPrefixTree
dSymbolTree = build_symbol_prefix_tree(lMultiCharacterSymbols)
def create(sString):
@ -17,8 +32,7 @@ def create(sString):
oLine.combine_whitespace()
oLine.combine_string_literals()
oLine.combine_backslash_characters_into_symbols()
oLine.combine_three_character_symbols()
oLine.combine_two_character_symbols()
oLine.combine_symbols_with_prefix_tree()
oLine.combine_characters_into_words()
oLine.combine_character_literals()
oLine.split_natural_numbers()
@ -28,7 +42,7 @@ def create(sString):
class New:
def __init__(self, sLine):
self.lChars = convert_string_to_chars(sLine)
self.lChars = list(sLine)
def combine_whitespace(self):
lReturn = []
@ -46,6 +60,30 @@ class New:
self.lChars = lReturn
def combine_symbols_with_prefix_tree(self):
lReturn = []
iStart = 0
iNumChars = len(self.lChars)
while iStart < iNumChars:
dNode = dSymbolTree
iEnd = iStart
oLastMatch = None
iPrevEnd = iStart
# Try to match as long a symbol as possible.
while iEnd < iNumChars and self.lChars[iEnd] in dNode:
dNode = dNode[self.lChars[iEnd]]
iEnd += 1
if "$" in dNode:
oLastMatch = dNode["$"]
iPrevEnd = iEnd
if oLastMatch:
lReturn.append(oLastMatch)
iStart = iPrevEnd
else:
lReturn.append(self.lChars[iStart])
iStart += 1
self.lChars = lReturn
def combine_backslash_characters_into_symbols(self):
lReturn = []
sSymbol = ""
@ -61,48 +99,21 @@ class New:
lReturn = add_trailing_string(lReturn, sSymbol)
self.lChars = lReturn
def combine_three_character_symbols(self):
lReturn = []
i = 0
while i < len(self.lChars):
sChars = "".join(self.lChars[i : i + 3])
if sChars in lThreeCharacterSymbols:
lReturn.append(sChars)
i += 3
else:
lReturn.append(self.lChars[i])
i += 1
self.lChars = lReturn
def combine_two_character_symbols(self):
lReturn = []
i = 0
while i < len(self.lChars):
sChars = "".join(self.lChars[i : i + 2])
if sChars in lTwoCharacterSymbols:
lReturn.append(sChars)
i += 2
else:
lReturn.append(self.lChars[i])
i += 1
self.lChars = lReturn
def combine_characters_into_words(self):
lReturn = []
sTemp = ""
sWord = []
for sChar in self.lChars:
if character_is_part_of_word(sChar):
sTemp += sChar
sWord.append(sChar)
else:
if sTemp != "":
lReturn.append(sTemp)
if sWord:
lReturn.append("".join(sWord))
sWord.clear()
lReturn.append(sChar)
sTemp = ""
if len(sTemp) != 0:
lReturn.append(sTemp)
if sWord:
lReturn.append("".join(sWord))
self.lChars = lReturn
@ -213,31 +224,23 @@ def find_character_literal_candidates(lQuotes, lChars):
def is_character_literal_candidate(iIndex, lQuotes, lChars):
iQuote = lQuotes[iIndex]
if (
return (
there_is_a_single_token_between_quotes(iIndex, lQuotes)
and token_between_quotes_is_a_single_character(iQuote, lChars)
and token_is_not_a_parenthesis(iQuote, lChars)
):
return True
return False
)
def there_is_a_single_token_between_quotes(iIndex, lQuotes):
if lQuotes[iIndex] + 2 == lQuotes[iIndex + 1]:
return True
return False
return lQuotes[iIndex] + 2 == lQuotes[iIndex + 1]
def token_between_quotes_is_a_single_character(iQuote, lChars):
if len(lChars[iQuote + 1]) == 1:
return True
return False
return len(lChars[iQuote + 1]) == 1
def token_is_not_a_parenthesis(iQuote, lChars):
if lChars[iQuote + 1] == "(":
return False
return True
return lChars[iQuote + 1] != "("
def filter_character_literal_candidates(lLiterals):
@ -272,15 +275,11 @@ def append_to_list(bSymbol, lChars, sChar):
def backslash_character_found(sChar):
if sChar == "\\":
return True
return False
return sChar == "\\"
def stop_character_found(sChar, bLiteral):
if (sChar in lStopChars or " " in sChar) and bLiteral:
return True
return False
return (sChar in lStopChars or " " in sChar) and bLiteral
def add_trailing_string(lReturn, sString):
@ -289,21 +288,8 @@ def add_trailing_string(lReturn, sString):
return lReturn
def convert_string_to_chars(sString):
lReturn = []
for sChar in sString:
lReturn.append(sChar)
return lReturn
def character_is_part_of_word(sChar):
if len(sChar) > 1:
return False
elif sChar.isspace():
return False
elif sChar in lSingleCharacterSymbols:
return False
return True
return len(sChar) == 1 and not sChar.isspace() and sChar not in lSingleCharacterSymbols
def find_indexes_of_double_quote_pairs(lTokens):

View File

@ -13,6 +13,9 @@ from vsg.token import (
relational_operator,
)
# Cache parser.item for speed, since it is referenced so frequently.
parser_item = parser.item
def assign_tokens_until(sToken, token, iToken, lObjects):
iCurrent = iToken
@ -110,22 +113,16 @@ def assign_parenthesis_as_todo(iToken, lObjects):
def object_value_is(lAllObjects, iToken, sString):
if lAllObjects[iToken].get_lower_value() == sString.lower():
return True
return False
return lAllObjects[iToken].get_lower_value() == sString.lower()
def object_value_matches(lAllObjects, iToken, oRegex):
sToken = lAllObjects[iToken].get_lower_value()
if oRegex.fullmatch(sToken) is not None:
return True
return False
return oRegex.fullmatch(sToken) is not None
def is_item(lAllObjects, iToken):
if type(lAllObjects[iToken]) == parser.item:
return True
return False
return type(lAllObjects[iToken]) is parser_item
def get_range(lObjects, iStart, sEnd):
@ -279,14 +276,17 @@ def find_earliest_occurrence_not_in_paren(lEnd, iToken, lObjects):
def find_next_token(iToken, lObjects):
for iCurrent, oToken in enumerate(lObjects[iToken::]):
if type(oToken) == parser.item:
return iCurrent + iToken
iLenObjects = len(lObjects)
iCurrent = iToken
while iCurrent < iLenObjects:
if type(lObjects[iCurrent]) is parser_item:
return iCurrent
iCurrent += 1
return iToken
def rename_this_is_item_function(oToken):
return type(oToken) == parser.item
return type(oToken) is parser_item
def find_next_non_whitespace_token(iToken, lObjects):
@ -326,9 +326,7 @@ def has_label(iObject, lObjects):
iCurrent = find_next_token(iObject, lObjects)
iCurrent = increment_token_count(iCurrent)
iCurrent = find_next_token(iCurrent, lObjects)
if object_value_is(lObjects, iCurrent, ":"):
return True
return False
return object_value_is(lObjects, iCurrent, ":")
def tokenize_postponed(iObject, lObjects, token):
@ -392,33 +390,23 @@ def print_lines(lObjects):
def token_is_semicolon(iObject, lObjects):
if object_value_is(lObjects, iObject, ";"):
return True
return False
return object_value_is(lObjects, iObject, ";")
def token_is_comma(iObject, lObjects):
if object_value_is(lObjects, iObject, ","):
return True
return False
return object_value_is(lObjects, iObject, ",")
def token_is_open_parenthesis(iObject, lObjects):
if object_value_is(lObjects, iObject, "("):
return True
return False
return object_value_is(lObjects, iObject, "(")
def token_is_close_parenthesis(iObject, lObjects):
if object_value_is(lObjects, iObject, ")"):
return True
return False
return object_value_is(lObjects, iObject, ")")
def token_is_assignment_operator(iObject, lObjects):
if object_value_is(lObjects, iObject, "<="):
return True
return False
return object_value_is(lObjects, iObject, "<=")
def increment_token_count(iToken):
@ -427,23 +415,17 @@ def increment_token_count(iToken):
def matches_next_token(oRegex, iToken, lObjects):
iCurrent = find_next_token(iToken, lObjects)
if object_value_matches(lObjects, iCurrent, oRegex):
return True
return False
return object_value_matches(lObjects, iCurrent, oRegex)
def is_next_token(sToken, iToken, lObjects):
iCurrent = find_next_token(iToken, lObjects)
if object_value_is(lObjects, iCurrent, sToken):
return True
return False
return object_value_is(lObjects, iCurrent, sToken)
def is_next_token_one_of(lTokens, iToken, lObjects):
iCurrent = find_next_token(iToken, lObjects)
if lObjects[iCurrent].get_lower_value() in lTokens:
return True
return False
return lObjects[iCurrent].get_lower_value() in lTokens
def detect_subelement_until(sToken, element, iToken, lObjects):
@ -519,20 +501,13 @@ def extract_module_name(token):
def keyword_found(sKeyword, iToken, lObjects):
if find_in_next_n_tokens(":", 2, iToken, lObjects):
if find_in_next_n_tokens(sKeyword, 3, iToken, lObjects):
return True
else:
return False
if is_next_token(sKeyword, iToken, lObjects):
return True
return False
return find_in_next_n_tokens(sKeyword, 3, iToken, lObjects)
return is_next_token(sKeyword, iToken, lObjects)
def is_next_token_in_list(lUntils, iToken, lObjects):
iCurrent = find_next_token(iToken, lObjects)
if lObjects[iCurrent].get_lower_value() in lUntils:
return True
return False
return lObjects[iCurrent].get_lower_value() in lUntils
def combine_two_token_class_lists(lToi_a, lToi_b):
@ -561,9 +536,7 @@ def does_length_of_tokens_exceed(lObjects, iLength):
iTotalLength = 0
for oObject in lObjects:
iTotalLength += len(oObject.get_value())
if iTotalLength > iLength:
return True
return False
return iTotalLength > iLength
def remove_carriage_returns_from_token_list(lTokens):
@ -613,9 +586,7 @@ def remove_comment_at_end_of_token_list(lTokens):
def does_token_type_match(oToken, oType):
if isinstance(oToken, oType):
return True
return False
return isinstance(oToken, oType)
def remove_trailing_whitespace(lTokens):
@ -664,42 +635,30 @@ def remove_all_trailing_whitespace(lTokens):
def token_is_whitespace_or_comment(oToken):
if (
return (
isinstance(oToken, parser.whitespace)
or isinstance(oToken, parser.carriage_return)
or isinstance(oToken, parser.comment)
or isinstance(oToken, parser.blank_line)
or isinstance(oToken, parser.preprocessor)
):
return True
else:
return False
)
def token_is_whitespace_token(oToken):
if isinstance(oToken, parser.whitespace):
return True
else:
return False
return isinstance(oToken, parser.whitespace)
def token_is_whitespace(oToken):
if (
return (
isinstance(oToken, parser.whitespace)
or isinstance(oToken, parser.carriage_return)
or isinstance(oToken, parser.blank_line)
or isinstance(oToken, parser.preprocessor)
):
return True
else:
return False
)
def token_is_carriage_return(oToken):
if isinstance(oToken, parser.carriage_return):
return True
else:
return False
return isinstance(oToken, parser.carriage_return)
def increment_line_number(iLine, oToken):
@ -743,9 +702,7 @@ def count_token_types_in_list_of_tokens(oType, lTokens):
def does_token_type_exist_in_list_of_tokens(oType, lTokens):
if count_token_types_in_list_of_tokens(oType, lTokens) == 0:
return False
return True
return count_token_types_in_list_of_tokens(oType, lTokens) != 0
def get_toi_parameters(oToi):
@ -763,16 +720,12 @@ def toi_is_array(oToi):
def does_token_start_line(iToken, lTokens):
if isinstance(lTokens[iToken - 1], parser.whitespace) and isinstance(lTokens[iToken - 2], parser.carriage_return):
return True
if isinstance(lTokens[iToken - 1], parser.carriage_return):
return True
return False
else:
return isinstance(lTokens[iToken - 1], parser.carriage_return)
def convert_token_list_to_string(lTokens):
sReturn = ""
for oToken in lTokens:
sReturn += oToken.get_value()
return sReturn
return "".join([oToken.get_value() for oToken in lTokens])
def fix_blank_lines(lTokens):
@ -816,17 +769,13 @@ def fix_trailing_whitespace(lTokens):
def is_whitespace(oObject):
if isinstance(oObject, parser.carriage_return):
return True
if isinstance(oObject, parser.blank_line):
return True
if isinstance(oObject, parser.comment):
return True
if isinstance(oObject, parser.whitespace):
return True
if isinstance(oObject, parser.preprocessor):
return True
return False
return (
isinstance(oObject, parser.carriage_return)
or isinstance(oObject, parser.blank_line)
or isinstance(oObject, parser.comment)
or isinstance(oObject, parser.whitespace)
or isinstance(oObject, parser.preprocessor)
)
def read_vhdlfile(sFileName, bIncludeEncoding=False):
@ -862,15 +811,12 @@ def read_vhdlfile(sFileName, bIncludeEncoding=False):
def is_token_at_end_of_line(iToken, lTokens):
iMyToken = iToken + 1
if are_next_consecutive_token_types([parser.carriage_return], iMyToken, lTokens):
return True
if are_next_consecutive_token_types([parser.whitespace, parser.carriage_return], iMyToken, lTokens):
return True
if are_next_consecutive_token_types([parser.comment, parser.carriage_return], iMyToken, lTokens):
return True
if are_next_consecutive_token_types([parser.whitespace, parser.comment, parser.carriage_return], iMyToken, lTokens):
return True
return False
return (
are_next_consecutive_token_types([parser.carriage_return], iMyToken, lTokens)
or are_next_consecutive_token_types([parser.whitespace, parser.carriage_return], iMyToken, lTokens)
or are_next_consecutive_token_types([parser.comment, parser.carriage_return], iMyToken, lTokens)
or are_next_consecutive_token_types([parser.whitespace, parser.comment, parser.carriage_return], iMyToken, lTokens)
)
def find_next_token_with_value(iToken, sValue, lTokens):
@ -973,13 +919,11 @@ def assign_special_tokens(lObjects, iCurrent, oType):
def exponent_detected(lObjects, iCurrent):
if isinstance(lObjects[iCurrent - 1], exponent.e_keyword):
return True
if isinstance(lObjects[iCurrent - 1], exponent.plus_sign):
return True
if isinstance(lObjects[iCurrent - 1], exponent.minus_sign):
return True
return False
return (
isinstance(lObjects[iCurrent - 1], exponent.e_keyword)
or isinstance(lObjects[iCurrent - 1], exponent.plus_sign)
or isinstance(lObjects[iCurrent - 1], exponent.minus_sign)
)
def classify_predefined_types(lObjects, iCurrent):

View File

@ -131,10 +131,8 @@ class vhdlFile:
self.lAllObjects = []
for sLine in self.filecontent:
self.dVars["line"] = sLine
lTokens = tokens.create(sLine.rstrip("\n").rstrip("\r"))
lObjects = []
for sToken in lTokens:
lObjects.append(parser.item(sToken))
lTokens = tokens.create(sLine.rstrip("\r\n"))
lObjects = [parser.item(sToken) for sToken in lTokens]
blank.classify(lObjects, oOptions)
whitespace.classify(lTokens, lObjects)