Skip to content

Example‐1

Viktor Chernev edited this page Nov 6, 2024 · 1 revision

This example shows how to parse a folder of Describe source files to an Unfold and then translate the unfold to an HTML page.

1. Add a reference

You can either download the Visual Studio project or the compiled dll file from the last release from here, and reference it in your .Net project.

2. Create log handlers

Create handler methods that are used for logging data. This is how we are going to get logs from the parser. In the example below, we are creating methods that will log data to the console in different colors.

//log text private static void ConsoleLog(string text) { Console.WriteLine(text); } //log info gray private static void ConsoleLogInfo(string text) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine(text); Console.ForegroundColor = ConsoleColor.White; } //log errors red private static void ConsoleLogError(string text) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(text); Console.ForegroundColor = ConsoleColor.White; } //log parser data green private static void ConsoleLogParseInfo(string text) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(text); Console.ForegroundColor = ConsoleColor.White; } 

3. Construct and set the compiler

The constructor for the compiler takes verbosity and log handlers as optional arguments, so that the user does not need to set them one by one. Some or all of log handlers can be omitted and corresponding output won't be logged.

DescribeCompiler.DescribeCompiler compiler =	new DescribeCompiler.DescribeCompiler(	LogVerbosity.Low,	Messages.ConsoleLog,	Messages.ConsoleLogError,	Messages.ConsoleLogInfo,	Messages.ConsoleLogParseInfo); //settings compiler.PARSE_TOP_DIRECTORY_ONLY = false; compiler.PARSE_DS_ONLY = true; compiler.STOP_ON_ERROR = false; compiler.LanguageVersion = DescribeVersionNumber.Version10; 

4. Compile

The Describe compiler will populate a DescribeUnfold structure with data.

DescribeUnfold unfold = new DescribeUnfold(); bool result = compiler.ParseFolder(new DirectoryInfo(path), unfold); 

5. Translate

Construct a translator of a desired type and translate the populated DescribeUnfold structure. If result is not null then the translation process was successful, so save the resulted string to file.

HtmlPageTranslator translator =	new HtmlPageTranslator(	ConsoleLog,	ConsoleLogError,	ConsoleLogParseInfo); translator.IsCensored = true; string? result = translator.TranslateUnfold(unfold); if (result != null) {	File.WriteAllText(@"C:\result\path\output.html", result); } 
Clone this wiki locally