sly 3.5.0-alpha6
dotnet add package sly --version 3.5.0-alpha6
NuGet\Install-Package sly -Version 3.5.0-alpha6
<PackageReference Include="sly" Version="3.5.0-alpha6" />
paket add sly --version 3.5.0-alpha6
#r "nuget: sly, 3.5.0-alpha6"
// Install sly as a Cake Addin #addin nuget:?package=sly&version=3.5.0-alpha6&prerelease // Install sly as a Cake Tool #tool nuget:?package=sly&version=3.5.0-alpha6&prerelease
C# lex and yacc
Csly is inspired by the Python lex yacc library (PLY) and aims to simplify generating lexer/parsers in C#.
Getting started
If you'd like to get coding right away, read the quick getting-started guide, which will guide you through the implementation of a basic parser.
Documentation and examples
Complete documentation can be found in the wiki. For a list of more advanced samples check out the samples folder in the repo.
Csly special features
Csly is packed with special features that make it simpler to use, maintainable, and type-safe.
Fully embeddable
Csly has been designed to avoid extra build steps. Parser generators often need a build-time step to generate target language source code. That is not the case with csly. A simple Nuget command will configure csly for use in a 100% .NET implementation.
Csly does not need a build-time step, simplifying the build/CI process
Compact lexer/parser definition
The csly lexer/parser is defined with only 2 types:
- a C#
enum
for the lexer, - a C#
class
for the parser.
Lexeme and parser production rules are defined using C# custom attributes making your code compact and readable. Although these features already exist with parser combinators (like Sprache or Eto.Parse), csly can use productions rules defined using either BNF or EBNF notation, which I think is more natural and easier to understand, assuring maintainability.
Define languages in a very compact and dependency-free way
See Lexer for lexers definition and BNF or EBNF for parser definitions.
Fully and Strictly typed
Csly is strictly typed, so every parser you define renders according to its input and output types. For additional details on parser typing, head to the parser definition section.
Be more confident that your parser will generate valid inputs and outputs.
Expression parsing
Many domain-specific languages need parsing expressions (boolean or numeric). A recursive-descent parser is hard to maintain when parsing expressions have multiple precedence levels. For that reason, csly offers a way to generate expression-parsing rules using only operator tokens and a simple-to-understand precedence scheme. Csly will then generate production rules to parse expressions, managing precedence and either left-or-right associativity.
Avoid burdensome hand-made expression parser implementations.
Indentable languages support
Some languages use indentation to denote functional blocks, like Python or Yaml. Csly provides native support for indentation. Head to Indented Languages
Easily use indentation to make your language more readable.
Preserve comments
Comments or whitespace are almost every time discardable. But sometimes it makes sens to preserve them :
- use comments to generate auto doc (think javadoc, c#'s xmldoc or python's docstring )
- introduce meta data without cluttering your grammar
So CSLY borrowed the (antlr channel concept)[https://datacadamia.com/antlr/channel]. Every lexeme can be redirected to a specific channel. By default comments go to channel 2.
This feature is already available on branch dev but not deployed in any nuget package. Documentation is also a work in progress event though you can have it a glance looking at (EBNF unit tests)[https://github.com/b3b00/csly/blob/dev/ParserTests/EBNFTests.cs] :
- TestIndentedParserNestedBlocks
- TestIndentedParserWithEolAwareness
- TestIndentedParserWithEolAwareness2
- TestIssue213WithChannels
Generic lexer
Lexemes are often similar from one language to another. Csly introduces a generic lexer that defines common lexemes and which can be reused across languages. The built-in generic lexer has better performance than a regex-based lexer.
Reuse common token definition and take advantage of better lexer performance.
See Generic lexer for the generic lexer implementation and Lexer for a general presentation on rolling your own.
What Csly is and isn't
Csly is not
Csly is not a fully-featured parser generator like ANTLR. You should therefore not use it to define strong-typed languages like C# or Java.
Csly is
Csly is perfect for small domain-specific languages (DSLs) that can be bundled in C# applications for end-users to interact with your application using natural language, for example.
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
Special thanks to
<a href="https://jb.gg/OpenSource"><img height="200" src="src/logos/jetbrains-variant-2.svg"><a>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
- Newtonsoft.Json (>= 13.0.2)
- System.Collections.Immutable (>= 7.0.0)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.1
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
- Newtonsoft.Json (>= 13.0.2)
- System.Collections.Immutable (>= 7.0.0)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
net6.0
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
- Newtonsoft.Json (>= 13.0.2)
- System.Collections.Immutable (>= 7.0.0)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
-
net7.0
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
- Newtonsoft.Json (>= 13.0.2)
- System.Collections.Immutable (>= 7.0.0)
- System.Memory (>= 4.5.5)
- System.ValueTuple (>= 4.5.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on sly:
Package | Downloads |
---|---|
CoreLisp
.net core lisp interpreter |
|
formulae
Package Description |
|
LuckyFish.Json
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on sly:
Repository | Stars |
---|---|
b3b00/csly
a C# embeddable lexer and parser generator (.Net core)
|
Version | Downloads | Last updated |
---|---|---|
3.5.0-alpha6 | 108 | 9/13/2024 |
3.5.0-alpha5 | 87 | 9/12/2024 |
3.5.0-alpha4 | 94 | 9/11/2024 |
3.5.0-alpha3 | 94 | 9/11/2024 |
3.5.0-alpha2 | 95 | 9/11/2024 |
3.5.0-alpha1 | 90 | 9/10/2024 |
3.4.6 | 40 | 11/8/2024 |
3.4.5 | 118 | 11/6/2024 |
3.4.4 | 58 | 11/5/2024 |
3.4.3 | 69 | 11/4/2024 |
3.4.2 | 78 | 11/3/2024 |
3.4.1 | 67 | 11/1/2024 |
3.4.1-alpha1 | 71 | 10/29/2024 |
3.4.0 | 119 | 10/26/2024 |
3.3.5 | 283 | 10/15/2024 |
3.3.4 | 80 | 10/14/2024 |
3.3.3 | 73 | 10/14/2024 |
3.3.2 | 77 | 10/14/2024 |
3.3.1 | 112 | 10/11/2024 |
3.3.0 | 122 | 10/10/2024 |
3.2.9 | 1,178 | 8/23/2024 |
3.2.9-alpha1 | 110 | 8/23/2024 |
3.2.8 | 1,722 | 7/19/2024 |
3.2.7 | 176 | 7/17/2024 |
3.2.6 | 118 | 7/16/2024 |
3.2.5 | 96 | 7/16/2024 |
3.2.4 | 105 | 7/16/2024 |
3.2.3 | 163 | 7/11/2024 |
3.2.2 | 124 | 7/8/2024 |
3.2.1 | 113 | 7/5/2024 |
3.2.0 | 126 | 7/3/2024 |
3.1.9 | 116 | 7/3/2024 |
3.1.8 | 134 | 7/3/2024 |
3.1.8-alpha3 | 113 | 7/2/2024 |
3.1.8-alpha2 | 91 | 7/2/2024 |
3.1.8-alpha1 | 115 | 7/2/2024 |
3.1.7 | 326 | 6/13/2024 |
3.1.6 | 390 | 5/29/2024 |
3.1.5 | 477 | 5/10/2024 |
3.1.4 | 253 | 5/2/2024 |
3.1.3 | 125 | 4/30/2024 |
3.1.2 | 107 | 4/29/2024 |
3.1.1 | 115 | 4/26/2024 |
3.1.0 | 454 | 4/19/2024 |
3.0.1 | 760 | 4/17/2024 |
3.0.0 | 115 | 4/17/2024 |
2.9.9 | 1,633 | 4/8/2024 |
2.9.8 | 4,841 | 1/5/2024 |
2.9.7.1 | 455 | 12/2/2023 |
2.9.7 | 3,210 | 10/19/2023 |
2.9.6.1 | 7,116 | 8/16/2023 |
2.9.6 | 168 | 8/16/2023 |
2.9.5.1 | 244 | 8/9/2023 |
2.9.5 | 167 | 8/8/2023 |
2.9.4.7 | 2,770 | 5/29/2023 |
2.9.4.6 | 4,372 | 3/31/2023 |
2.9.4.6-alpha | 202 | 3/29/2023 |
2.9.4.5 | 4,253 | 3/13/2023 |
2.9.4.4 | 585 | 2/21/2023 |
2.9.4.3 | 787 | 2/12/2023 |
2.9.4.2 | 273 | 2/12/2023 |
2.9.4.2-alpha3 | 170 | 2/7/2023 |
2.9.4.2-alpha2 | 168 | 2/7/2023 |
2.9.4.2-alpha | 256 | 1/31/2023 |
2.9.4.1 | 384 | 1/30/2023 |
2.9.4 | 445 | 1/12/2023 |
2.9.3.1 | 1,400 | 12/30/2022 |
2.9.3 | 939 | 12/7/2022 |
2.9.2.2 | 489 | 11/23/2022 |
2.9.2.1 | 525 | 11/9/2022 |
2.9.2 | 510 | 11/2/2022 |
2.9.1.1 | 679 | 10/17/2022 |
2.9.1 | 1,351 | 9/12/2022 |
2.9.0.9 | 1,327 | 9/4/2022 |
2.9.0.8 | 439 | 9/2/2022 |
2.9.0.7 | 453 | 9/1/2022 |
2.9.0.6 | 507 | 8/31/2022 |
2.9.0.5 | 3,926 | 8/8/2022 |
2.9.0.4 | 597 | 7/3/2022 |
2.9.0.3 | 522 | 7/1/2022 |
2.9.0.2 | 658 | 6/29/2022 |
2.9.0.1 | 474 | 6/29/2022 |
2.9.0 | 532 | 6/28/2022 |
2.8.0.5 | 5,578 | 3/22/2022 |
2.8.0.4-alpha | 219 | 1/26/2022 |
2.8.0.3 | 19,976 | 12/11/2021 |
2.8.0.2 | 1,048 | 12/1/2021 |
2.8.0.1 | 902 | 12/1/2021 |
2.8.0 | 5,496 | 11/24/2021 |
2.8.0-alpha | 6,004 | 11/24/2021 |
2.7.0.5 | 409 | 11/5/2021 |
2.7.0.4 | 350 | 11/5/2021 |
2.7.0.4-alpha.2 | 190 | 8/16/2021 |
2.7.0.4-alpha | 250 | 8/16/2021 |
2.7.0.3 | 2,121 | 6/16/2021 |
2.7.0.2 | 462 | 6/14/2021 |
2.7.0.1 | 436 | 6/1/2021 |
2.7.0 | 11,267 | 5/11/2021 |
2.7.0-alpha | 332 | 11/30/2020 |
2.6.4.2 | 1,115 | 4/15/2021 |
2.6.4.1 | 1,051 | 3/3/2021 |
2.6.4 | 510 | 2/22/2021 |
2.6.4-beta | 246 | 2/22/2021 |
2.6.4-bea | 257 | 2/22/2021 |
2.6.3.1 | 586 | 1/2/2021 |
2.6.3 | 556 | 11/23/2020 |
2.6.2.2 | 529 | 11/16/2020 |
2.6.2.1 | 554 | 11/7/2020 |
2.6.2 | 457 | 11/6/2020 |
2.6.1 | 3,192 | 10/5/2020 |
2.6.0.6 | 559 | 10/5/2020 |
2.6.0.5 | 844 | 9/4/2020 |
2.6.0.4 | 538 | 8/24/2020 |
2.6.0.3 | 584 | 8/4/2020 |
2.6.0.2 | 578 | 8/3/2020 |
2.6.0.1 | 1,174 | 6/12/2020 |
2.6.0 | 595 | 5/26/2020 |
2.5.0.1 | 1,788 | 4/21/2020 |
2.5.0 | 565 | 4/15/2020 |
2.4.2 | 2,244 | 2/21/2020 |
2.4.1.6 | 608 | 2/17/2020 |
2.4.1.5 | 675 | 1/28/2020 |
2.4.1.4 | 664 | 1/3/2020 |
2.4.1.3 | 608 | 1/2/2020 |
2.4.1.2 | 610 | 1/2/2020 |
2.4.1.1 | 606 | 12/17/2019 |
2.4.1 | 611 | 11/27/2019 |
2.4.0.6 | 598 | 11/21/2019 |
2.4.0.5 | 574 | 11/20/2019 |
2.4.0.4 | 590 | 11/18/2019 |
2.4.0.3 | 2,004 | 6/14/2019 |
2.4.0.1 | 669 | 6/14/2019 |
2.4.0 | 649 | 6/13/2019 |
2.3.0.1 | 755 | 5/15/2019 |
2.3.0 | 684 | 5/15/2019 |
2.2.5.3 | 755 | 3/22/2019 |
2.2.5.2 | 716 | 3/8/2019 |
2.2.5.1 | 1,709 | 12/27/2018 |
2.2.5 | 708 | 12/24/2018 |
2.2.4 | 754 | 12/4/2018 |
2.2.3 | 812 | 10/26/2018 |
2.2.2 | 816 | 9/21/2018 |
2.2.1 | 956 | 8/9/2018 |
2.2.0 | 957 | 7/25/2018 |
2.1.3 | 1,045 | 6/18/2018 |
2.1.2 | 1,054 | 6/10/2018 |
2.1.1 | 1,021 | 5/21/2018 |
2.1.0 | 1,052 | 5/14/2018 |
2.0.7 | 1,240 | 3/8/2018 |
2.0.6.2 | 1,033 | 3/6/2018 |
2.0.3 | 1,088 | 12/12/2017 |
2.0.2 | 999 | 11/30/2017 |
2.0.1 | 987 | 11/11/2017 |
1.3.5 | 992 | 10/30/2017 |
1.3.1 | 963 | 10/26/2017 |
1.0.4 | 1,287 | 6/16/2017 |