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

Implement proper VT100 parser #2

Open
bitc opened this issue Aug 1, 2021 · 2 comments
Open

Implement proper VT100 parser #2

bitc opened this issue Aug 1, 2021 · 2 comments

Comments

@bitc
Copy link
Owner

bitc commented Aug 1, 2021

The current parser is a bit adhoc and doesn't handle invalid escape sequences well.

Here is a document that explains how to implement a proper parser using a state machine: https://vt100.net/emu/dec_ansi_parser

Here is a TypeScript implementation I found: https://github.com/xtermjs/xterm.js/blob/522c8bf3afcc296f7586c21b097025fe3626dc32/src/common/parser/EscapeSequenceParser.ts#L201

@iogrt
Copy link

iogrt commented Sep 23, 2022

Hi, first of all, thanks for the cool project.
If you want to structure the parser around a state machine, while keeping the code very similar to what you already have, I recommend checking out https://github.com/UnkindPartition/regex-applicative.
I'm not sure what you mean by the parser being "adhoc".

@bitc
Copy link
Owner Author

bitc commented Sep 26, 2022

I guess what I meant by "adhoc" is that the parser doesn't deal with edge cases and errors properly. For example, the way that the parseEscape function falls back to handleSingle I don't think is correct. And when a parse error is detected, it just skips the character, while the correct thing is to perform error recovery according to the link I gave above.

The current parser seems to work well in practice, with lots of apps working. But a few apps don't work properly and I'm not sure if it's because of the parser or other parts of the terminal emulator, but improving the parser feels to me like a good first step.

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

No branches or pull requests

2 participants