What you want is a structured editor with syntax . This is the one that combines parsing with the AST building and uses a parser to predict what you can print next (or to complete the syntax), or has a link to the last run of the compiler so that it can interpret the edit point to find out which are valid identifiers can follow by checking the compiler symbol table, which was the last relevant at this point in the code.
The hardest part is to offer the user an unhindered experience; to a large extent, she must believe that she is editing the text or (editors show experience with structures), she rejects this as inconvenient.
These are many mechanisms for coordination and great effort. The good news is that you need a parser anyway for the compiler; if editing also parses, the AST required by the compiler is essentially available. (Of course, you also need to worry about batch compilation). The compiler must create a character table; therefore, you can use this in the process of completing editing. More complicated news is that parsers are much more difficult to build; they cannot just declare a syntax error visible to the user and exit; rather, they should be tolerant of a number of errors that persist at the same time, hold partial ASTs for pieces, and stitch them together, as errors are deleted by the user.
Berkeley Harmonia people do a good job in this area. You should read some of your articles to get a detailed idea of ββthe problems and one approach to handling them.
Other important people (especially Intentional Programming and XText ) seem to be object-oriented editors, where you attach editing actions to each AST node and link each point on the screen to the AST node. Then editing actions activate certain actions (insert-character, go right, go up, ...), and he can decide how to act and how to change the screen. Perhaps you can get these editors to do something; its a little harder to practice. I used these editors; they do not feel like text editors. There are some enthusiastic users, but YMMV.
I think you should probably choose between trying to create such an editor, rather than trying to define a new langauge. Performing both at once is likely to cause you trouble.
source share