make tokens into flags yo

This commit is contained in:
Qrakhen 2025-11-23 00:38:21 +01:00
parent 2f10015229
commit f9f2f5b81a
2 changed files with 94 additions and 87 deletions

View File

@ -336,7 +336,9 @@ public class Reader : IReader<Token>, IDisposable
Check('=') ?
MakeToken(GreaterEqual, buffer + Next()) :
MakeToken(Greater, buffer),
'~' => MakeToken(BitwiseNot, buffer),
'~' => Check('(') ?
MakeToken(Lambda, buffer) :
MakeToken(BitwiseNot, buffer),
'?' => Check('?') ?
MakeToken(DoubleQuestion, buffer + Next()) :
Check(':') ?

View File

@ -2,109 +2,114 @@
using static TokenType;
[Flags]
public enum TokenType
{
Error,
Void,
Null,
Error = -1,
Void = 0,
Eof,
NewLine,
Whitespace,
Comment,
Constant = 1 << 4,
Null = Constant | 1,
True = Constant | 2,
False = Constant | 3,
Bracket = 1 << 8,
GroupOpen = Bracket | 1,
GroupClose = Bracket | 2,
Format = 1 << 5,
Eof = Format | 1,
NewLine = Format | 2,
Whitespace = Format | 3,
Comment = Format | 4,
ContextOpen = Bracket | 3,
ContextClose = Bracket | 4,
Bracket = 1 << 6,
GroupOpen = Bracket | 1,
GroupClose = Bracket | 2,
ContextOpen = Bracket | 3,
ContextClose = Bracket | 4,
ArrayOpen = Bracket | 5,
ArrayClose = Bracket | 6,
ListOpen = Bracket | 7,
Lambda = Bracket | 8,
ArrayOpen = Bracket | 5,
ArrayClose = Bracket | 6,
ListOpen = Bracket | 7,
Structure = 1 << 7,
Comma = Structure | 1,
Dot = Structure | 2,
Colon = Structure | 3,
Semicolon = Structure | 4,
AddItem,
RemoveItem,
Operator = 1 << 8,
Minus = Operator | 1,
Plus = Operator | 2,
Decrement = Operator | 3,
Increment = Operator | 4,
Slash = Operator | 5,
Star = Operator | 6,
Modulo = Operator | 7,
BitwiseAnd = Operator | 8,
BitwiseOr = Operator | 9,
BitwiseXor = Operator | 10,
BitwiseNot = Operator | 11,
BitwiseLeft = Operator | 12,
BitwiseRight = Operator | 13,
Comma,
Dot,
Colon,
Semicolon,
Assignment = 1 << 9,
Equal = Assignment | 1,
PlusEqual = Assignment | 2,
MinusEqual = Assignment | 3,
SlashEqual = Assignment | 4,
StarEqual = Assignment | 5,
ModuloEqual = Assignment | 6,
AddItem = Assignment | 7,
RemoveItem = Assignment | 8,
Minus,
Plus,
MinusEqual,
PlusEqual,
Decrement,
Increment,
Condition = 1 << 10,
Bang = Condition | 1,
BangEqual = Condition | 2,
EqualEqual = Condition | 4,
Greater = Condition | 5,
GreaterEqual = Condition | 6,
Less = Condition | 7,
LessEqual = Condition | 8,
And = Condition | 9,
Or = Condition | 10,
Slash,
SlashEqual,
Star,
StarEqual,
Modulo,
ModuloEqual,
Literal = 1 << 11,
Identifier = Literal | 1,
String = Literal | 2,
Integer = Literal | 3,
Decimal = Literal | 4,
Hexadecimal = Literal | 5,
BitwiseAnd,
BitwiseOr,
BitwiseXor,
BitwiseNot,
Control = 1 << 12,
Else = Control | 1,
For = Control | 2,
If = Control | 3,
This = Control | 4,
Var = Control | 5,
While = Control | 6,
Do = Control | 7,
Return = Control | 8,
Question = Control | 9,
DoubleQuestion = Control | 10,
TernaryElse = Control | 11,
Ref = Control | 12,
Function = Control | 13,
Class = Control | 14,
Base = Control | 15,
BitwiseLeft,
BitwiseRight,
Native = 1 << 14,
Print = Native | 1,
PrintStack = Native | 2,
PrintGlobals = Native | 3,
PrintExpr = Native | 4,
TypeOf = Native | 5,
Bang,
BangEqual,
Equal,
EqualEqual,
Greater,
GreaterEqual,
Less,
LessEqual,
Question,
DoubleQuestion,
Identifier,
String,
Integer,
Decimal,
Hexadecimal,
And,
Else,
False,
For,
If,
Or,
This,
True,
Var,
While,
Do,
Return,
TernaryElse,
Ref,
Function,
Class,
Base,
Print,
PrintStack,
PrintGlobals,
PrintExpr,
TypeOf,
Import,
Export
Import = Native | 6,
Export = Native | 7
}
public static class TokenTypeExtensions
public static class TokenTypeExtensions // iknow, i know, gotta make this flagged rather than THIS
{
public static bool IsBracket(this TokenType type)
=> type is GroupClose or GroupOpen or ContextClose or ContextOpen or ArrayClose or ArrayOpen or ListOpen;
=> type is GroupClose or GroupOpen or ContextClose or ContextOpen or ArrayClose or ArrayOpen or ListOpen or Lambda;
public static bool IsString(this TokenType type)
=> type is TokenType.String;