This repository contains a versatile parser for arithmetic expressions which allows customizing literal definitions, type annotations and several other aspects of parsing. The repository also contains several auxiliary crates (for example, a simple interpreter).
arithmetic-parser
is the core parsing library.arithmetic-eval
is a simple interpreter that could be used on parsed expressions in some cases. See the crate docs for more details on its limitations.arithmetic-typing
is Hindley–Milner type inference for parsed expressions.arithmetic-parser-cli
is the CLI / REPL for the library.
- The parser is designed to be reusable and customizable for simple scripting use cases. For example, it's used to dynamically define and process complex-valued functions in a Julia set renderer. Customization specifically extends to literals; e.g., it is possible to have a single numeric literal / primitive type.
- Interpreter and type inference are natural complementary tools for the parser that allow evaluating parsed ASTs and reasoning about their correctness. Again, it is possible to fully customize primitive types and their mapping from literals, as well as semantics of arithmetic ops and (in case of typing) constraints they put on operands.
- Type inference is a challenging (and therefore interesting!) problem given the requirements (being able to work without any explicit type annotations).
Early-stage; quite a bit of functionality is lacking, especially in interpreter and typing. As an example, method resolution is a mess (methods are just syntax sugar for functions).
- Scripting languages like Rhai and Gluon are significantly more mature and have a sizable standard library, but are less customizable. E.g., there is a pre-determined set of primitive types with unchangeable semantics and type constraints. Rhai also does not have parser / interpreter separation or type inference support, and Gluon's syntax is a bit academic at times.
All contributions are welcome! See the contributing guide to help you get involved.
All code in this repository is licensed under either of Apache License, Version 2.0 or MIT license at your option.