From c9318e046c44fd3c161ff1253eb41c108e4733e3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 2 Feb 2018 22:08:14 +0300 Subject: G: extern functions --- src/parser/event_parser/grammar/items/mod.rs | 43 +++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/parser/event_parser/grammar') diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 4d8783735..a6d8f375c 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs @@ -19,18 +19,36 @@ fn item(p: &mut Parser) { visibility(p); let la = p.nth(1); let item_kind = match p.current() { + USE_KW => { + use_item(p); + USE_ITEM + } EXTERN_KW if la == CRATE_KW => { extern_crate_item(p); EXTERN_CRATE_ITEM } + EXTERN_KW => { + abi(p); + match p.current() { + FN_KW => { + fn_item(p); + FN_ITEM + } + L_CURLY => { + extern_block(p); + EXTERN_BLOCK + } + _ => { + item.abandon(p); + p.error().message("expected `fn` or `{`").emit(); + return; + } + } + } MOD_KW => { mod_item(p); MOD_ITEM } - USE_KW => { - use_item(p); - USE_ITEM - } STRUCT_KW => { structs::struct_item(p); STRUCT_ITEM @@ -155,6 +173,12 @@ fn mod_item(p: &mut Parser) { } } +fn extern_block(p: &mut Parser) { + assert!(p.at(L_CURLY)); + p.bump(); + p.expect(R_CURLY); +} + pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool { kind == STAR || kind == L_CURLY } @@ -225,6 +249,17 @@ fn use_item(p: &mut Parser) { } } +fn abi(p: &mut Parser) { + assert!(p.at(EXTERN_KW)); + let abi = p.start(); + p.bump(); + match p.current() { + STRING | RAW_STRING => p.bump(), + _ => (), + } + abi.complete(p, ABI); +} + fn fn_item(p: &mut Parser) { assert!(p.at(FN_KW)); p.bump(); -- cgit v1.2.3