hs-term-emulator icon indicating copy to clipboard operation
hs-term-emulator copied to clipboard

Implement proper VT100 parser

Open bitc opened this issue 4 years ago • 2 comments

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

bitc avatar Aug 01 '21 08:08 bitc

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".

iogrt avatar Sep 23 '22 18:09 iogrt

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.

bitc avatar Sep 26 '22 06:09 bitc