Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added index of error to LexError #3

Merged
merged 1 commit into from Feb 17, 2017
Merged

Added index of error to LexError #3

merged 1 commit into from Feb 17, 2017

Conversation

pydanny
Copy link
Contributor

@pydanny pydanny commented Feb 17, 2017

This allows for easier writing of tools empowered by the sly library. Now you can extend the library to get a better context of the lexed data.

Working example taken from the TSD parser:

for path in glob('chapters/*'):
    with open(path) as f:
        data = f.read()
    try:
        tokens = [x for x in tokenize(data)]
    except LexError as err:
        print(f"ERROR AT {err.error_index} in {path}")
        print('*'*40)
        res = data[err.error_index-20:err.error_index+20]
        print(res)
        print('*'*40)
        # print("Precise:" + data[err.error_index-1:err.error_index+1], sep='')
        break

This allows for easier writing of tools empowered by the `sly` library. Now you can extend the library to get a better context of the lexed data.
@dabeaz dabeaz merged commit c0694aa into dabeaz:master Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants