G: static items

This commit is contained in:
Aleksey Kladov 2018-02-02 23:45:15 +03:00
parent 049c9b60fb
commit 0000f4f4f2
7 changed files with 68 additions and 9 deletions

View File

@ -24,6 +24,7 @@ Grammar(
"match",
"const",
"static",
"mut",
],
tokens: [
"ERROR",
@ -87,6 +88,7 @@ Grammar(
"EXTERN_CRATE_ITEM",
"MOD_ITEM",
"USE_ITEM",
"STATIC_ITEM",
"EXTERN_BLOCK",
"ENUM_VARIANT",

View File

@ -46,6 +46,10 @@ fn item(p: &mut Parser) {
}
}
}
STATIC_KW => {
static_item(p);
STATIC_ITEM
}
MOD_KW => {
mod_item(p);
MOD_ITEM
@ -92,6 +96,24 @@ fn extern_crate_item(p: &mut Parser) {
p.expect(IDENT) && alias(p) && p.expect(SEMI);
}
fn extern_block(p: &mut Parser) {
assert!(p.at(L_CURLY));
p.bump();
p.expect(R_CURLY);
}
fn static_item(p: &mut Parser) {
assert!(p.at(STATIC_KW));
p.bump();
p.eat(MUT_KW);
p.expect(IDENT);
p.expect(COLON);
types::type_ref(p);
p.expect(EQ);
expressions::expr(p);
p.expect(SEMI);
}
fn mod_item(p: &mut Parser) {
assert!(p.at(MOD_KW));
p.bump();
@ -104,12 +126,6 @@ fn mod_item(p: &mut Parser) {
}
}
fn extern_block(p: &mut Parser) {
assert!(p.at(L_CURLY));
p.bump();
p.expect(R_CURLY);
}
fn abi(p: &mut Parser) {
assert!(p.at(EXTERN_KW));
let abi = p.start();

View File

@ -30,6 +30,7 @@ pub enum SyntaxKind {
MATCH_KW,
CONST_KW,
STATIC_KW,
MUT_KW,
ERROR,
IDENT,
UNDERSCORE,
@ -88,6 +89,7 @@ pub enum SyntaxKind {
EXTERN_CRATE_ITEM,
MOD_ITEM,
USE_ITEM,
STATIC_ITEM,
EXTERN_BLOCK,
ENUM_VARIANT,
NAMED_FIELD,
@ -141,6 +143,7 @@ impl SyntaxKind {
MATCH_KW => &SyntaxInfo { name: "MATCH_KW" },
CONST_KW => &SyntaxInfo { name: "CONST_KW" },
STATIC_KW => &SyntaxInfo { name: "STATIC_KW" },
MUT_KW => &SyntaxInfo { name: "MUT_KW" },
ERROR => &SyntaxInfo { name: "ERROR" },
IDENT => &SyntaxInfo { name: "IDENT" },
UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" },
@ -199,6 +202,7 @@ impl SyntaxKind {
EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" },
MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" },
USE_ITEM => &SyntaxInfo { name: "USE_ITEM" },
STATIC_ITEM => &SyntaxInfo { name: "STATIC_ITEM" },
EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" },
ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" },
NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" },
@ -248,6 +252,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {
"match" => Some(MATCH_KW),
"const" => Some(CONST_KW),
"static" => Some(STATIC_KW),
"mut" => Some(MUT_KW),
_ => None,
}
}

View File

@ -1,2 +1,3 @@
fn use struct trait enum impl true false as extern crate
mod pub self super in where for loop while if match const static
mod pub self super in where for loop while if match const
static mut

View File

@ -43,6 +43,8 @@ WHITESPACE 1 " "
MATCH_KW 5 "match"
WHITESPACE 1 " "
CONST_KW 5 "const"
WHITESPACE 1 " "
STATIC_KW 6 "static"
WHITESPACE 1 "\n"
STATIC_KW 6 "static"
WHITESPACE 1 " "
MUT_KW 3 "mut"
WHITESPACE 1 "\n"

View File

@ -0,0 +1,2 @@
static FOO: u32 = 1;
static mut BAR: i32 = 92;

View File

@ -0,0 +1,31 @@
FILE@[0; 47)
STATIC_ITEM@[0; 21)
STATIC_KW@[0; 6)
WHITESPACE@[6; 7)
IDENT@[7; 10) "FOO"
COLON@[10; 11)
WHITESPACE@[11; 12)
IDENT@[12; 15) "u32"
WHITESPACE@[15; 16)
EQ@[16; 17)
LITERAL@[17; 19)
WHITESPACE@[17; 18)
INT_NUMBER@[18; 19)
SEMI@[19; 20)
WHITESPACE@[20; 21)
STATIC_ITEM@[21; 47)
STATIC_KW@[21; 27)
WHITESPACE@[27; 28)
MUT_KW@[28; 31)
WHITESPACE@[31; 32)
IDENT@[32; 35) "BAR"
COLON@[35; 36)
WHITESPACE@[36; 37)
IDENT@[37; 40) "i32"
WHITESPACE@[40; 41)
EQ@[41; 42)
LITERAL@[42; 45)
WHITESPACE@[42; 43)
INT_NUMBER@[43; 45)
SEMI@[45; 46)
WHITESPACE@[46; 47)