Feature: Rust-style AST-aware macros #15

Open
opened 2024-03-01 09:07:56 +00:00 by j · 0 comments
Owner

Feature Progress

  • Decide on macro syntax

  • Define AST nodes to store that syntax in

  • Implement macro syntax within parser

Feature description

Many popular programming languages have code templating/generation syntax, commonly called "macros".

Implementing some kind of macro->expansion system would go a long way toward improving the usability of Conlang.

Possible syntax

Macro           = Path '!' DelimitedTokens ;
DelimitedTokens = `'('` Tokens* `')'` | `'{'` Tokens* `'}'` | `'['` Tokens* `']'` ;
Tokens          = DelimitedTokens | Token ;

Example

// Assume there's some macro `macro_foo!` in scope

fn main () {
    let x = macro_foo!{
        {}({}){({})} "this is a macro, the contents of this delimited token tree don't matter!"
    };
    x
}

# Feature Progress <!-- Describe the steps for implementing this feature in Conlang --> - [ ] Decide on macro syntax - [ ] Define AST nodes to store that syntax in - [ ] Implement macro syntax within parser - [ ] # Feature description <!-- [Feature name] does a cool thing that you should describe here --> Many popular programming languages have code templating/generation syntax, commonly called "macros". Implementing some kind of macro->expansion system would go a long way toward improving the usability of Conlang. ## Possible syntax ```ebnf Macro = Path '!' DelimitedTokens ; DelimitedTokens = `'('` Tokens* `')'` | `'{'` Tokens* `'}'` | `'['` Tokens* `']'` ; Tokens = DelimitedTokens | Token ; ``` # Example <!-- Demonstrate this feature with a clear, concise code example Right now, we're (ab)using Rust syntax highlighting, since it most closely matches what I'm currently aiming for --> ```rust // Assume there's some macro `macro_foo!` in scope fn main () { let x = macro_foo!{ {}({}){({})} "this is a macro, the contents of this delimited token tree don't matter!" }; x } ```
j added the
enhancement
label 2024-03-01 09:07:56 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: j/Conlang#15
No description provided.