Structure editors
Posted: Fri Jul 31, 2015 12:50 pm
This is probably nothing new to many of you, but at the moment I'm fascinated by the idea of a structured editor:
Let's say you have a grammar specification (like this one for Java), upon opening a file you can represent it as a syntax tree in the memory of the editor, by typing you can edit the syntax tree directly - but you're actually editing the nodes of tree rather than text although the tree is pretty printed on the screen to look like a text editor.
Pros:
- Syntax highlighting comes for free - you know what node you're printing on the screen.
- Code completion comes for close to free - you know what node you're editing - if it's an identifier, suggest declared identifiers.
- Auto-indent/etc comes for free - the code is always pretty printed in the IDE.
- Code folding comes for free - just don't print the children of that node.
- Syntax errors are impossible - the syntax tree has to always be valid.
- Refracting comes almost for free - you simply walk the node to find all references to an identifier.
- You could work with languages that are syntactically ambiguous. (I don't know why you would do this though.)
- Potentially really fast coding - since there's only so many possibilities, the editor can suggest what goes next with only a few keystrokes.
- Cool things - like drawing boxes around structures, etc. Like Lamdu does:
Cons:
- Copying and pasting might be interesting. You can only paste code in places where it would syntactically fit.
- You're enforcing code to uniformally formatted (though it could be configured in the IDE.)
Other possibilities:
- 'Strict mode' - only allow the programmer to user identifiers that have been declared somewhere. (This might get annoying, like not letting you delete a declaration of a variable that might be used somewhere.)
- You could store the syntax tree in binary form instead of text. Smaller files and potentially faster compiles, but they wouldn't be human readable in another text editor.
Since I'm designing a language for my operating system, a structure editor (and possible storing it on disk in binary format) might be interesting.
Thoughts?
Let's say you have a grammar specification (like this one for Java), upon opening a file you can represent it as a syntax tree in the memory of the editor, by typing you can edit the syntax tree directly - but you're actually editing the nodes of tree rather than text although the tree is pretty printed on the screen to look like a text editor.
Pros:
- Syntax highlighting comes for free - you know what node you're printing on the screen.
- Code completion comes for close to free - you know what node you're editing - if it's an identifier, suggest declared identifiers.
- Auto-indent/etc comes for free - the code is always pretty printed in the IDE.
- Code folding comes for free - just don't print the children of that node.
- Syntax errors are impossible - the syntax tree has to always be valid.
- Refracting comes almost for free - you simply walk the node to find all references to an identifier.
- You could work with languages that are syntactically ambiguous. (I don't know why you would do this though.)
- Potentially really fast coding - since there's only so many possibilities, the editor can suggest what goes next with only a few keystrokes.
- Cool things - like drawing boxes around structures, etc. Like Lamdu does:
Cons:
- Copying and pasting might be interesting. You can only paste code in places where it would syntactically fit.
- You're enforcing code to uniformally formatted (though it could be configured in the IDE.)
Other possibilities:
- 'Strict mode' - only allow the programmer to user identifiers that have been declared somewhere. (This might get annoying, like not letting you delete a declaration of a variable that might be used somewhere.)
- You could store the syntax tree in binary form instead of text. Smaller files and potentially faster compiles, but they wouldn't be human readable in another text editor.
Since I'm designing a language for my operating system, a structure editor (and possible storing it on disk in binary format) might be interesting.
Thoughts?