Add @rust-attr on scturct (#2785)

Fixes: #2660
This commit is contained in:
Amirhossein Akhlaghpour 2023-06-05 17:59:55 +03:30 committed by GitHub
parent bef2e3617d
commit 3a4f3c61d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 196 additions and 16 deletions

View file

@ -4,6 +4,7 @@
use super::element::{parse_element, parse_element_content};
use super::prelude::*;
use super::r#type::parse_struct_declaration;
use crate::parser::r#type::parse_rustattr;
#[cfg_attr(test, parser_test)]
/// ```test,Document
@ -45,6 +46,35 @@ pub fn parse_document(p: &mut impl Parser) -> bool {
break;
}
}
"@" if p.nth(1).as_str() == "rust-attr" => {
let mut is_export = false;
let mut i = 0;
loop {
let value = p.nth(i);
if value.as_str() == ")" && p.nth(i + 1).as_str() == "export" {
is_export = true;
break;
} else if (value.as_str() == ")"
&& p.nth(i + 1).as_str() != "struct"
&& p.nth(i + 1).as_str() != "export"
&& p.nth(i + 1).as_str() != ")")
|| (value.as_str() == ")" && p.nth(i + 1).as_str() == "struct")
{
break;
}
i += 1;
}
if is_export {
let mut p = p.start_node(SyntaxKind::ExportsList);
if !parse_rustattr(&mut *p) {
break;
}
} else {
if !parse_rustattr(&mut *p) {
break;
}
}
}
_ => {
if !parse_component(&mut *p) {
break;