Chisel
Overview
The language-agnostic foundation Notch is built on
Chisel is Notch's internal toolkit for building tokenizers, parsers, and type coercions. The Notch language is built on top of chisel; you can use the same primitives to build your own JVM-hosted languages.
Audience: this section is for embedders and language designers. If you only want to use Notch as a scripting language, you do not need to read this. Start at Syntax Overview or REPL Getting Started.
What chisel provides
Chisel lives in the edu.montana.notch.chisel package and exposes:
Tokenizer- a generic tokenizer that takes pluggableTokenTypeinstances. Notch'sNotch.TOKENIZERis a chiselTokenizerconfigured with Notch-specific token types.BasicParser- a generic parser base class operating on aTokenStream.NotchParserextendsBasicParser.- Token primitives -
Token,TokenStream,TokenType.Token.EOFis the sentinel returned past the end of input, so parser loops can stop on it without bounds-checking. - Built-in token types - in
chisel/type/:TokenTypeBoolean,TokenTypeBoundary,TokenTypeCComment,TokenTypeIdentifier,TokenTypeInteger,TokenTypePattern,TokenTypePunct,TokenTypeString,TokenTypeWhitespace.TokenTypePunctis itself an enum with ~30 variants (EQ,EQ2,PLUS,DOT,QUESTION_DOT, etc.) covering common ASCII punctuation. - Source location tracking -
Locationtracks line, column, and absolute character index.Spanwraps a start and endLocation.Spannedis the interface every parsed node implements so error messages can renderfile:line:columnwith a caret. - Errors -
ParseException,TokenizeException. Both implementSpanned. - Type coercions - the
Coercionabstract class lives in the Notch runtime packageedu.montana.notch.types.coercions(not underchisel/). It is the extension point for letting the runtime bridge type mismatches during method invocation.
Why chisel exists
Notch's design goal of syntax extensibility relies on a stable foundation that other languages can also build on. By keeping the parsing and type-coercion machinery separate from Notch-language-specific code, third parties can fork the Notch surface and reuse the underlying machinery.
See also
- Extending Chisel for a worked example of writing a small language on top of chisel.
- JVM Coercions for the Notch-facing view of the coercion system.