frroossst / py_mips_debugger

A minimal MIPS python interpreter that allows for easy debugging and improved developer workflow
https://frroossst.github.io/py_mips_debugger/
GNU General Public License v3.0
0 stars 0 forks source link

Impl fuzzy string matching for better error message suggestions #20

Closed frroossst closed 1 year ago

frroossst commented 1 year ago
labels = ['main', 'start', 'exit']

# Get the user's input
user_input = input('Enter a label: ')

# Find the closest match to the user's input
distances = [len(label) - sum([1 for i, j in zip(label, user_input) if i == j]) for label in labels]
min_distance = min(distances)
closest_match = labels[distances.index(min_distance)]

# If the closest match is within a certain threshold, suggest it to the user
if min_distance <= 2:
    suggestion = input(f'Did you mean "{closest_match}" instead? (y/n)')
    if suggestion.lower() == 'y':
        user_input = closest_match

# Use the user's input for further processing
print(f'Processing label "{user_input}"...')
frroossst commented 1 year ago

Initial code, not implemented 73ef10846098ab3b4246596fabf7f00c8f491ade