WoofWare.PrattParser 0.2.2

dotnet add package WoofWare.PrattParser --version 0.2.2                
NuGet\Install-Package WoofWare.PrattParser -Version 0.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WoofWare.PrattParser" Version="0.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WoofWare.PrattParser --version 0.2.2                
#r "nuget: WoofWare.PrattParser, 0.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WoofWare.PrattParser as a Cake Addin
#addin nuget:?package=WoofWare.PrattParser&version=0.2.2

// Install WoofWare.PrattParser as a Cake Tool
#tool nuget:?package=WoofWare.PrattParser&version=0.2.2                

WoofWare.PrattParser

Project logo: the face of a cartoon Shiba Inu wearing glasses, looking directly at the viewer, with a background of cartoon basic mathematical symbols. The dog is holding a pencil and a notepad with more symbols written on it. At the bottom is the slogan "EXPRESSION PAWS-ER".

A Pratt parser, based on Matklad's tutorial.

Bug reports welcome; I wouldn't exactly say this is well-tested, although it has worked correctly on the two things I've used it for so far.

See the example for how you should use this. In brief:

  • Define a lexer somehow (which produces a stream of Tokens, where a Token is a type you define).
  • Define what it means for a lexeme to be atomic (this is Expr.atom). Atomic tokens can appear on their own to form an expression all by themselves, or they can be combined or modified using operations specified by non-atomic tokens.
  • Define how the various non-atomic lexemes behave (this is Parser.withUnaryPrefix and friends) to combine subexpressions into larger expressions.

We supply:

  • Parser.withUnaryPrefix, which specifies e.g. that the token ! can appear as a unary prefix of another expression, and that when it does, it indicates (e.g.) negation.
  • Parser.withUnaryPostfix, which specifies e.g. that the token ! can appear as a unary suffix of another expression, and that when it does, it indicates (e.g.) the factorial.
  • Parser.withInfix, which specifies e.g. that the token + can appear between two expressions, and that when it does, it indicates (e.g.) addition.
  • Parser.withBracketLike, which specifies e.g. that the token ( can appear before an expression, and that it's terminated by e.g. ). You can also implement if/then/else this way: that's just a weird kind of bracket and comma (and the else is kind of mixfix: it needs to consume one expression after itself, by contrast with the closing bracket ) which does not).

When specifying how expressions combine, you also provide precedences; numerically larger precedences are higher-precedence (so they bind more tightly). Precedences are given as pairs, so that you can define e.g. left-associativity (resp. right-associativity) by having the infix operator bind more strongly to the right (resp. left). For example, if + has precedence (10, 5), so it binds strongly on the left and weakly on the right:

  • a + b + c is morally a+ b+ c because the + binds strongly to the left;
  • a+ b+ c can only be bracketed as a+ (b+ c) because the rightmost + wants to stick to the b more than it wants to stick to the c;
  • so a + b + c is equal to a + (b + c), i.e. + is right-associative.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on WoofWare.PrattParser:

Package Downloads
WoofWare.NUnitTestRunner.Lib

Library with primitives to allow you to run NUnit tests.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.2 2,161 6/23/2024
0.2.1 318 6/17/2024
0.1.2 1,721 6/3/2024
0.1.1 147 6/3/2024