G: function item

This commit is contained in:
Aleksey Kladov 2018-01-07 16:01:30 +03:00
parent 7c6f0f9128
commit b5034410c8
5 changed files with 32 additions and 4 deletions

View File

@ -64,5 +64,6 @@ Grammar(
"FILE",
"STRUCT_ITEM",
"STRUCT_FIELD",
"FN_ITEM",
]
)

View File

@ -22,8 +22,12 @@ fn inner_attributes(_: &mut Parser) {
}
fn item_first(p: &Parser) -> bool {
match p.current() {
Some(STRUCT_KW) => true,
let current = match p.current() {
Some(c) => c,
None => return false,
};
match current {
STRUCT_KW | FN_KW => true,
_ => false,
}
}
@ -31,7 +35,8 @@ fn item_first(p: &Parser) -> bool {
fn item(p: &mut Parser) {
outer_attributes(p);
visibility(p);
node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item);
node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item)
|| node_if(p, FN_KW, FN_ITEM, fn_item);
}
fn struct_item(p: &mut Parser) {
@ -45,6 +50,12 @@ fn struct_field(p: &mut Parser) -> bool {
})
}
fn fn_item(p: &mut Parser) {
p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN)
&& p.curly_block(|p| ());
}
// Paths, types, attributes, and stuff //
fn outer_attributes(_: &mut Parser) {

View File

@ -61,8 +61,9 @@ pub const SHEBANG: SyntaxKind = SyntaxKind(56);
pub const FILE: SyntaxKind = SyntaxKind(57);
pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(58);
pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(59);
pub const FN_ITEM: SyntaxKind = SyntaxKind(60);
static INFOS: [SyntaxInfo; 60] = [
static INFOS: [SyntaxInfo; 61] = [
SyntaxInfo { name: "USE_KW" },
SyntaxInfo { name: "FN_KW" },
SyntaxInfo { name: "STRUCT_KW" },
@ -123,6 +124,7 @@ static INFOS: [SyntaxInfo; 60] = [
SyntaxInfo { name: "FILE" },
SyntaxInfo { name: "STRUCT_ITEM" },
SyntaxInfo { name: "STRUCT_FIELD" },
SyntaxInfo { name: "FN_ITEM" },
];
pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo {

View File

@ -0,0 +1,2 @@
fn foo() {
}

View File

@ -0,0 +1,12 @@
FILE@[0; 13)
FN_ITEM@[0; 13)
FN_KW@[0; 2)
WHITESPACE@[2; 3)
IDENT@[3; 6)
L_PAREN@[6; 7)
R_PAREN@[7; 8)
WHITESPACE@[8; 9)
L_CURLY@[9; 10)
WHITESPACE@[10; 11)
R_CURLY@[11; 12)
WHITESPACE@[12; 13)