Skip to content

feat(macros): Add TopLevelItem and Type types for quoting top-level definitions and types#5267

Merged
jfecher merged 6 commits intojf/annotationsfrom
jf/top-level-item
Jun 18, 2024
Merged

feat(macros): Add TopLevelItem and Type types for quoting top-level definitions and types#5267
jfecher merged 6 commits intojf/annotationsfrom
jf/top-level-item

Conversation

@jfecher
Copy link
Contributor

@jfecher jfecher commented Jun 17, 2024

Description

Problem*

Resolves

Summary*

Adds a TopLevelItem and Type keywords & types for quoting type definitions, functions, trait impls, etc. and types respectively. The former is needed to identify items which can be unquoted at the top-level of a file - e.g. to prevent random expressions from being unquoted at the top level and to prevent trait impls from being unquoted in the middle of a function.

Additional Context

There is no way currently to create a TopLevelItem. The intended method is to be able to specify the type you want to quote in a quote expression: quote TopLevelItem { ... } but our current parser makes this very difficult since the top level statement parser would need to become recursive and be passed down through each function. For now I'm planning to have compiler API function's as a work around - e.g:

impl TopLevelItem {
    #[builtin(new_trait_impl)]
    pub fn new_trait_impl(generics: Vec<String>, trait: Type, typ: Type, methods: Vec<TopLevelItem>) -> TopLevelItem { }
}

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher jfecher requested review from a team and TomAFrench June 17, 2024 18:09
@jfecher jfecher changed the base branch from master to jf/annotations June 17, 2024 18:10
@jfecher jfecher merged commit 7fe9ced into jf/annotations Jun 18, 2024
@jfecher jfecher deleted the jf/top-level-item branch June 18, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants