Issue#1123: Added exception for malformed discrete_range. (#1126)

This commit is contained in:
Jeremiah Leary 2024-02-13 19:02:57 -06:00 committed by GitHub
parent 69cc709cb5
commit 9f45cfbf2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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