ToyIDE
ToyIDE is an imitation of a full-featured IDE plus toy languages (imperative, functional) with complete IDE support, interpreters and compilers. All the parts were built from scratch in Scala, without relying on any existing code or libraries.
The project is purely educational. It is a product of a long vacation in the country and a desire to learn how all this stuff really works.
Although I applied evolutionary design in the development (to uncover the reasons behind architecture), it turns out that many techniques in the code come close to commonly used patterns. I learned a lot from the project and hope it might be useful to the people who want to know more about lexers, parsers, AST, Java bytecode and other similar fun, but tricky things.
Update: Jason Zaugg endorsed the project as “open-source Scala application with simplicity and taste”
Source code is 100% Scala (including ~800 unit tests which run in < 3 seconds).
Download binaries: toyide-1.2.4-bin.zip (7.5 MB)
Features
- Imperative language
- Functional language
- Syntax highlighting
- Advanced editor
- Split editing
- Brace matching
- Show usages
- Autocomplete
- Code formatting
- Rename refactoring
- Control / data flow analysis
- Static code optimization
- Structure pane
- Interpreter
- Compiler
- Class export
Imperative language
Imperative, statically-typed, C-like language:
- common data types & operators,
- comprehensive static analysis,
- data & control flow inspections,
- error reporting & stack traces,
- expression optimization,
- JVM bytecode emitter.
Project Euler code examples:
Functional language
Functional, dynamically-typed, Clojure-like language:
- macros, variadic functions,
- quasi-quotations, anonymous function literals,
- unique symbol name generation,
- structural binding,
- tail call optimization,
- error reporting & stack traces,
- comprehensive standard library,
Minimalistic web server code as an example:
Syntax highlighting
Expressive syntax and error highlighting, code inspections, customizable schemes:
Advanced editor
Editor with selection, copy/paste, undo/redo, braces balancing, auto-indentation:
Split editing
Editor can be split horizontally, so that viewports, cursors and selections are separate, while text is common:
Brace matching
Brace pairs are highlighted, complement braces are added / removed automatically:
Show usages
Highlighting of declaration identifier and all related references:
Autocomplete
Automatic completion of identifiers and keywords:
Code formatting
Automatic formatting of arbitrary code blocks (spacing, indentation, line breaks):
…transformed to:
Rename refactoring
For languages that rely on built-in concept of references, renaming works out-of-the-box:
…transformed to:
Control / data flow analysis
Code is checked for unused declarations and unreachable statements:
Static code optimization
Code expressions are automatically analyzed for possible simplifications:
Structure pane
Internal code representation is reflected in a structure pane (with synchronous highlighting):
Interpreter
Programs can be run by interpreter, without previously compiling them into bytecode:
Compiler
Programs can also be compiled and run as JVM bytecode:
Class export
The bytecode can be exported as runnable JVM .class files: