morgana-core

Crates.iomorgana-core
lib.rsmorgana-core
version0.1.7
sourcesrc
created_at2023-11-29 17:12:46.396303
updated_at2023-12-09 16:52:45.432403
descriptionCore libraries for the Morgana metalanguage
homepagehttps://github.com/broceliande-labs/morgana-core
repositoryhttps://github.com/broceliande-labs/morgana-core
max_upload_size
id1053343
size305,445
edoardo (xdoardo)

documentation

README

⚠️ Morgana is still in early stage. ⚠️

Morgana

Morgana is a declarative language that allows users to define the datatypes of the AST of a language together with their syntax rules.

Why?

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

  • if we have the objective of automatically giving meaningful names to the nodes of the tree - by using EBNF rules only such as
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.

Usage

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.

Commit count: 15

cargo fmt