Gnosis.PEG 1.1.61

Parsing Expression Grammar

This is a code-centric library for parsing of PEG grammars in .NET, producing strongly typed outputs. It operates via cursors, and ships with cursors for processing text-streams, token-arrays and XML trees. It contains LINQ extensions to cleanly express grammars directly in code using the C# Integrated Query syntax, and an XML based AST for grammars that it can convert to executable code, as well as a grammar for parsing a human-readable syntax into this AST.

Todo: something about performance and expressability.

Todo: overview and concepts

Cursors, Rules and Results.

Grammar helpers are static classes with type definitions and function helpers for creating rules for a specific cursor type, simplifying definitions by omitting the cursor type.

Grammar formats.

Todo: Cursors

TextTokenCursor, TokenCursor and Tokenizer

XNodeCursor

Todo: list of rule types

Terminal rules

Nonterminal rules

Todo: Grammar helpers

  • WithFeedback

    Provides an error-boundary around a rule, replacing all inner errors with a single provided error message.

  • EndOfInput

    Creates a rule matching the end-of-input token.

  • Choice

    Creates a rule that tries match each of its inner rules in turn, returning success when the first rule matches, or error if none match.

  • Optional

    Wraps an inner rule, returning its result if successful, or a successful default-result if not.

  • ZeroOrOne

    Wraps the Range rule, with min=0 and max=1.

  • ZeroOrMore

    Wraps the Range rule, with min=0 and max=infinity

  • OneOrMore

    Wraps the Range rule, with min=1 and max=infinity

  • Range

  • Between

  • PositiveLookahead

  • NegativeLookahead

  • Label

  • Chain

  • LeftAssociativeRange

TokenGrammar

  • Token

    Creates a rule for matching a token. Has overloads for matching a TokenType or aa constant that is specified directly.

XNodeGrammar

  • Element

  • Structure

  • Content

  • Attribute

Todo: describe the XML grammar AST

Todo: describe the simple grammar format

Build

Before commiting run

dotnet format

this will use .editorconfig and format all files in the solution.

CI Pipeline

dotnet restore
dotnet format --verify-no-changes
dotnet build -c Release --no-restore
dotnet test -c Release --no-restore --no-build
dotnet pack -c Release --no-restore --no-build

No packages depend on Gnosis.PEG.

.NET 8.0

  • No dependencies.

Version Downloads Last updated
1.1.61 48 05/22/2024
0.1.57 193 04/02/2022
0.1.56 185 04/02/2022