From 1646a7905526c5e98306bf9207e88f831d3a5ff2 Mon Sep 17 00:00:00 2001 From: 0x4261756D <38735823+0x4261756D@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:39:22 +0100 Subject: [PATCH] better command line handling + big formatting stuff --- .editorconfig | 91 ++++++++++- Program.cs | 58 ++++++- Tokenizer.cs | 434 +++++++++++++++++++++++++------------------------- 3 files changed, 357 insertions(+), 226 deletions(-) diff --git a/.editorconfig b/.editorconfig index dc97a31..3879955 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,94 @@ root = true +[*] indent_size = 4 indent_style = tab +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true +charset = utf-8 [*.cs] - -trim_trailing_whitespace = true - csharp_space_after_keywords_in_control_flow_statements = false -csharp_indent_case_contents_when_block = false \ No newline at end of file +csharp_indent_case_contents_when_block = false +csharp_style_unused_value_expression_preference = unused_local_variable +csharp_prefer_braces = true +csharp_prefer_static_local_function = true +dotnet_style_prefer_foreach_explicit_cast_in_source = always +dotnet_diagnostic.IDE0001.severity = warning +dotnet_diagnostic.IDE0002.severity = warning +dotnet_diagnostic.IDE0004.severity = warning +dotnet_diagnostic.IDE0005.severity = warning +dotnet_diagnostic.IDE0011.severity = warning +dotnet_diagnostic.IDE0020.severity = warning +dotnet_diagnostic.IDE0028.severity = warning +dotnet_diagnostic.IDE0029.severity = warning +dotnet_diagnostic.IDE0030.severity = warning +dotnet_diagnostic.IDE0031.severity = warning +dotnet_diagnostic.IDE0035.severity = error +dotnet_diagnostic.IDE0038.severity = error +dotnet_diagnostic.IDE0041.severity = warning +dotnet_diagnostic.IDE0042.severity = warning +dotnet_diagnostic.IDE0051.severity = warning +dotnet_diagnostic.IDE0052.severity = warning +dotnet_diagnostic.IDE0054.severity = warning +dotnet_diagnostic.IDE0050.severity = warning +dotnet_diagnostic.IDE0056.severity = warning +dotnet_diagnostic.IDE0057.severity = warning +dotnet_diagnostic.IDE0058.severity = warning +dotnet_diagnostic.IDE0060.severity = warning +dotnet_diagnostic.IDE0062.severity = warning +dotnet_diagnostic.IDE0066.severity = warning +dotnet_diagnostic.IDE0071.severity = warning +dotnet_diagnostic.IDE0074.severity = warning +dotnet_diagnostic.IDE0075.severity = warning +dotnet_diagnostic.IDE0078.severity = warning +dotnet_diagnostic.IDE0080.severity = warning +dotnet_diagnostic.IDE0083.severity = warning +dotnet_diagnostic.IDE0090.severity = warning +dotnet_diagnostic.IDE0100.severity = warning +dotnet_diagnostic.IDE0180.severity = warning +dotnet_diagnostic.IDE0200.severity = warning +dotnet_diagnostic.IDE0220.severity = warning +dotnet_diagnostic.IDE0260.severity = warning +dotnet_diagnostic.IDE0270.severity = warning +dotnet_diagnostic.CA1508.severity = warning +dotnet_diagnostic.CA1514.severity = warning +dotnet_diagnostic.CA1515.severity = warning +dotnet_diagnostic.CA1801.severity = warning +dotnet_diagnostic.CA1802.severity = warning +dotnet_diagnostic.CA1805.severity = warning +dotnet_diagnostic.CA1806.severity = warning +dotnet_diagnostic.CA1810.severity = warning +dotnet_diagnostic.CA1812.severity = warning +dotnet_diagnostic.CA1814.severity = warning +dotnet_diagnostic.CA1820.severity = warning +dotnet_diagnostic.CA1822.severity = warning +dotnet_diagnostic.CA1823.severity = warning +dotnet_diagnostic.CA1825.severity = warning +dotnet_diagnostic.CA1826.severity = error +dotnet_diagnostic.CA1827.severity = error +dotnet_diagnostic.CA1829.severity = error +dotnet_diagnostic.CA1830.severity = error +dotnet_diagnostic.CA1833.severity = warning +dotnet_diagnostic.CA1834.severity = warning +dotnet_diagnostic.CA1835.severity = warning +dotnet_diagnostic.CA1836.severity = warning +dotnet_diagnostic.CA1841.severity = error +dotnet_diagnostic.CA1845.severity = warning +dotnet_diagnostic.CA1846.severity = warning +dotnet_diagnostic.CA1847.severity = warning +dotnet_diagnostic.CA1849.severity = warning +dotnet_diagnostic.CA1850.severity = warning +dotnet_diagnostic.CA1851.severity = warning +dotnet_diagnostic.CA1853.severity = warning +dotnet_diagnostic.CA1859.severity = warning +dotnet_diagnostic.CA1860.severity = warning +dotnet_diagnostic.CA1861.severity = warning +dotnet_diagnostic.CA1864.severity = warning +dotnet_diagnostic.CA1865.severity = warning +dotnet_diagnostic.CA1866.severity = warning +dotnet_diagnostic.CA1867.severity = warning +dotnet_diagnostic.CA2007.severity = warning +dotnet_diagnostic.CA2011.severity = error +dotnet_diagnostic.CA2248.severity = error diff --git a/Program.cs b/Program.cs index a4830f5..95cbc73 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,54 @@ -string text = File.ReadAllText(args[0]); -Token[] tokens = new Tokenizer().tokenize(text); -foreach (Token token in tokens) +namespace luaaaaah; + +public class Program { - Console.WriteLine($"{token.region}: {token.type} {{{token.data}}}"); -} \ No newline at end of file + public static void Main(string[] args) + { + switch(args[0]) + { + case "test": + { + Test(args[1]); + } + break; + case "run": + { + Run(args[1]); + } + break; + } + } + public static void Run(string file) + { + Token[] tokens = new Tokenizer().Tokenize(File.ReadAllText(file)); + foreach(Token token in tokens) + { + Console.WriteLine($"{token.region}: {token.type} {{{token.data}}}"); + } + + } + public static void Test(string directory) + { + Dictionary failedFiles = []; + foreach(string file in Directory.EnumerateFiles(directory)) + { + if(file.EndsWith(".lua")) + { + try + { + Run(file); + } + catch(Exception e) + { + Console.WriteLine($"{file}: {e.Message}"); + failedFiles.Add(file, e.Message); + } + } + } + Console.WriteLine("===FAILED==="); + foreach(KeyValuePair entry in failedFiles) + { + Console.WriteLine($"{entry.Key}: {entry.Value}"); + } + } +} diff --git a/Tokenizer.cs b/Tokenizer.cs index 5ac5e68..358b285 100644 --- a/Tokenizer.cs +++ b/Tokenizer.cs @@ -1,20 +1,20 @@ - +namespace luaaaaah; class Tokenizer { - private List tokens = []; + private readonly List tokens = []; private State state = State.Start; - int? lastIndex = null; - int index = 0; - int openingLongBracketLevel = 0; - int closingLongBracketLevel = 0; - Token? currentToken = null; + int? lastIndex; + int index; + int openingLongBracketLevel; + int closingLongBracketLevel; + Token? currentToken; CodeLocation currentLocation = new(line: 0, col: 0); - public Token[] tokenize(string content) + public Token[] Tokenize(string content) { while(index < content.Length) { - tokenizeChar(content[index]); + TokenizeChar(content[index]); if(content[index] == '\n') { currentLocation.line += 1; @@ -26,11 +26,11 @@ class Tokenizer } index += 1; } - tokenizeChar('\n'); - return tokens.ToArray(); + TokenizeChar('\n'); + return [.. tokens]; } - private void appendDataChar(char ch) + private void AppendDataChar(char ch) { if((Token.StringData?)currentToken!.data == null) { @@ -43,36 +43,36 @@ class Tokenizer currentToken.region.end = new(currentLocation); } - private void appendDataInt(char ch) + private void AppendDataInt(char ch) { if((Token.NumeralData?)currentToken!.data == null) { - currentToken!.data = new Token.NumeralData(new Numeral.Integer(ch - '0')); + currentToken!.data = new Token.NumeralData(new INumeral.Integer(ch - '0')); } else { - ((Numeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value *= 10; - ((Numeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value += ch - '0'; + ((INumeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value *= 10; + ((INumeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value += ch - '0'; } currentToken.region.end = new(currentLocation); } - private void appendDataIntHex(char ch) + private void AppendDataIntHex(char ch) { int v = char.IsAsciiDigit(ch) ? ch - '0' : 10 + char.ToLower(ch) - 'a'; if((Token.NumeralData?)currentToken!.data == null) { - currentToken!.data = new Token.NumeralData(new Numeral.Integer(v)); + currentToken!.data = new Token.NumeralData(new INumeral.Integer(v)); } else { - ((Numeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value *= 16; - ((Numeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value += v; + ((INumeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value *= 16; + ((INumeral.Integer)((Token.NumeralData?)currentToken!.data!).numeral).value += v; } currentToken.region.end = new(currentLocation); } - private void tokenizeChar(char ch) + private void TokenizeChar(char ch) { switch(state) { @@ -343,7 +343,7 @@ class Tokenizer { lastIndex = index; state = State.Zero; - currentToken = new(region: new(start: new(currentLocation), end: new(currentLocation)), type: TokenType.Numeral, data: new Token.NumeralData(new Numeral.Integer(0))); + currentToken = new(region: new(start: new(currentLocation), end: new(currentLocation)), type: TokenType.Numeral, data: new Token.NumeralData(new INumeral.Integer(0))); } /* tokenizeTerminalIntNum(TokenType.Numeral, TokenizerState.Zero, tokenNumeral, ch); */ break; case '"': @@ -373,7 +373,7 @@ class Tokenizer { lastIndex = index; state = State.Number; - currentToken = new(region: new(start: new(currentLocation), end: new(currentLocation)), type: TokenType.Numeral, data: new Token.NumeralData(new Numeral.Integer(ch - '0'))); + currentToken = new(region: new(start: new(currentLocation), end: new(currentLocation)), type: TokenType.Numeral, data: new Token.NumeralData(new INumeral.Integer(ch - '0'))); } else { @@ -406,7 +406,7 @@ class Tokenizer } else { - appendDataChar(ch); + AppendDataChar(ch); } } break; @@ -416,62 +416,62 @@ class Tokenizer { case 'a': { - appendDataChar('\u0007'); + AppendDataChar('\u0007'); state = State.Quote; } break; case 'b': { - appendDataChar('\u0008'); + AppendDataChar('\u0008'); state = State.Quote; } break; case 't': { - appendDataChar('\t'); + AppendDataChar('\t'); state = State.Quote; } break; case 'n': case '\n': { - appendDataChar('\n'); + AppendDataChar('\n'); state = State.Quote; } break; case 'v': { - appendDataChar('\u000b'); + AppendDataChar('\u000b'); state = State.Quote; } break; case 'f': { - appendDataChar('\u000c'); + AppendDataChar('\u000c'); state = State.Quote; } break; case 'r': { - appendDataChar('\r'); + AppendDataChar('\r'); state = State.Quote; } break; case '\\': { - appendDataChar('\\'); + AppendDataChar('\\'); state = State.Quote; } break; case '"': { - appendDataChar('"'); + AppendDataChar('"'); state = State.Quote; } break; case '\'': { - appendDataChar('\''); + AppendDataChar('\''); state = State.Quote; } break; @@ -506,7 +506,7 @@ class Tokenizer } else if(!char.IsWhiteSpace(ch)) { - appendDataChar(ch); + AppendDataChar(ch); state = State.Quote; } else @@ -538,7 +538,7 @@ class Tokenizer } else { - appendDataChar(ch); + AppendDataChar(ch); } } break; @@ -548,62 +548,62 @@ class Tokenizer { case 'a': { - appendDataChar('\u0007'); + AppendDataChar('\u0007'); state = State.SingleQuote; } break; case 'b': { - appendDataChar('\u0008'); + AppendDataChar('\u0008'); state = State.SingleQuote; } break; case 't': { - appendDataChar('\t'); + AppendDataChar('\t'); state = State.SingleQuote; } break; case 'n': case '\n': { - appendDataChar('\n'); + AppendDataChar('\n'); state = State.SingleQuote; } break; case 'v': { - appendDataChar('\u000b'); + AppendDataChar('\u000b'); state = State.SingleQuote; } break; case 'f': { - appendDataChar('\u000c'); + AppendDataChar('\u000c'); state = State.SingleQuote; } break; case 'r': { - appendDataChar('\r'); + AppendDataChar('\r'); state = State.SingleQuote; } break; case '\\': { - appendDataChar('\\'); + AppendDataChar('\\'); state = State.SingleQuote; } break; case '"': { - appendDataChar('"'); + AppendDataChar('"'); state = State.SingleQuote; } break; case '\'': { - appendDataChar('\''); + AppendDataChar('\''); state = State.SingleQuote; } break; @@ -638,7 +638,7 @@ class Tokenizer } else if(!char.IsWhiteSpace(ch)) { - appendDataChar(ch); + AppendDataChar(ch); state = State.Quote; } else @@ -671,7 +671,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -703,7 +703,7 @@ class Tokenizer else if(char.IsAsciiDigit(ch)) { lastIndex = index; - appendDataInt(ch); + AppendDataInt(ch); } else { @@ -726,7 +726,7 @@ class Tokenizer { lastIndex = index; currentToken!.type = TokenType.Numeral; - appendDataIntHex(ch); + AppendDataIntHex(ch); state = State.HexNumber; } else @@ -755,7 +755,7 @@ class Tokenizer { lastIndex = index; currentToken!.type = TokenType.Numeral; - appendDataIntHex(ch); + AppendDataIntHex(ch); } else { @@ -787,7 +787,7 @@ class Tokenizer { lastIndex = index; currentToken!.type = TokenType.Numeral; - appendDataInt(ch); + AppendDataInt(ch); } else { @@ -1199,7 +1199,7 @@ class Tokenizer } else { - appendDataChar(ch); + AppendDataChar(ch); } } break; @@ -1212,7 +1212,7 @@ class Tokenizer { state = State.StringWithLongBracket; } - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == ']' && openingLongBracketLevel == closingLongBracketLevel) { @@ -1237,7 +1237,7 @@ class Tokenizer else { closingLongBracketLevel = 0; - appendDataChar(ch); + AppendDataChar(ch); } } break; @@ -1247,14 +1247,14 @@ class Tokenizer { lastIndex = index; state = State.An; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1278,14 +1278,14 @@ class Tokenizer { lastIndex = index; state = State.And; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1310,7 +1310,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1335,14 +1335,14 @@ class Tokenizer { lastIndex = index; state = State.Wh; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1366,14 +1366,14 @@ class Tokenizer { lastIndex = index; state = State.Whi; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1397,14 +1397,14 @@ class Tokenizer { lastIndex = index; state = State.Whil; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1428,14 +1428,14 @@ class Tokenizer { lastIndex = index; state = State.While; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1460,7 +1460,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1485,14 +1485,14 @@ class Tokenizer { lastIndex = index; state = State.Br; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1516,14 +1516,14 @@ class Tokenizer { lastIndex = index; state = State.Bre; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1547,14 +1547,14 @@ class Tokenizer { lastIndex = index; state = State.Brea; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1578,14 +1578,14 @@ class Tokenizer { lastIndex = index; state = State.Break; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1610,7 +1610,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1635,14 +1635,14 @@ class Tokenizer { lastIndex = index; state = State.Go; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1666,14 +1666,14 @@ class Tokenizer { lastIndex = index; state = State.Got; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1697,14 +1697,14 @@ class Tokenizer { lastIndex = index; state = State.Goto; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1729,7 +1729,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1754,14 +1754,14 @@ class Tokenizer { lastIndex = index; state = State.Re; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1785,20 +1785,20 @@ class Tokenizer { lastIndex = index; state = State.Ret; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'p') { lastIndex = index; state = State.Rep; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1822,14 +1822,14 @@ class Tokenizer { lastIndex = index; state = State.Retu; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1853,14 +1853,14 @@ class Tokenizer { lastIndex = index; state = State.Retur; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1884,14 +1884,14 @@ class Tokenizer { lastIndex = index; state = State.Return; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1916,7 +1916,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1941,14 +1941,14 @@ class Tokenizer { lastIndex = index; state = State.Repe; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -1972,14 +1972,14 @@ class Tokenizer { lastIndex = index; state = State.Repea; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2003,14 +2003,14 @@ class Tokenizer { lastIndex = index; state = State.Repeat; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2035,7 +2035,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2060,20 +2060,20 @@ class Tokenizer { lastIndex = index; state = State.Ni; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'o') { - lastIndex= index; + lastIndex = index; state = State.No; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2097,14 +2097,14 @@ class Tokenizer { lastIndex = index; state = State.Nil; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2129,7 +2129,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2154,14 +2154,14 @@ class Tokenizer { lastIndex = index; state = State.Not; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2186,7 +2186,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2211,20 +2211,20 @@ class Tokenizer { lastIndex = index; state = State.Th; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'r') { lastIndex = index; state = State.Tr; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2248,14 +2248,14 @@ class Tokenizer { lastIndex = index; state = State.The; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2279,14 +2279,14 @@ class Tokenizer { lastIndex = index; state = State.Then; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2311,7 +2311,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2336,14 +2336,14 @@ class Tokenizer { lastIndex = index; state = State.Tru; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2367,14 +2367,14 @@ class Tokenizer { lastIndex = index; state = State.True; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2399,7 +2399,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2424,20 +2424,20 @@ class Tokenizer { lastIndex = index; state = State.El; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'n') { lastIndex = index; state = State.En; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2461,14 +2461,14 @@ class Tokenizer { lastIndex = index; state = State.Els; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2492,14 +2492,14 @@ class Tokenizer { lastIndex = index; state = State.Else; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2523,14 +2523,14 @@ class Tokenizer { lastIndex = index; state = State.Elsei; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2555,14 +2555,14 @@ class Tokenizer { lastIndex = index; state = State.Elseif; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2587,7 +2587,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2612,14 +2612,14 @@ class Tokenizer { lastIndex = index; state = State.End; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2644,7 +2644,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2669,14 +2669,14 @@ class Tokenizer { lastIndex = index; state = State.Or; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2701,7 +2701,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2726,14 +2726,14 @@ class Tokenizer { lastIndex = index; state = State.Do; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2758,7 +2758,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2783,20 +2783,20 @@ class Tokenizer { lastIndex = index; state = State.If; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'n') { lastIndex = index; state = State.In; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2821,7 +2821,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2847,7 +2847,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2872,26 +2872,26 @@ class Tokenizer { lastIndex = index; state = State.Fu; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'a') { lastIndex = index; state = State.Fa; - appendDataChar(ch); + AppendDataChar(ch); } else if(ch == 'o') { lastIndex = index; state = State.Fo; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2915,14 +2915,14 @@ class Tokenizer { lastIndex = index; state = State.Fun; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2946,14 +2946,14 @@ class Tokenizer { lastIndex = index; state = State.Func; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -2977,14 +2977,14 @@ class Tokenizer { lastIndex = index; state = State.Funct; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3008,14 +3008,14 @@ class Tokenizer { lastIndex = index; state = State.Functi; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3039,14 +3039,14 @@ class Tokenizer { lastIndex = index; state = State.Functio; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3070,14 +3070,14 @@ class Tokenizer { lastIndex = index; state = State.Function; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3102,7 +3102,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3127,14 +3127,14 @@ class Tokenizer { lastIndex = index; state = State.Fal; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3158,14 +3158,14 @@ class Tokenizer { lastIndex = index; state = State.Fals; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3189,14 +3189,14 @@ class Tokenizer { lastIndex = index; state = State.False; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3221,7 +3221,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3246,14 +3246,14 @@ class Tokenizer { lastIndex = index; state = State.For; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3278,7 +3278,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3303,14 +3303,14 @@ class Tokenizer { lastIndex = index; state = State.Lo; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3334,14 +3334,14 @@ class Tokenizer { lastIndex = index; state = State.Loc; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3365,14 +3365,14 @@ class Tokenizer { lastIndex = index; state = State.Loca; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3396,14 +3396,14 @@ class Tokenizer { lastIndex = index; state = State.Local; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3428,7 +3428,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3453,14 +3453,14 @@ class Tokenizer { lastIndex = index; state = State.Un; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3484,14 +3484,14 @@ class Tokenizer { lastIndex = index; state = State.Unt; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3515,14 +3515,14 @@ class Tokenizer { lastIndex = index; state = State.Unti; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3546,14 +3546,14 @@ class Tokenizer { lastIndex = index; state = State.Until; - appendDataChar(ch); + AppendDataChar(ch); } else if(char.IsAsciiLetterOrDigit(ch) || ch == '_') { lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3578,7 +3578,7 @@ class Tokenizer lastIndex = index; state = State.Name; currentToken!.type = TokenType.Name; - appendDataChar(ch); + AppendDataChar(ch); } else { @@ -3656,22 +3656,22 @@ class CodeLocation(int line, int col) } } -class Token(CodeRegion region, TokenType? type = null, Token.Data? data = null) +class Token(CodeRegion region, TokenType? type = null, Token.IData? data = null) { public CodeRegion region = region; - public Data? data = data; + public IData? data = data; public TokenType? type = type; - public interface Data { } - public class NumeralData(Numeral numeral) : Data + public interface IData { } + public class NumeralData(INumeral numeral) : IData { - public Numeral numeral = numeral; + public INumeral numeral = numeral; public override string ToString() { return $"NumeralData {numeral}"; } } - public class StringData(string data) : Data + public class StringData(string data) : IData { public string data = data; public override string ToString() @@ -3696,38 +3696,38 @@ public enum TokenType StringLiteral, } -public interface Numeral +public interface INumeral { - public class Integer(int value) : Numeral + public class Integer(int value) : INumeral { public int value = value; - public bool rawEqual(Numeral other) + public bool RawEqual(INumeral other) { - if(other is Numeral.Integer) + if(other is Integer integer) { - return ((Numeral.Integer)other).value == value; + return integer.value == value; } // TODO: Check if this is actually doing what is expected - return ((Numeral.Float)other).value == value; + return ((Float)other).value == value; } public override string ToString() { return $"Numeral Integer {value}"; } } - public class Float(float value) : Numeral + public class Float(float value) : INumeral { public float value = value; - public bool rawEqual(Numeral other) + public bool RawEqual(INumeral other) { - if(other is Numeral.Float) + if(other is Float float_val) { - return ((Numeral.Float)other).value == value; + return float_val.value == value; } // TODO: Check if this is actually doing what is expected - return ((Numeral.Integer)other).value == value; + return ((Integer)other).value == value; } public override string ToString() { @@ -3735,5 +3735,5 @@ public interface Numeral } } - public bool rawEqual(Numeral other); -} \ No newline at end of file + public bool RawEqual(INumeral other); +}