Files
2026-11-19 04:54:17 -06:00

45 lines
1.1 KiB
Plaintext

#! @file attribute.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains the parsing of attributes, written `@name` or `@name{ fields }`
#! before a declaration.
module sakura::analyzer;
#! The attributes before a declaration, as `@name` or `@name{ fields }`.
#! @param this The parser.
#! @returns The run of `attribute` nodes, empty when there are none.
def parser::attributes(&mut this): u32 {
val mark := this.mark;
while this.check(tk::attr) {
val made := this.attribute();
break if made == 0;
this.push(made);
}
return this.make_run(mark);
}
#! One attribute, from its `@`, whose value is the struct literal written, so
#! `@name` is `name{}`.
#! @param this The parser.
#! @returns The `attribute` node, or 0 where no type follows the `@`.
def parser::attribute(&mut this): u32 {
val token := this.index;
this.advance();
val type_name := this.type_name();
return 0 if this.syntax.node_kinds[type_name] == nk::error;
return this.make_node(
nk::attribute,
token,
type_name,
this.check(tk::lbrace)
? this.field_list()
: 0
);
}