File tree 4 files changed +53
-0
lines changed
4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ use indexmap:: Equivalent ;
2
+ use std:: hash:: Hash ;
3
+
4
+ pub struct Ident {
5
+ pub name : Box < str > ,
6
+ }
7
+
8
+ pub struct IdentRef < ' a > {
9
+ pub name : & ' a str ,
10
+ }
11
+
12
+ impl < T : Into < Box < str > > > From < T > for Ident {
13
+ fn from ( name : T ) -> Self {
14
+ Self { name : name. into ( ) }
15
+ }
16
+ }
17
+
18
+ impl < ' a > From < & ' a str > for IdentRef < ' a > {
19
+ fn from ( name : & ' a str ) -> Self {
20
+ Self { name }
21
+ }
22
+ }
23
+
24
+ impl < ' a > Equivalent < Ident > for IdentRef < ' a > {
25
+ fn equivalent ( & self , key : & Ident ) -> bool {
26
+ * self . name == * key. name
27
+ }
28
+ }
29
+
30
+ impl Hash for Ident {
31
+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
32
+ self . name . hash ( state)
33
+ }
34
+ }
35
+
36
+ impl < ' a > Hash for IdentRef < ' a > {
37
+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
38
+ self . name . hash ( state)
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -312,6 +312,10 @@ impl<T: Text + Send> Lexer<T> {
312
312
state. identifier . push ( self . characters . next ( ) . unwrap ( ) . 0 ) ;
313
313
Waiting
314
314
}
315
+ Character :: At ( '/' , _) if self . characters . peek_nth ( 1 ) . is_alphabetic ( ) => {
316
+ state. identifier . push ( self . characters . next ( ) . unwrap ( ) . 0 ) ;
317
+ Waiting
318
+ }
315
319
Character :: At ( '<' , _)
316
320
if matches ! ( state. identifier. as_str( ) , "struct" | "union" | "enum" ) =>
317
321
{
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ mod compiler;
16
16
mod data_units;
17
17
mod diagnostics;
18
18
mod generate_workspace;
19
+ mod ident;
19
20
mod index_map_ext;
20
21
mod inflow;
21
22
mod interpreter;
Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ impl Character {
47
47
}
48
48
}
49
49
50
+ #[ inline]
51
+ pub fn is_alphabetic ( & self ) -> bool {
52
+ match self {
53
+ Character :: At ( c, _) => c. is_alphabetic ( ) ,
54
+ Character :: End ( _) => false ,
55
+ }
56
+ }
57
+
50
58
#[ inline]
51
59
pub fn is_c_non_digit ( & self ) -> bool {
52
60
// NOTE: We support the extension of using '$' in identifier/non-digit character
You can’t perform that action at this time.
0 commit comments