Kamo
This is the release of the first module of the Kamo project. Kamo (カモ) is japanese for duck.
Parser Combinator Library kamo::parser
This module implements a parser combinator library. The library is focused on parsing UTF-8 text in a safe and mostly zero-copy way. It is designed to be used to implement parsers for programming languages. It is not designed to be used to parse binary data.
One design goal of this library is to make it easy to write parsers that keep track of the position of the input and the cause of the error. The position is tracked automatically by its offset in bytes from the begining of the input and the line and column number in UTF-8 characters. The cause of the error is tracked by a stack of causes in the error. The stack is used to keep track of multiple causes of one error. The cause is added to the stack when a parser fails and holds the position, error code and a message. The error code is used to identify the cause of the error. Typically parsers wich take other parsers as input will add a cause to the stack when the input parser fails.
Example
Example of a parser that parses a Scheme-like byte-vector and returns it as
Vec<u8>.
The grammar is defined as follows:
ByteVector = "#u8(" Byte* ')'
Byte = <any exact integer between 0 and 255>
The parser is defined as follows:
use ;
Feature List
- Module
kamo::parserfor parsing UTF-8 text. A parser combinator library for parsing UTF-8 text in a safe and mostly zero-copy way. - Module
kamo::memfor automatic memory management. Values are allocated in a mutator which holds an arena allocator for each type. Memory collection is done by a mark and sweep garbage collector. - Module
kamo::valuefor values. Values can either hold immediate values or pointers to values allocated in the mutator. - Module
kamo::evalfor evaluation. The evaluator processes an AST, which is an symbolic expression tree, and evaluates it to an intermediate representation. The intermediate representation can then be interpreted or compiled to a target representation. The interpreter is generic and can be used to interpret any intermediate representation. - Module
kamo::typesfor types. The type system is used to infer the types of the intermediate representation and the AST. - Module
kamo::replfor a read-eval-print-loop. The REPL is used to interactively evaluate expressions and is generic and can be used to evaluate any intermediate representation. - Module
kamo::lang::schemefor the Scheme language. The Scheme language is implemented as a library on top of thekamomodules. It implements a subset of the R7RS standard.