Skip to content

Commit c21e06c

Browse files
committed
Started working on namespaces
1 parent dae296e commit c21e06c

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Diff for: src/ident.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

Diff for: src/lexer/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ impl<T: Text + Send> Lexer<T> {
312312
state.identifier.push(self.characters.next().unwrap().0);
313313
Waiting
314314
}
315+
Character::At('/', _) if self.characters.peek_nth(1).is_alphabetic() => {
316+
state.identifier.push(self.characters.next().unwrap().0);
317+
Waiting
318+
}
315319
Character::At('<', _)
316320
if matches!(state.identifier.as_str(), "struct" | "union" | "enum") =>
317321
{

Diff for: src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod compiler;
1616
mod data_units;
1717
mod diagnostics;
1818
mod generate_workspace;
19+
mod ident;
1920
mod index_map_ext;
2021
mod inflow;
2122
mod interpreter;

Diff for: src/text/character.rs

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ impl Character {
4747
}
4848
}
4949

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+
5058
#[inline]
5159
pub fn is_c_non_digit(&self) -> bool {
5260
// NOTE: We support the extension of using '$' in identifier/non-digit character

0 commit comments

Comments
 (0)