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 +++++++++++++++++++++++++--- src/syntax_kinds.rs | 20 +++++++------ 2 files changed, 51 insertions(+), 12 deletions(-) (limited to 'src') 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(); diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index cd4c753a9..7577fa037 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -82,15 +82,16 @@ pub enum SyntaxKind { FILE, STRUCT_ITEM, ENUM_ITEM, + FN_ITEM, + EXTERN_CRATE_ITEM, + MOD_ITEM, + USE_ITEM, + EXTERN_BLOCK, ENUM_VARIANT, NAMED_FIELD, POS_FIELD, - FN_ITEM, - EXTERN_CRATE_ITEM, ATTR, META_ITEM, - MOD_ITEM, - USE_ITEM, USE_TREE, PATH, PATH_SEGMENT, @@ -100,6 +101,7 @@ pub enum SyntaxKind { TYPE_PARAM_LIST, LIFETIME_PARAM, TYPE_PARAM, + ABI, // Technical SyntaxKinds: they appear temporally during parsing, // but never end up in the final tree @@ -189,15 +191,16 @@ impl SyntaxKind { FILE => &SyntaxInfo { name: "FILE" }, STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" }, ENUM_ITEM => &SyntaxInfo { name: "ENUM_ITEM" }, + FN_ITEM => &SyntaxInfo { name: "FN_ITEM" }, + EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, + MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, + USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, + EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, POS_FIELD => &SyntaxInfo { name: "POS_FIELD" }, - FN_ITEM => &SyntaxInfo { name: "FN_ITEM" }, - EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, ATTR => &SyntaxInfo { name: "ATTR" }, META_ITEM => &SyntaxInfo { name: "META_ITEM" }, - MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, - USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, USE_TREE => &SyntaxInfo { name: "USE_TREE" }, PATH => &SyntaxInfo { name: "PATH" }, PATH_SEGMENT => &SyntaxInfo { name: "PATH_SEGMENT" }, @@ -207,6 +210,7 @@ impl SyntaxKind { TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, + ABI => &SyntaxInfo { name: "ABI" }, TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, EOF => &SyntaxInfo { name: "EOF" }, -- cgit v1.2.3