Heraclitus is an open source compiler frontend written in rust. It's going to be used as a basis for programming languages such as Amber and Flame.
With heraclitus you can create your language by skipping the cumbersome lexing step and using convenience parsing methods that can get you started on your language much quicker.
The main construct that you need is the Compiler
. The compiler will tokenize your code and assemble it
in a way that you can use to create AST by implementing predefined trait that helps you parse your code.
It's pretty simple. In order to get started you need 3 steps:
- Create lexing rules
- Create your ast nodes and let them implement trait provided by this package
- Create compiler and tie all the components together
Voilá! 🎉
Now you got yourself a ready to analyze / interpret / validate / compile AST.
Ready to get started?
use heraclitus::prelude::*;
Compiler::new("HerbScript", rules);
It is recommended to use included prelude to import just the things we will actually need.
The Compiler
requires lexer rules in order to exist.
let cc = Compiler::new("HerbScript", rules);
let tokens = cc.tokenize()?;
- Now prints newline on text errors as well as syntax errors
- Lexer is now better separated from the compiler thus easier to integrate in other projects like LSP servers
- Prevent Logger from panicking when trying to display a region that is out of bounds
Logger::text
now doesn't end with a new line
- Added
Logger::line
method that adds a new line in the end (works just like oldLogger::text
)
PositionInfo::from_between_tokens
shows the range even if the end token is None
- Bugfixes for calculating start index in tokens
- Tokens now contain information about their index of the first character in the source code
- Added
PositionInfo::from_between_tokens
method to select a region between two tokens in messages
- Fixes escapes that were handled improperly
- Remove debug information
- Heraclitus no longer panics when error happens out of bounds of file
- Escaping escape key now treats it as a character
- Escaping regions is now properly handled
- Major fix that caused the lexer to lead to an undefined behavior with defining a region that has a beginning rule longer than one character.
- Compiler now does not rely strongly on provided source code. It can now open files from path if provided. This can improve drastically performance of the compiler when working with imports.
- Show elapsed time in parser debug mode
- Offset now supports negative values
- Token now derives Default trait
- Message now does not consumes itself when it's being displayed
- Removed
warn*
andinfo*
macros as we don't see any reason to use them at this point
- Added
error_at
,warn_at
,info_at
macros
- Breaking change: All new Failing API
- Syntax Result now returns Failing enum
- Errors are now encouraged to be propagated back to the root of the AST.
- Added
context
macro to support better developer experience
- Tracebacks
- Terminal colors (support for non-truecolor consoles)
- Logger now prints errors to STDERR
- Multiline regions wouldn't parse
- Added support for UTF symbols
- Critical bug with non-tokenizable regions being tokenized
- Changed Logger API that improves adding code snippets
Logger::new_err
is now calledLogger::new_err_at_position
Logger::new_warn
is now calledLogger::new_warn_at_position
Logger::new_info
is now calledLogger::new_info_at_position
- Bad token highlighting in Logger when showing a code snippet
- Major bug with a tokenised interpolation being parsed in a wrong way.
- Intensively used code is now inlined at compile time
ErrorDetails::from_token_option(...)
can now be used to create errors at location of given token
- Added compounds
- Logger can now display messages not related to code
- New method for retrieving current token
- New debug functionality
- Changed string reference of all function parameters to
impl AsRef<str>