Skip to content

Commit

Permalink
highlight binary number constants
Browse files Browse the repository at this point in the history
  • Loading branch information
x87 committed Nov 24, 2023
1 parent 4bb0b45 commit a22447a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/language_service/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ fn resolve_path(p: String, parent_file: &String) -> Option<String> {
return Some(p);
}

// todo:
// If the file path is relative, the compiler scans directories in the following order to find the file:
// 1. directory of the file with the directive
// 2. data folder for the current edit mode
// 3. Sanny Builder root directory
// 4. the game directory
let dir_name = Path::new(&parent_file).parent()?;
let abs_name = dir_name.join(path);

Expand Down Expand Up @@ -365,7 +371,7 @@ pub fn process_var_declaration(
return;
}
found_constants.push((
name.to_ascii_lowercase(),
name_lower,
SymbolInfoMap {
line_number: line_number as u32,
_type: SymbolType::Var,
Expand Down Expand Up @@ -415,7 +421,8 @@ pub fn get_type(value: &str) -> Option<SymbolType> {
|| value.ends_with('@')
|| value.ends_with("@s")
|| value.ends_with("@v")
|| (value.ends_with(")") && value.contains("@(")) // arrays 0@(1@,2i)
|| (value.ends_with(")") && value.contains("@("))
// arrays 0@(1@,2i)
{
return Some(SymbolType::Var);
}
Expand All @@ -428,13 +435,19 @@ pub fn get_type(value: &str) -> Option<SymbolType> {
if value.starts_with('@') {
return Some(SymbolType::Label);
}
if value.starts_with("0x")
|| value.starts_with("-0x")
|| value.starts_with("+0x")
|| value.starts_with("0b")
|| value.starts_with("-0b")
|| value.starts_with("+0b")
{
return Some(SymbolType::Number);
}
}
if let Some(_) = value.parse::<f32>().ok() {
return Some(SymbolType::Number);
}
if value.starts_with("0x") || value.starts_with("-0x") || value.starts_with("+0x") {
return Some(SymbolType::Number);
}
return None;
}

Expand Down

0 comments on commit a22447a

Please sign in to comment.