summaryrefslogtreecommitdiff
path: root/Compiler/Program.cs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-28 14:44:51 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-28 14:44:51 +1000
commitcf7e621c104cb4aea801392585d2dcc9335bc013 (patch)
treeee4aef401c399995968afe217d06557587707c51 /Compiler/Program.cs
parent7f96fc5e7f412a66d460dcaa82bbdbcaea08f360 (diff)
added preprocessor (wip)
Diffstat (limited to 'Compiler/Program.cs')
-rw-r--r--Compiler/Program.cs24
1 files changed, 23 insertions, 1 deletions
diff --git a/Compiler/Program.cs b/Compiler/Program.cs
index 3a277a1..09f7127 100644
--- a/Compiler/Program.cs
+++ b/Compiler/Program.cs
@@ -2,6 +2,7 @@
using System.Text;
using Antlr4.Runtime;
+using Antlr4.Runtime.Misc;
using CommandLine;
using visitors;
using Parser = CommandLine.Parser;
@@ -26,7 +27,7 @@ public class Program
try
{
- AntlrFileStream inputStream = new(options.InputFile);
+ ICharStream inputStream = new PreprocessingCharStream(options.InputFile);
CGrammarLexer lexer = new(inputStream);
lexer.RemoveErrorListeners();
@@ -48,4 +49,25 @@ public class Program
Console.WriteLine($"{ex.Message}");
}
}
+}
+
+public class PreprocessingCharStream : ICharStream
+{
+ private readonly AntlrInputStream inner;
+
+ public PreprocessingCharStream(string filePath)
+ {
+ string preprocessed = Preprocessor.Process(filePath);
+ inner = new AntlrInputStream(preprocessed);
+ }
+
+ public int Index => inner.Index;
+ public int Size => inner.Size;
+ public string SourceName => inner.SourceName;
+ public void Consume() => inner.Consume();
+ public int LA(int i) => inner.LA(i);
+ public int Mark() => inner.Mark();
+ public void Release(int marker) => inner.Release(marker);
+ public void Seek(int index) => inner.Seek(index);
+ public string GetText(Interval interval) => inner.GetText(interval);
} \ No newline at end of file