-
Notifications
You must be signed in to change notification settings - Fork 0
Example‐5
This example shows how to parse Describe source code from a string to an Abstract Syntax Tree.
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.
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;
}
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.High,
Messages.ConsoleLog,
Messages.ConsoleLogError,
Messages.ConsoleLogInfo,
Messages.ConsoleLogParseInfo);
//settings
compiler.LanguageVersion = DescribeVersionNumber.Version10;
The Describe compiler will produce an AstScriptureNode.
AstScriptureNode? rootNode;
bool result = compiler.ParseString(source, fileName, out rootNode);
Home
Grammar How To
Compiler How To
CLI Compiler - How to
CLI Compiler - How to - help
CLI Compiler - How to - parse-file
CLI Compiler - How to - parse-folder
CLI Compiler - How to - encrypt-file
CLI Compiler - How to - decrypt-file
CLI Compiler - How to - recrypt-file
CLI Compiler - How to - encrypt-folder
CLI Compiler - How to - decrypt-folder
CLI Compiler - How to - recrypt-folder
API Compiler - How to
API Compiler - How to - Example 1
API Compiler - How to - Example 2
API Compiler - How to - Example 3
API Compiler - How to - Example 4
API Compiler - How to - Example 5
AWS Compiler - How to
AWS technical overview
API gateway configuration
output - low
output - medium
output - high
output - themes
Grammar - Lists
Grammar - Comments
Grammar - Links
Grammar - Decorators
Grammar - Tags
Grammar - More on Tags
Grammar - Directives
Grammar - Dot Notation
Grammar - Tildes
Grammar - Files
Deprecated - Slash Notation
Deprecated - Delimiter Mode
Describe Basics - v0.6
Describe Tags - v0.7
Describe Links - v0.8
Describe Decorators - v0.9
Describe Lines - v1.0
Describe Doubles - v1.1