WoofWare.PrattParser
0.2.1
See the version list below for details.
dotnet add package WoofWare.PrattParser --version 0.2.1
NuGet\Install-Package WoofWare.PrattParser -Version 0.2.1
<PackageReference Include="WoofWare.PrattParser" Version="0.2.1" />
paket add WoofWare.PrattParser --version 0.2.1
#r "nuget: WoofWare.PrattParser, 0.2.1"
// Install WoofWare.PrattParser as a Cake Addin #addin nuget:?package=WoofWare.PrattParser&version=0.2.1 // Install WoofWare.PrattParser as a Cake Tool #tool nuget:?package=WoofWare.PrattParser&version=0.2.1
WoofWare.PrattParser
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
Token
s, where aToken
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 implementif/then/else
this way: that's just a weird kind of bracket and comma (and theelse
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 morallya+ b+ c
because the+
binds strongly to the left;a+ b+ c
can only be bracketed asa+ (b+ c)
because the rightmost+
wants to stick to theb
more than it wants to stick to thec
;- so
a + b + c
is equal toa + (b + c)
, i.e.+
is right-associative.
Product | Versions 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. |
-
.NETStandard 2.0
- FSharp.Core (>= 6.0.0)
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.