From 18868128e18d38b706e7df14e8e683e1a9739c17 Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Tue, 17 Mar 2026 20:49:22 +1000 Subject: chore: Initial commit --- Compiler/Preprocessor.cs | 57 ------------------------------------------------ 1 file changed, 57 deletions(-) delete mode 100644 Compiler/Preprocessor.cs (limited to 'Compiler/Preprocessor.cs') diff --git a/Compiler/Preprocessor.cs b/Compiler/Preprocessor.cs deleted file mode 100644 index f11ae3a..0000000 --- a/Compiler/Preprocessor.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace Q1.Compiler; - -using System.Text.RegularExpressions; - -public static class Preprocessor -{ - private static readonly Dictionary Defines = new(); - - public static string Process(string filePath) - { - List lines = []; - ProcessFile(filePath, lines, []); - return string.Join(Environment.NewLine, lines); - } - - private static void ProcessFile(string filePath, List output, HashSet includeGuard) - { - if (includeGuard.Contains(Path.GetFullPath(filePath))) - return; // prevent recursive includes - - includeGuard.Add(Path.GetFullPath(filePath)); - - foreach (string rawLine in File.ReadAllLines(filePath)) - { - string line = rawLine.Trim(); - - if (line.StartsWith("#include")) - { - Match match = Regex.Match(line, "#include\\s+\"([^\"]+)\""); - if (match.Success) - { - string includePath = Path.Combine(Path.GetDirectoryName(filePath)!, match.Groups[1].Value); - ProcessFile(includePath, output, includeGuard); - } - continue; - } - else if (line.StartsWith("#define")) - { - Match match = Regex.Match(line, "#define\\s+(\\w+)\\s+(.*)"); - if (match.Success) - Defines[match.Groups[1].Value] = match.Groups[2].Value; - continue; - } - else if (line.StartsWith("#load")) - { - output.Add(line.Replace("#load", "#.include")); - continue; - } - - // expand macros - foreach (KeyValuePair kvp in Defines.OrderByDescending(k => k.Key.Length)) - line = line.Replace(kvp.Key, kvp.Value); - - output.Add(line); - } - } -} \ No newline at end of file -- cgit v1.3.1