Home

Awesome

C# Lex Yacc

Test status Coverage Status .NET Core FOSSA Status

License: MIT NuGet

CSLY is highly inspired by the python lex yacc library (PLY) and aims at easen the writing of lexer and parser with C#.

Getting started

If you're too impatient to further read this readme here is a quick getting started that will guide you through the implementation of a dumb parser.

full documentation

Complete documentation can be found in the wiki

CSLY special features

CSLY provide some special features that make it easier or safer to use.

fully embedded

CSLY has been thought to avoid any extra build step. Parser generators often need a build time step to generate target language source code that do the parse job. Juste include a nuget and configure your lexer/parser in pure C# code.

CSLY does not need a build time step and easen your build / CI process

compact lexer/parser definition

A lexer/parser is defined with only 2 files : * a C# enum for the lexer * a C# class for the parser

Lexeme and parser production rules are defined with c# attributes making notation even more compact. this features already exists with parser combinators (like sprache or Eto.Parse), but productions rules are defined using either BNF or EBNF notation which I think is more natural and easier to understand for maintenance.

Define languages in a very compact and isolated way.

See Lexer for lexers definition. And BNF or EBNF for parser definitions.

Fully and Strictly typed

CSLY is strictly typed, every parser is defines according to its input and output types. For further reading about parser typing, head to typing section to correctly type your parser.

Be more confident in parser inputs and outputs validity.

expression parsing

Many language needs parsing expressions (boolean or numeric). A recursive descent parser is hard to maintain when parsing expressions with multiple precedence levels. So CSLY offers a way to express expression parsing using only operator tokens and precedence level. CSLY will then generates production rules to parse expressions. It also manages precedence and left or right associativity.

Get rid of the burden of writing an expression parser.

see expression parsing

indented languages support

Some languages use indentation to deonte blocks (think of Python or Yaml ). CSLY provides a way to manage this. Head to Indented Languages

Easily use indentation to make your language structure more readable.

generic lexer

Lexemes are often similar from one language to another. So CSLY introduces a Generic Lexer that defines common lexemes that can be reused across languages. furthermore the generic has better performance than a regex based lexer.

Reuse common token definition and take avantage of a better lexer performance.

See Generic lexer for generic lexer and Lexer for general presentation.

What is and what is not CSLY

CSLY is not

CSLY is not a full featured parser generator like ANTLR. Hence you should not use it to define a full featured language (say C# or Java).

CSLY is

CSLY is dedicated to small Domain-Specific Languages that can easily be embedded in a C# code base.

Installation

Install from the NuGet gallery GUI or with the Package Manager Console using the following command:

Install-Package sly

or with dotnet core

dotnet add package sly

License

FOSSA Status