From 9f45cfbf2d38bc1ab4b3f291262cfcd6b9f253a0 Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Tue, 13 Feb 2024 19:02:57 -0600 Subject: [PATCH] Issue#1123: Added exception for malformed discrete_range. (#1126) --- vsg/vhdlFile/classify/discrete_range.py | 8 +++++++ vsg/vhdlFile/utils.py | 28 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/vsg/vhdlFile/classify/discrete_range.py b/vsg/vhdlFile/classify/discrete_range.py index 8ff70009..0bba30c5 100644 --- a/vsg/vhdlFile/classify/discrete_range.py +++ b/vsg/vhdlFile/classify/discrete_range.py @@ -31,8 +31,14 @@ def classify_until(lUntils, iToken, lObjects): iStop = len(lObjects) - 1 iOpenParenthesis = 0 iCloseParenthesis = 0 + iPrevious = -1 + while iCurrent < iStop: iCurrent = utils.find_next_token(iCurrent, lObjects) + + if iCurrent == iPrevious: + utils.print_missing_error_message(lUntils, iToken, lObjects) + if utils.token_is_open_parenthesis(iCurrent, lObjects): iOpenParenthesis += 1 if utils.token_is_close_parenthesis(iCurrent, lObjects): @@ -46,4 +52,6 @@ def classify_until(lUntils, iToken, lObjects): utils.assign_token(lObjects, iCurrent, parser.todo) else: utils.assign_token(lObjects, iCurrent, parser.todo) + iPrevious = iCurrent + return iCurrent diff --git a/vsg/vhdlFile/utils.py b/vsg/vhdlFile/utils.py index fb4dae31..d31a9f65 100644 --- a/vsg/vhdlFile/utils.py +++ b/vsg/vhdlFile/utils.py @@ -472,6 +472,20 @@ def print_error_message(sToken, token, iToken, lObjects): raise exceptions.ClassifyError(sErrorMessage) +def print_missing_error_message(lTokens, iToken, lObjects): + iLine = calculate_line_number(iToken, lObjects) + + sErrorMessage = '\n' + sErrorMessage += f'Error: Closing token not found while parsing Line {iLine}' + sErrorMessage += '\n' + sErrorMessage += '\n' + sErrorMessage += f' {iLine} | ' + sErrorMessage += extract_line_with_token_index_of(iToken, lObjects) + sErrorMessage += '\n' + + raise exceptions.ClassifyError(sErrorMessage) + + def extract_module_name(token): return token.__module__.split('.')[-1] @@ -956,3 +970,17 @@ def convert_boolean_to_yes_no(option): else: return 'no' return option + + +def extract_line_with_token_index_of(iToken, lObjects): + for iIndex in range(0, iToken): + if isinstance(lObjects[iIndex], parser.carriage_return): + iStart = iIndex + 1 + for iIndex in range(iToken, len(lObjects)): + if isinstance(lObjects[iIndex], parser.carriage_return): + iEnd = iIndex + break + sReturn = '' + for oObject in lObjects[iStart:iEnd]: + sReturn += oObject.get_value() + return sReturn