update syntax highlighting to use vscode dark mode theme
This commit is contained in:
@@ -118,18 +118,31 @@ public static unsafe class SlangExtensions
|
|||||||
{
|
{
|
||||||
switch (kind)
|
switch (kind)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1: // Strings
|
||||||
return SlangFormatter.ColorString; // String
|
return SlangFormatter.ColorString;
|
||||||
case 2:
|
case 2: // Numbers
|
||||||
return SlangFormatter.ColorString; // Number
|
return SlangFormatter.ColorNumber;
|
||||||
case 3:
|
case 3: // Booleans
|
||||||
return SlangFormatter.ColorInstruction; // Boolean
|
return SlangFormatter.ColorBoolean;
|
||||||
case 4:
|
|
||||||
return SlangFormatter.ColorSelection; // Keyword
|
case 4: // (if, else, loop)
|
||||||
case 5:
|
return SlangFormatter.ColorControl;
|
||||||
return SlangFormatter.ColorLineNumber; // Identifier
|
case 5: // (let, const, device)
|
||||||
case 6:
|
return SlangFormatter.ColorDeclaration;
|
||||||
return SlangFormatter.ColorDefault; // Symbol
|
|
||||||
|
case 6: // (variables)
|
||||||
|
return SlangFormatter.ColorIdentifier;
|
||||||
|
case 7: // (punctuation)
|
||||||
|
return SlangFormatter.ColorDefault;
|
||||||
|
|
||||||
|
case 10: // (syscalls)
|
||||||
|
return SlangFormatter.ColorFunction;
|
||||||
|
|
||||||
|
case 11: // Comparisons
|
||||||
|
case 12: // Math
|
||||||
|
case 13: // Logic
|
||||||
|
return SlangFormatter.ColorOperator;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return SlangFormatter.ColorDefault;
|
return SlangFormatter.ColorDefault;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,19 @@ public class SlangFormatter : ICodeFormatter
|
|||||||
private CancellationTokenSource? _lspCancellationToken;
|
private CancellationTokenSource? _lspCancellationToken;
|
||||||
private object _tokenLock = new();
|
private object _tokenLock = new();
|
||||||
|
|
||||||
public static readonly uint ColorInstruction = ColorFromHTML("#ffff00");
|
// VS Code Dark Theme Palette
|
||||||
public static readonly uint ColorString = ColorFromHTML("#ce9178");
|
public static readonly uint ColorControl = ColorFromHTML("#C586C0"); // Pink (if, return, loop)
|
||||||
|
public static readonly uint ColorDeclaration = ColorFromHTML("#569CD6"); // Blue (let, device, fn)
|
||||||
|
public static readonly uint ColorFunction = ColorFromHTML("#DCDCAA"); // Yellow (syscalls)
|
||||||
|
public static readonly uint ColorString = ColorFromHTML("#CE9178"); // Orange
|
||||||
|
public static new readonly uint ColorNumber = ColorFromHTML("#B5CEA8"); // Light Green
|
||||||
|
public static readonly uint ColorBoolean = ColorFromHTML("#569CD6"); // Blue (true/false)
|
||||||
|
public static readonly uint ColorIdentifier = ColorFromHTML("#9CDCFE"); // Light Blue (variables)
|
||||||
|
public static new readonly uint ColorDefault = ColorFromHTML("#D4D4D4"); // White (punctuation ; { } )
|
||||||
|
|
||||||
|
// Operators are often the same color as default text in VS Code Dark,
|
||||||
|
// but having a separate definition lets you tweak it (e.g. make them slightly darker or distinct)
|
||||||
|
public static readonly uint ColorOperator = ColorFromHTML("#D4D4D4");
|
||||||
|
|
||||||
private HashSet<uint> _linesWithErrors = new();
|
private HashSet<uint> _linesWithErrors = new();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
mod macros;
|
mod macros;
|
||||||
|
mod syscall;
|
||||||
|
|
||||||
/// This trait will allow the LSP to emit documentation for various tokens and expressions.
|
/// This trait will allow the LSP to emit documentation for various tokens and expressions.
|
||||||
/// You can easily create documentation for large enums with the `documented!` macro.
|
/// You can easily create documentation for large enums with the `documented!` macro.
|
||||||
@@ -10,5 +11,5 @@ pub trait Documentation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::{Documentation, documented};
|
pub use super::{Documentation, documented, with_syscalls};
|
||||||
}
|
}
|
||||||
|
|||||||
32
rust_compiler/libs/helpers/src/syscall.rs
Normal file
32
rust_compiler/libs/helpers/src/syscall.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#[macro_export]
|
||||||
|
macro_rules! with_syscalls {
|
||||||
|
($matcher:ident) => {
|
||||||
|
$matcher!(
|
||||||
|
"yield",
|
||||||
|
"sleep",
|
||||||
|
"hash",
|
||||||
|
"loadFromDevice",
|
||||||
|
"loadBatchNamed",
|
||||||
|
"loadBatch",
|
||||||
|
"setOnDevice",
|
||||||
|
"setOnDeviceBatched",
|
||||||
|
"setOnDeviceBatchedNamed",
|
||||||
|
"acos",
|
||||||
|
"asin",
|
||||||
|
"atan",
|
||||||
|
"atan2",
|
||||||
|
"abs",
|
||||||
|
"ceil",
|
||||||
|
"cos",
|
||||||
|
"floor",
|
||||||
|
"log",
|
||||||
|
"max",
|
||||||
|
"min",
|
||||||
|
"rand",
|
||||||
|
"sin",
|
||||||
|
"sqrt",
|
||||||
|
"tan",
|
||||||
|
"trunc"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -256,31 +256,6 @@ impl std::fmt::Display for SysCall {
|
|||||||
|
|
||||||
impl SysCall {
|
impl SysCall {
|
||||||
pub fn is_syscall(identifier: &str) -> bool {
|
pub fn is_syscall(identifier: &str) -> bool {
|
||||||
matches!(
|
tokenizer::token::is_syscall(identifier)
|
||||||
identifier,
|
|
||||||
"yield"
|
|
||||||
| "sleep"
|
|
||||||
| "hash"
|
|
||||||
| "loadFromDevice"
|
|
||||||
| "setOnDevice"
|
|
||||||
| "setOnDeviceBatched"
|
|
||||||
| "setOnDeviceBatchedNamed"
|
|
||||||
| "acos"
|
|
||||||
| "asin"
|
|
||||||
| "atan"
|
|
||||||
| "atan2"
|
|
||||||
| "abs"
|
|
||||||
| "ceil"
|
|
||||||
| "cos"
|
|
||||||
| "floor"
|
|
||||||
| "log"
|
|
||||||
| "max"
|
|
||||||
| "min"
|
|
||||||
| "rand"
|
|
||||||
| "sin"
|
|
||||||
| "sqrt"
|
|
||||||
| "tan"
|
|
||||||
| "trunc"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
use helpers::prelude::*;
|
use helpers::prelude::*;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
|
|
||||||
|
// Define a local macro to consume the list
|
||||||
|
macro_rules! generate_check {
|
||||||
|
($($name:literal),*) => {
|
||||||
|
pub fn is_syscall(s: &str) -> bool {
|
||||||
|
matches!(s, $($name)|*)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Token {
|
pub struct Token {
|
||||||
/// The type of the token
|
/// The type of the token
|
||||||
@@ -101,17 +110,43 @@ impl Documentation for TokenType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helpers::with_syscalls!(generate_check);
|
||||||
|
|
||||||
impl From<TokenType> for u32 {
|
impl From<TokenType> for u32 {
|
||||||
fn from(value: TokenType) -> Self {
|
fn from(value: TokenType) -> Self {
|
||||||
use TokenType::*;
|
|
||||||
match value {
|
match value {
|
||||||
String(_) => 1,
|
TokenType::String(_) => 1,
|
||||||
Number(_) => 2,
|
TokenType::Number(_) => 2,
|
||||||
Boolean(_) => 3,
|
TokenType::Boolean(_) => 3,
|
||||||
Keyword(_) => 4,
|
TokenType::Keyword(k) => match k {
|
||||||
Identifier(_) => 5,
|
Keyword::If
|
||||||
Symbol(_) => 6,
|
| Keyword::Else
|
||||||
EOF => 0,
|
| Keyword::Loop
|
||||||
|
| Keyword::While
|
||||||
|
| Keyword::Break
|
||||||
|
| Keyword::Continue
|
||||||
|
| Keyword::Return => 4,
|
||||||
|
_ => 5,
|
||||||
|
},
|
||||||
|
TokenType::Identifier(s) => {
|
||||||
|
if is_syscall(&s) {
|
||||||
|
10
|
||||||
|
} else {
|
||||||
|
6
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TokenType::Symbol(s) => {
|
||||||
|
if s.is_comparison() {
|
||||||
|
11
|
||||||
|
} else if s.is_operator() {
|
||||||
|
12
|
||||||
|
} else if s.is_logical() {
|
||||||
|
13
|
||||||
|
} else {
|
||||||
|
7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TokenType::EOF => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user