Updated attr grammar

This commit is contained in:
2026-05-05 02:46:32 +02:00
parent 0af357df97
commit d9c20467a4
2 changed files with 21 additions and 95 deletions
+17 -10
View File
@@ -19,18 +19,25 @@ var_decl = { type_expr ~ mutable? ~ identifier }
// ================= TOP LEVEL =================
attribute_list = { sharp ~ "[" ~ attribute ~ ("," ~ attribute)* ~ "]" }
attribute = { static_path ~ attribute_args? }
attribute_args = { "(" ~ (attr_expr ~ ("," ~ attr_expr)*)? ~ ")" }
attr_expr = {
(identifier ~ "=" ~ primary)
| primary
attribute = {
"#" ~ "[" ~ (structured_style | list_style | key_value_style | simple_style) ~ "]"
}
top_level = _{ attribute_list* ~ (import | function_decl | struct_decl) }
// Simple: #[test]
simple_style = { identifier }
// Key-Value: #[crate_type = "lib"]
key_value_style = { identifier ~ "=" ~ primary }
// #[derive(PartialEq, PartialOrd)]
list_style = { identifier ~ "(" ~ identifier ~ ("," ~ identifier)* ~ ","? ~ ")" }
// #[link(name = "readline")]
structured_style = { identifier ~ "(" ~ pair ~ ("," ~ pair)* ~ ","? ~ ")" }
pair = { identifier ~ "=" ~ primary }
top_level = _{ attribute* ~ (import | function_decl | struct_decl) }
import = { sharp ~ "include" ~ "<" ~ static_path ~ ">" }