Skip to content
teo-tsirpanisPublic

About

The most advanced LR(1) parsing library for C# and F#

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

120 stars

Watchers

2 watching

Forks

Repository files navigation

Licensed under the MIT License NuGet CI CII Best Practices OpenSSF Scorecard Discord Server

Farkle

Farkle is a .NET library for building fast, reliable text parsers in C# and F#. It creates LALR(1) and IELR(1) parsers through an API that resembles parser combinators, combining generated-parser performance and reliability, with a source-code-first development experience.

Farkle follows the GOLD Parser approach of serializing grammars to a binary format. This makes grammars available for introspection, and enables features such as Scriban template rendering, and ahead-of-time precompilation for faster startup and compile-time grammar validation.

Quick Start

Install Farkle from NuGet, then define and build a grammar in code:

C#

using Farkle;
using Farkle.Builder;

var number = Terminals.Int32("Number");
var addExpression = Nonterminal.Create("Add Expression",
	number.Extended().Append("+").Extend(number).Finish((n1, n2) => n1 + n2)
);

var parser = addExpression.Build();
var result = parser.Parse("1 + 2"); // Whitespace is ignored by default.
Console.WriteLine(result); // 3

F#

open Farkle
open Farkle.Builder

let number = Terminals.Int32("Number")
let addExpression = "Add Expression" ||= [
	!@ number .>> "+" .>>. number => (fun n1 n2 -> n1 + n2)
]

let parser = GrammarBuilder.build addExpression
let result = CharParser.parseString parser "1 + 2" // Whitespace is ignored by default.
printfn "%O" result // 3

Documentation

Contributing

Issues and pull requests are welcome at teo-tsirpanis/Farkle. See the contribution guide for development and submission guidance.

Maintainer(s)

About

The most advanced LR(1) parsing library for C# and F#

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

120 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages