5. A brief overview of the Loyc libraries

30 May 2016

When writing a parser, you have to decide whether you’ll use the Loyc runtime libraries or not; the main advantage of not using them is that you won’t have to distribute the 3 Loyc DLLs with your application. But they contain a lot of useful stuff, so have a look and see if you like them.

The alternative is to use the standalone LexerSource and ParserSource which can be found in the “standalone” example in the LLLPG Samples repository.

The important library for parsers based on LLLPG is Loyc.Syntax.dll, which depends on Loyc.Essentials.dll and Loyc.Collections.dll. These DLLs have documentation for most of the classes they contain, automatically available to VS IntelliSense through Loyc.Syntax.xml, Loyc.Essentials.xml and Loyc.Collections.xml; you can also view the reference documentation online. The Loyc libraries contain only “safe”, verifiable code.

In brief, let me just say very briefly what these libraries are for and what they contain.

Loyc.Essentials.dll

A library of general-purpose code that supplements the .NET BCL (standard libraries). It contains the following categories of stuff:

Loyc.Essentials also defines ICharSource, a standard interface for a source of characters, which is used by lexers. It also defines UString which is a string slice structure that implements ICharSource. string is implicitly convertible to UString. The Slice(start, count) extension method for string can also get slices.

IMessageSink serves as a simple, generic logging interface. It is recommended that your parsers report warnings and errors to an IMessageSink object. You can use ConsoleMessageSink.Value to print (colored) errors to the console, MessageSink.Null to suppress output, and MessageSink.FromDelegate((type, context, message, args) => {...}) to customize error handling.

The ParseHelpers class has generic number parsers that are handy for lexers, such as TryParseDouble, which can parse numbers of any reasonable radix and is therefore useful for hex float literals such as 0xF.Fp+1 (a syntax that represents 31.875).

Loyc.Collections.dll

A library of data structures, mostly rather complex ones, currently all written by me:

Loyc.Syntax.dll

Provides the foundations for LLLPG and contains the reference implementation of LES, the syntax tree interchange format:

Next up

The next article in this series is “how to write a parser”.