Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the import statement of molecule for the codegen #643

Closed
homura opened this issue Mar 4, 2024 · 0 comments · Fixed by #648
Closed

Support the import statement of molecule for the codegen #643

homura opened this issue Mar 4, 2024 · 0 comments · Fixed by #648
Milestone

Comments

@homura
Copy link
Collaborator

homura commented Mar 4, 2024

The first version of the codegen doesn't support the import statement of Molecule yet. To deal with the cases of importing other schemas, the codegen CLI also needs to

  1. resolve all import schema items
  2. remove the intersection with prepend
  3. append them to the prepend

Originally posted by @homura in #635 (comment)

Note:

The parser of Molecule written in JS doesn't support the import statement, therefore, it is better to handle the import statement separately. The instructions for handling the import feature could be

  1. resolve the items from the import statement
  2. convert the exported items into ESM syntax and append these items into the prepend
  3. erase the import clause from the schema when calling the codegen method
  4. generate code recursively and name outputs the same with schema's

For example, now we have 2 schema files, base and character

// base.mol

array RGB [byte;3];
vector UTF8String <byte>;
// character.mol

import base;

table Character {
  hair_color: RGB, 
  name: UTF8String,
}

After the codegen, it should be

// base.ts
export const RGB = array(byte, 3);
export const UTF8String = vector(byte);
// character.ts

import { RGB, UTF8String } from './base'

export const Character = table({
  hair_color: RGB,
  name: UTF8String,
}, ['hair_color', 'name'])
@homura homura added this to the 0.22.0 milestone Mar 5, 2024
coder-van pushed a commit to Web3-City-0X07/lumos that referenced this issue Mar 5, 2024
@homura homura mentioned this issue Mar 6, 2024
4 tasks
coder-van pushed a commit to Web3-City-0X07/lumos that referenced this issue Mar 6, 2024
coder-van pushed a commit to Web3-City-0X07/lumos that referenced this issue Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant