Skip to content

Commit

Permalink
Add primitive procedural macro example
Browse files Browse the repository at this point in the history
commit-id:824a01ae
  • Loading branch information
maciektr committed Jul 31, 2024
1 parent de12213 commit 3b62beb
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"utils/test-for-each-example",
"xtask",
]
exclude = ["examples/procedural_macro/some_macro"]
"resolver" = "2"

[workspace.package]
Expand Down
13 changes: 13 additions & 0 deletions examples/procedural_macro/hello_world/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "hello_world"
version = "0.1.0"
dependencies = [
"some_macro",
]

[[package]]
name = "some_macro"
version = "0.1.0"
12 changes: 12 additions & 0 deletions examples/procedural_macro/hello_world/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "hello_world"
version = "0.1.0"
edition = "2023_10"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
some_macro = { path = "../some_macro" }

[dev-dependencies]
cairo_test = "2.6.4"
2 changes: 2 additions & 0 deletions examples/procedural_macro/hello_world/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[some]
fn main() -> felt252 { 12 }
107 changes: 107 additions & 0 deletions examples/procedural_macro/some_macro/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions examples/procedural_macro/some_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "some_macro"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
cairo-lang-macro = "0.1"
5 changes: 5 additions & 0 deletions examples/procedural_macro/some_macro/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "some_macro"
version = "0.1.0"

[cairo-plugin]
7 changes: 7 additions & 0 deletions examples/procedural_macro/some_macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use cairo_lang_macro::{attribute_macro, ProcMacroResult, TokenStream};

#[attribute_macro]
pub fn some(_attr: TokenStream, token_stream: TokenStream) -> ProcMacroResult {
let token_stream = TokenStream::new(token_stream.to_string().replace("12", "34"));
ProcMacroResult::new(token_stream)
}

0 comments on commit 3b62beb

Please sign in to comment.