Skip to content

Commit

Permalink
Started working on namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Sep 17, 2024
1 parent dae296e commit c21e06c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/ident.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use indexmap::Equivalent;
use std::hash::Hash;

pub struct Ident {
pub name: Box<str>,
}

pub struct IdentRef<'a> {
pub name: &'a str,
}

impl<T: Into<Box<str>>> From<T> for Ident {
fn from(name: T) -> Self {
Self { name: name.into() }
}
}

impl<'a> From<&'a str> for IdentRef<'a> {
fn from(name: &'a str) -> Self {
Self { name }
}
}

impl<'a> Equivalent<Ident> for IdentRef<'a> {
fn equivalent(&self, key: &Ident) -> bool {
*self.name == *key.name
}
}

impl Hash for Ident {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state)
}
}

impl<'a> Hash for IdentRef<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state)
}
}
4 changes: 4 additions & 0 deletions src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ impl<T: Text + Send> Lexer<T> {
state.identifier.push(self.characters.next().unwrap().0);
Waiting
}
Character::At('/', _) if self.characters.peek_nth(1).is_alphabetic() => {
state.identifier.push(self.characters.next().unwrap().0);
Waiting
}
Character::At('<', _)
if matches!(state.identifier.as_str(), "struct" | "union" | "enum") =>
{
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod compiler;
mod data_units;
mod diagnostics;
mod generate_workspace;
mod ident;
mod index_map_ext;
mod inflow;
mod interpreter;
Expand Down
8 changes: 8 additions & 0 deletions src/text/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ impl Character {
}
}

#[inline]
pub fn is_alphabetic(&self) -> bool {
match self {
Character::At(c, _) => c.is_alphabetic(),
Character::End(_) => false,
}
}

#[inline]
pub fn is_c_non_digit(&self) -> bool {
// NOTE: We support the extension of using '$' in identifier/non-digit character
Expand Down

0 comments on commit c21e06c

Please sign in to comment.