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('=') ? Check('=') ?
MakeToken(GreaterEqual, buffer + Next()) : MakeToken(GreaterEqual, buffer + Next()) :
MakeToken(Greater, buffer), MakeToken(Greater, buffer),
'~' => MakeToken(BitwiseNot, buffer), '~' => Check('(') ?
MakeToken(Lambda, buffer) :
MakeToken(BitwiseNot, buffer),
'?' => Check('?') ? '?' => Check('?') ?
MakeToken(DoubleQuestion, buffer + Next()) : MakeToken(DoubleQuestion, buffer + Next()) :
Check(':') ? Check(':') ?

View File

@ -2,109 +2,114 @@
using static TokenType; using static TokenType;
[Flags]
public enum TokenType public enum TokenType
{ {
Error, Error = -1,
Void, Void = 0,
Null,
Eof, Constant = 1 << 4,
NewLine, Null = Constant | 1,
Whitespace, True = Constant | 2,
Comment, False = Constant | 3,
Bracket = 1 << 8, Format = 1 << 5,
Eof = Format | 1,
NewLine = Format | 2,
Whitespace = Format | 3,
Comment = Format | 4,
Bracket = 1 << 6,
GroupOpen = Bracket | 1, GroupOpen = Bracket | 1,
GroupClose = Bracket | 2, GroupClose = Bracket | 2,
ContextOpen = Bracket | 3, ContextOpen = Bracket | 3,
ContextClose = Bracket | 4, ContextClose = Bracket | 4,
ArrayOpen = Bracket | 5, ArrayOpen = Bracket | 5,
ArrayClose = Bracket | 6, ArrayClose = Bracket | 6,
ListOpen = Bracket | 7, ListOpen = Bracket | 7,
Lambda = Bracket | 8,
AddItem, Structure = 1 << 7,
RemoveItem, Comma = Structure | 1,
Dot = Structure | 2,
Colon = Structure | 3,
Semicolon = Structure | 4,
Comma, Operator = 1 << 8,
Dot, Minus = Operator | 1,
Colon, Plus = Operator | 2,
Semicolon, 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,
Minus, Assignment = 1 << 9,
Plus, Equal = Assignment | 1,
MinusEqual, PlusEqual = Assignment | 2,
PlusEqual, MinusEqual = Assignment | 3,
Decrement, SlashEqual = Assignment | 4,
Increment, StarEqual = Assignment | 5,
ModuloEqual = Assignment | 6,
AddItem = Assignment | 7,
RemoveItem = Assignment | 8,
Slash, Condition = 1 << 10,
SlashEqual, Bang = Condition | 1,
Star, BangEqual = Condition | 2,
StarEqual, EqualEqual = Condition | 4,
Modulo, Greater = Condition | 5,
ModuloEqual, GreaterEqual = Condition | 6,
Less = Condition | 7,
LessEqual = Condition | 8,
And = Condition | 9,
Or = Condition | 10,
BitwiseAnd, Literal = 1 << 11,
BitwiseOr, Identifier = Literal | 1,
BitwiseXor, String = Literal | 2,
BitwiseNot, Integer = Literal | 3,
Decimal = Literal | 4,
Hexadecimal = Literal | 5,
BitwiseLeft, Control = 1 << 12,
BitwiseRight, 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,
Bang, Native = 1 << 14,
BangEqual, Print = Native | 1,
Equal, PrintStack = Native | 2,
EqualEqual, PrintGlobals = Native | 3,
Greater, PrintExpr = Native | 4,
GreaterEqual, TypeOf = Native | 5,
Less,
LessEqual,
Question, Import = Native | 6,
DoubleQuestion, Export = Native | 7
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
} }
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) 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) public static bool IsString(this TokenType type)
=> type is TokenType.String; => type is TokenType.String;