hazel icon indicating copy to clipboard operation
hazel copied to clipboard

Parsing

Open nj-wilson opened this issue 2 years ago • 2 comments

Adds ability to import text into hazel as a program, as well as exporting the current program to plain text.

Currently is part of the hamburger menu as separate options (could easily be combined). Import errors are shown, but currently are quite rudimentary, only showing what character caused a problem.

A couple commits are still local, for cleanup and additional tests. There is a behavior difference with regard to empty or comment lines, but nothing that impacts correct programs.

ExternalLineBreak was added to Layout.t, but may be better as an Annot (for a future PR). The module naming for the parser and lexer are somewhat confusing, i.e. Parsing.Parser, and Lexing.Lexer. Could use better names.

nj-wilson avatar Nov 04 '21 20:11 nj-wilson

Is an interesting idea, I shall look into it. My only questions would be on how to display errors resulting in trying to go back to structured, though maybe that'll be taking care of from running the evaluator during edit. Though I do wonder if that would be problematic to run on every character typed.

I'll also have to see how easy it would be to switch the main text box between modes, or do some other method.

nj-wilson avatar May 13 '22 20:05 nj-wilson

You can use the same area in the UI that results are displayed to show errors, since no result is available when parsing fails, and the button to toggle back to structure editing can be disabled when there is a parse error. Don't worry about the performance cost of running the parser on each edit. If that becomes an issue down the line we can look into incremental parsing approaches, but nothing at the scale we're using Hazel should cause an issue. Learn OCaml already parses and pretty prints on every character.

Shouldn't be too difficult GUI wise with the model-view-controller approach. When in text mode, render the text box you already have set up from the pop up in your branch, otherwise render the existing structure editor box.

cyrus- avatar May 19 '22 03:05 cyrus-

no longer relevant with the two other PRs.

cyrus- avatar Aug 19 '22 00:08 cyrus-