Skip to content

moonbitlang/parser

Repository files navigation

moonbitlang/parser

Note: This module is highly experimental and unstable. Use with caution.

A parser implementation for the MoonBit programming language, written in MoonBit, providing lexical analysis and syntax parsing capabilities.

This module defines the Abstract Syntax Tree (AST) and provides parsers for MoonBit source code. It includes both a hand-written LL(k) parser with error recovery and an LR(1) parser generated by moonyacc.

Project Structure

.
├── tokens/            # token definitions and utilities
├── lexer/             # Lexical analysis components
├── mbti_ast/          # AST for .mbti files
├── mbti_parser/       # LR parser for .mbti files
├── syntax/            # AST and utils for MoonBit source code
├── handrolled_parser/ # Hand-written parser implementation
├── yacc_parser/       # LR parser generated by moonyacc
├── test/              # Test suite
└── top.mbt            # parsing entries

Usage

///|
test {
  let source = "let number = 123"
  let (impls, _) = parse_string(source)
  @json.inspect(impls, content=[
    {
      "type": "Impl::TopLetDef",
      "binder": { "type": "Binder", "name": "number", "loc": null },
      "ty": null,
      "expr": {
        "type": "Expr::Constant",
        "c": { "type": "Constant::Int", "0": "123" },
        "loc": null,
      },
      "vis": { "type": "Visibility::Default" },
      "is_constant": false,
      "loc": null,
      "attrs": [],
      "doc": "",
    },
  ])
}

You can also explore the parsing results using the AST Explorer.

Build & Test

This project uses the MoonBit build system:

moon update
moon check
moon test

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •