diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer/mod.rs | 2 | ||||
-rw-r--r-- | src/parser/event_parser/grammar.rs | 26 | ||||
-rw-r--r-- | src/parser/event_parser/parser.rs | 8 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 8 |
4 files changed, 35 insertions, 9 deletions
diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index bc5344b5f..842059a42 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs | |||
@@ -129,7 +129,7 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { | |||
129 | ptr.bump(); | 129 | ptr.bump(); |
130 | NEQ | 130 | NEQ |
131 | } | 131 | } |
132 | _ => NOT, | 132 | _ => EXCL, |
133 | }, | 133 | }, |
134 | '-' => return if ptr.next_is('>') { | 134 | '-' => return if ptr.next_is('>') { |
135 | ptr.bump(); | 135 | ptr.bump(); |
diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index 09b2f02b2..d657ee1cd 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs | |||
@@ -17,10 +17,6 @@ pub fn file(p: &mut Parser) { | |||
17 | }) | 17 | }) |
18 | } | 18 | } |
19 | 19 | ||
20 | fn inner_attributes(_: &mut Parser) { | ||
21 | //TODO | ||
22 | } | ||
23 | |||
24 | fn item_first(p: &Parser) -> bool { | 20 | fn item_first(p: &Parser) -> bool { |
25 | let current = match p.current() { | 21 | let current = match p.current() { |
26 | Some(c) => c, | 22 | Some(c) => c, |
@@ -58,6 +54,20 @@ fn fn_item(p: &mut Parser) { | |||
58 | 54 | ||
59 | // Paths, types, attributes, and stuff // | 55 | // Paths, types, attributes, and stuff // |
60 | 56 | ||
57 | fn inner_attributes(p: &mut Parser) { | ||
58 | many(p, inner_attribute) | ||
59 | } | ||
60 | |||
61 | fn inner_attribute(p: &mut Parser) -> bool { | ||
62 | if !(p.lookahead(&[EXCL, POUND])) { | ||
63 | return false; | ||
64 | } | ||
65 | node(p, ATTR, |p| { | ||
66 | p.bump_n(2); | ||
67 | }); | ||
68 | true | ||
69 | } | ||
70 | |||
61 | fn outer_attributes(_: &mut Parser) { | 71 | fn outer_attributes(_: &mut Parser) { |
62 | } | 72 | } |
63 | 73 | ||
@@ -143,9 +153,15 @@ impl<'p> Parser<'p> { | |||
143 | } | 153 | } |
144 | } | 154 | } |
145 | 155 | ||
146 | pub(crate) fn optional(&mut self, kind: SyntaxKind) { | 156 | fn optional(&mut self, kind: SyntaxKind) { |
147 | if self.current_is(kind) { | 157 | if self.current_is(kind) { |
148 | self.bump(); | 158 | self.bump(); |
149 | } | 159 | } |
150 | } | 160 | } |
161 | |||
162 | fn bump_n(&mut self, n: u8) { | ||
163 | for _ in 0..n { | ||
164 | self.bump(); | ||
165 | } | ||
166 | } | ||
151 | } \ No newline at end of file | 167 | } \ No newline at end of file |
diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index eafa03521..f8330af4e 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs | |||
@@ -86,6 +86,14 @@ impl<'t> Parser<'t> { | |||
86 | Some(kind) | 86 | Some(kind) |
87 | } | 87 | } |
88 | 88 | ||
89 | pub(crate) fn lookahead(&self, kinds: &[SyntaxKind]) -> bool { | ||
90 | if self.non_ws_tokens[self.pos..].len() < kinds.len() { | ||
91 | return false | ||
92 | } | ||
93 | kinds.iter().zip(self.non_ws_tokens[self.pos..].iter()) | ||
94 | .all(|(&k1, &(idx, _))| k1 == self.raw_tokens[idx].kind) | ||
95 | } | ||
96 | |||
89 | pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool { | 97 | pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool { |
90 | let old_level = self.curly_level; | 98 | let old_level = self.curly_level; |
91 | let old_limit = self.curly_limit; | 99 | let old_limit = self.curly_limit; |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 6099cd6e0..67c840a3e 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -38,7 +38,7 @@ pub const EQ: SyntaxKind = SyntaxKind(33); | |||
38 | pub const EQEQ: SyntaxKind = SyntaxKind(34); | 38 | pub const EQEQ: SyntaxKind = SyntaxKind(34); |
39 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(35); | 39 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(35); |
40 | pub const NEQ: SyntaxKind = SyntaxKind(36); | 40 | pub const NEQ: SyntaxKind = SyntaxKind(36); |
41 | pub const NOT: SyntaxKind = SyntaxKind(37); | 41 | pub const EXCL: SyntaxKind = SyntaxKind(37); |
42 | pub const LIFETIME: SyntaxKind = SyntaxKind(38); | 42 | pub const LIFETIME: SyntaxKind = SyntaxKind(38); |
43 | pub const CHAR: SyntaxKind = SyntaxKind(39); | 43 | pub const CHAR: SyntaxKind = SyntaxKind(39); |
44 | pub const BYTE: SyntaxKind = SyntaxKind(40); | 44 | pub const BYTE: SyntaxKind = SyntaxKind(40); |
@@ -62,8 +62,9 @@ pub const FILE: SyntaxKind = SyntaxKind(57); | |||
62 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(58); | 62 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(58); |
63 | pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(59); | 63 | pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(59); |
64 | pub const FN_ITEM: SyntaxKind = SyntaxKind(60); | 64 | pub const FN_ITEM: SyntaxKind = SyntaxKind(60); |
65 | pub const ATTR: SyntaxKind = SyntaxKind(61); | ||
65 | 66 | ||
66 | static INFOS: [SyntaxInfo; 61] = [ | 67 | static INFOS: [SyntaxInfo; 62] = [ |
67 | SyntaxInfo { name: "USE_KW" }, | 68 | SyntaxInfo { name: "USE_KW" }, |
68 | SyntaxInfo { name: "FN_KW" }, | 69 | SyntaxInfo { name: "FN_KW" }, |
69 | SyntaxInfo { name: "STRUCT_KW" }, | 70 | SyntaxInfo { name: "STRUCT_KW" }, |
@@ -101,7 +102,7 @@ static INFOS: [SyntaxInfo; 61] = [ | |||
101 | SyntaxInfo { name: "EQEQ" }, | 102 | SyntaxInfo { name: "EQEQ" }, |
102 | SyntaxInfo { name: "FAT_ARROW" }, | 103 | SyntaxInfo { name: "FAT_ARROW" }, |
103 | SyntaxInfo { name: "NEQ" }, | 104 | SyntaxInfo { name: "NEQ" }, |
104 | SyntaxInfo { name: "NOT" }, | 105 | SyntaxInfo { name: "EXCL" }, |
105 | SyntaxInfo { name: "LIFETIME" }, | 106 | SyntaxInfo { name: "LIFETIME" }, |
106 | SyntaxInfo { name: "CHAR" }, | 107 | SyntaxInfo { name: "CHAR" }, |
107 | SyntaxInfo { name: "BYTE" }, | 108 | SyntaxInfo { name: "BYTE" }, |
@@ -125,6 +126,7 @@ static INFOS: [SyntaxInfo; 61] = [ | |||
125 | SyntaxInfo { name: "STRUCT_ITEM" }, | 126 | SyntaxInfo { name: "STRUCT_ITEM" }, |
126 | SyntaxInfo { name: "STRUCT_FIELD" }, | 127 | SyntaxInfo { name: "STRUCT_FIELD" }, |
127 | SyntaxInfo { name: "FN_ITEM" }, | 128 | SyntaxInfo { name: "FN_ITEM" }, |
129 | SyntaxInfo { name: "ATTR" }, | ||
128 | ]; | 130 | ]; |
129 | 131 | ||
130 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { | 132 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { |