rust/src/parser/event_parser/grammar/attributes.rs

80 lines
1.8 KiB
Rust
Raw Normal View History

2018-01-07 12:46:10 -06:00
use super::*;
pub(super) fn inner_attributes(p: &mut Parser) {
2018-01-20 15:31:29 -06:00
while p.at([POUND, EXCL]) {
attribute(p, true)
}
2018-01-07 12:46:10 -06:00
}
2018-01-11 14:01:12 -06:00
pub(super) fn outer_attributes(p: &mut Parser) {
2018-01-20 15:31:29 -06:00
while p.at(POUND) {
attribute(p, false)
}
2018-01-07 12:46:10 -06:00
}
2018-01-27 17:31:23 -06:00
fn attribute(p: &mut Parser, inner: bool) {
2018-01-20 15:31:29 -06:00
let attr = p.start();
assert!(p.at(POUND));
p.bump();
if inner {
assert!(p.at(EXCL));
2018-01-20 12:49:58 -06:00
p.bump();
2018-01-08 13:40:14 -06:00
}
2018-01-20 15:31:29 -06:00
if p.expect(L_BRACK) {
meta_item(p);
p.expect(R_BRACK);
}
attr.complete(p, ATTR);
2018-01-07 12:46:10 -06:00
}
2018-01-20 15:31:29 -06:00
fn meta_item(p: &mut Parser) {
2018-01-20 12:49:58 -06:00
if p.at(IDENT) {
2018-01-20 14:25:34 -06:00
let meta_item = p.start();
2018-01-20 12:49:58 -06:00
p.bump();
2018-01-20 15:31:29 -06:00
match p.current() {
EQ => {
p.bump();
if !expressions::literal(p) {
2018-01-27 17:31:23 -06:00
p.error().message("expected literal").emit();
2018-01-20 15:31:29 -06:00
}
2018-01-07 12:46:10 -06:00
}
2018-01-20 15:31:29 -06:00
L_PAREN => meta_item_arg_list(p),
_ => (),
2018-01-07 12:46:10 -06:00
}
2018-01-20 14:25:34 -06:00
meta_item.complete(p, META_ITEM);
2018-01-20 12:49:58 -06:00
} else {
2018-01-27 17:31:23 -06:00
p.error().message("expected attribute value").emit()
2018-01-20 12:49:58 -06:00
}
2018-01-07 12:46:10 -06:00
}
2018-01-20 15:31:29 -06:00
fn meta_item_arg_list(p: &mut Parser) {
assert!(p.at(L_PAREN));
p.bump();
loop {
match p.current() {
EOF | R_PAREN => break,
IDENT => meta_item(p),
c => if !expressions::literal(p) {
let message = "expected attribute";
2018-01-07 12:46:10 -06:00
2018-01-20 15:31:29 -06:00
if items::ITEM_FIRST.contains(c) {
p.error().message(message).emit();
return;
}
let err = p.start();
p.error().message(message).emit();
p.bump();
err.complete(p, ERROR);
2018-01-27 17:31:23 -06:00
continue;
},
2018-01-20 15:31:29 -06:00
}
if !p.at(R_PAREN) {
p.expect(COMMA);
}
}
p.expect(R_PAREN);
}