Crates.io | morgana-core |
lib.rs | morgana-core |
version | 0.1.7 |
source | src |
created_at | 2023-11-29 17:12:46.396303 |
updated_at | 2023-12-09 16:52:45.432403 |
description | Core libraries for the Morgana metalanguage |
homepage | https://github.com/broceliande-labs/morgana-core |
repository | https://github.com/broceliande-labs/morgana-core |
max_upload_size | |
id | 1053343 |
size | 305,445 |
⚠️ Morgana is still in early stage. ⚠️
Morgana is a declarative language that allows users to define the datatypes of the AST of a language together with their syntax rules.
Most compilers generator tend to overlook the aspect of the generation of the AST, which can be as tedious as writing a parser or a lexer. This formalism aims at providing a single declarative specification that cleanly and concisely allows to represent the nodes of the AST of a language together with their introduction rules, that is, their syntax rules.
Once a specification is in place, the user will be able to generate automatically code for the AST, lexer, parser, pretty printer and hopefully also a skeleton for the LSP. Morgana itself is not a CLI or a library, Morgana is the formalism; ideally, various adoption of the format will allow more generators for spurious objectives.
Consider the following Morg.
-- Simple arithmetic expressions
ast Expressions
node Expression :=
| Num : u32
| Mul : Expression '*' Expression
| Div : Expression '/' Expression
| Sum : Expression '+' Expression
| Min : Expression '-' Expression
Analysing the Morg, a Rust generator (for example) can generate an AST in a form such as
pub enum Expression {
Num(u32),
Mul(Box<Expression>, Box<Expression>),
...
}
together with a parser, automatically. It is clear that this would not be possible
Expression := Expression '*' Expression
| Expression '/' Expression
| Expression '+' Expression
| Expression '-' Expression
as, simply, no information regarding the structure of the AST is embedded in the rules: we would need another formalism or implement by hand the AST.
Remember that Morgana is in early stage and we are trying to figure out the best way to do what we plan. In general, the usage is as shown here:
flowchart TD
subgraph Z[" "]
direction LR
lang.morg --> parser
parser --> MorgAst
MorgAst --> AST-IR
MorgAst --> EBNF-IR
AST-IR --> ASTGen
EBNF-IR --> ParserGen
end
where MorgAst
is the internal representation of the structure of the language represented in the metalanguage and AST-IR
and EBNF-IR
are internal representation of the AST of the language as represented in the Morg and of the syntax of the language, respectively.