Skip to content

mbti_parser: Missing support for pub impl, pub using, pub let #96

@mizchi

Description

@mizchi

Summary

The mbti_parser does not support several visibility-prefixed constructs that are used in official MoonBit toolchain-generated .mbti files.

Affected Patterns

1. pub impl

pub impl ToJson for FooterColumn
pub impl Add for BigInt

2. pub using

pub using @builtin {type ArrayView as View}

3. pub let

pub let null : Json
pub let max_value : Byte

Evidence

These patterns are present in the official MoonBit core library's .mbti files:

$ grep -r "^pub impl" ~/.moon/lib/core/**/*.mbti | head -3
/Users/.../.moon/lib/core/bench/pkg.generated.mbti:pub impl ToJson for Summary
/Users/.../.moon/lib/core/bigint/pkg.generated.mbti:pub impl Add for BigInt
...

$ grep -r "^pub using" ~/.moon/lib/core/**/*.mbti | head -3
/Users/.../.moon/lib/core/array/pkg.generated.mbti:pub using @builtin {type ArrayView as View}
...

$ grep -r "^pub let" ~/.moon/lib/core/**/*.mbti | head -3
/Users/.../.moon/lib/core/builtin/pkg.generated.mbti:pub let null : Json
...

Root Cause

Looking at mbti_parser/mbti_parser.mbty:

impl_sig (line 188-192)

impl_sig -> ImplSig
  : "impl" type_params_with_constraints qualified_uident "for" type_ { ... }
  | "impl" qualified_uident "for" type_ { ... }
  | "impl" uident "::" lident { ... }
  ;

The impl_sig rule starts directly with the "impl" keyword and does not accept a vis (visibility) prefix like type_sig or trait_sig do.

Missing using support

There is no grammar rule for using statements in the mbti parser.

value_sig (line 150-152)

value_sig -> ValueSig
  : attributes "let" lident ":" type_ { ... }
  ;

The value_sig rule does not accept a vis prefix.

Expected Behavior

Per CONTRIBUTING.md:

This project aims to follow the behavior of MoonBit's OCaml parser implementation when the input source has no syntax errors.

These patterns should be parseable since they are generated by the official MoonBit toolchain.

Suggested Fix

  1. Add vis prefix support to impl_sig
  2. Add using statement grammar rule
  3. Add vis prefix support to value_sig

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions