BEHC.SimpleTextPreprocessor
1.0.1
dotnet add package BEHC.SimpleTextPreprocessor --version 1.0.1
NuGet\Install-Package BEHC.SimpleTextPreprocessor -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BEHC.SimpleTextPreprocessor" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BEHC.SimpleTextPreprocessor --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: BEHC.SimpleTextPreprocessor, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BEHC.SimpleTextPreprocessor as a Cake Addin #addin nuget:?package=BEHC.SimpleTextPreprocessor&version=1.0.1 // Install BEHC.SimpleTextPreprocessor as a Cake Tool #tool nuget:?package=BEHC.SimpleTextPreprocessor&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SimpleTextPreprocessor
Simple text preprocessor that supports basic directives like #include
and conditional blocks (#if
/#elif
/#else
/#endif
).
Not as powerful as C/C++ preprocessor, but slightly more robust than C# preprocessor directives.
Expressions for conditional blocks (#if
/#elif
) can include boolean logic and integer comparisons:
#if DEF1 && (DEF2 || DEF3)
// or
#if DEF1 > 0x10 && (DEF2 || DEF3 != 0)
Check repository for more detailed description.
How to use
Examples
Simple string processing, without #include
support:
Preprocessor preprocessor = new();
using TextReader source = new StringReader(sourceText);
StringBuilder sb = new StringBuilder();
using TextWriter result = new StringWriter(sb);
bool success = preprocessor.Process(source, result);
String processing, with #include
support, ignored directive, and defined symbols:
InMemoryIncludeResolver includeResolver = new();
includeResolver.Entries.Add("file1", "some content...");
includeResolver.Entries.Add("file2", "some content...");
Preprocessor preprocessor = new (includeResolver, new DefaultExpressionSolver(), PreprocessorOptions.Default);
preprocessor.AddToIgnored("version");
preprocessor.AddSymbol("DEF1", "123");
preprocessor.AddSymbol("DEF2", "false");
preprocessor.AddSymbol("DEF3"); // no value, defaults to true
using TextReader source = new StringReader(sourceText);
StringBuilder sb = new StringBuilder();
using TextWriter result = new StringWriter(sb);
bool success = preprocessor.Process(source, result);
File processing, with #include
, error reporting, and source line number mapping:
FileSystemIncludeResolver includeResolver = new();
Preprocessor preprocessor = new (includeResolver, new DefaultExpressionSolver(), PreprocessorOptions.Default);
ReportList report = new();
LineNumberMapper lineNumberMapper = new();
using TextReader source = new StreamReader(sourceFilePath);
using TextWriter output = new StreamWriter(outputFilePath);
string rootFileId = includeResolver.GetFileId(sourceFilePath);
bool success = preprocessor.Process(rootFileId, source, output, report, lineNumberMapper);
if (!success)
{
foreach (ReportList.Entry entry in report.Entries)
Console.WriteLine($"{entry.FileId}({entry.Line},{entry.Column}): {entry.Message}");
}
// after using output file by external tools and get error at line 123 it is possible to point to correct file/line number
(string sourceFileId, int sourceLineNumber) = lineNumberMapper.GetSource(123);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.