-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de9b26d
commit 4f76824
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
crates/cairo-lang-plugins/src/plugins/inline_macros/array.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use cairo_lang_syntax::node::TypedSyntaxNode; | ||
|
||
use crate::plugins::InlineMacro; | ||
|
||
pub struct ArrayMacro; | ||
impl InlineMacro for ArrayMacro { | ||
fn append_macro_code( | ||
&self, | ||
macro_expander_data: &mut crate::plugins::InlineMacroExpanderData, | ||
db: &dyn cairo_lang_syntax::node::db::SyntaxGroup, | ||
macro_arguments: &cairo_lang_syntax::node::ast::ExprList, | ||
) { | ||
let args = macro_arguments.elements(db); | ||
let mut expanded_code = "{ | ||
let mut __array_builder_macro_result__ = ArrayTrait::new();" | ||
.to_string(); | ||
for arg in args { | ||
expanded_code.push_str(&format!( | ||
"\n __array_builder_macro_result__.append({});", | ||
arg.as_syntax_node().get_text(db) | ||
)); | ||
} | ||
expanded_code.push_str( | ||
"\n __array_builder_macro_result__ | ||
}", | ||
); | ||
macro_expander_data.result_code.push_str(&expanded_code); | ||
macro_expander_data.code_changed = true; | ||
} | ||
|
||
fn is_bracket_type_allowed( | ||
&self, | ||
db: &dyn cairo_lang_syntax::node::db::SyntaxGroup, | ||
macro_ast: &cairo_lang_syntax::node::ast::ExprInlineMacro, | ||
) -> bool { | ||
matches!( | ||
macro_ast.arguments(db), | ||
cairo_lang_syntax::node::ast::WrappedExprList::BracketedExprList(_) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod array; | ||
pub mod consteval_int; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters