Common commit parser library used by other EasyBuild tools like EasyBuild.ChangelogGen or EasyBuild.CommitLinter.
Thoth.Parser is a parsing library aiming to provide a simple and efficient way to parse text.
It aims to be:
Terse: The syntax should be as simple as possible
Speedy: Go fast enough for most use cases
Modular: Allow for easy extension and modification
Cross-platform:
Thanks to Fable, Thoth.Parser can be used on different runtime
- .NET ✅
- JavaScript 🚧 (planned)
- Python 🚧 (planned)
openThoth.ParseropenThoth.Parser.OperatorstypePoint={
X:int
Y:int}modulePoint =letparser=
Parser.succeed (fun x y ->{
X = x
Y = y
})|. Parser.token "("|. Parser.spaces
|= Parser.int32
|. Parser.spaces
|. Parser.token ","|. Parser.spaces
|= Parser.int32
|. Parser.spaces
|. Parser.token ")"|. Parser.exhaustedYou can install Thoth.Parser via NuGet:
dotnet add package Thoth.ParserThoth.Parser provides two syntaxes:
The pipeline syntax
Parser.dropto ignore the result of a parserParser.keepto keep the result of a parser
The operator syntax
|.equivalent toParser.drop|=equivalent toParser.keep
openThoth.Parser
Parser.succeed (fun x y ->{
X = x
Y = y
})|> Parser.drop (Parser.token "(")|> Parser.drop Parser.spaces
|> Parser.keep Parser.int32
|> Parser.drop Parser.spaces
|> Parser.drop (Parser.token ",")|> Parser.drop Parser.spaces
|> Parser.keep Parser.int32
|> Parser.drop Parser.spaces
|> Parser.drop (Parser.token ")")|> Parser.drop Parser.exhaustedAs you can see, thanks to drop and keep, being short and 4 characters long, the code is aligned and easy to read.
Tip
To make sure the code is aligned, it is recommended to use a monospaced font.
openThoth.ParseropenThoth.Parser.Operators
Parser.succeed (fun x y ->{
X = x
Y = y
})|. Parser.token "("|. Parser.spaces
|= Parser.int32
|. Parser.spaces
|. Parser.token ","|. Parser.spaces
|= Parser.int32
|. Parser.spaces
|. Parser.token ")"|. Parser.exhaustedIf you are using Fantomas to format your F# code, it can happens that Fantomas will format the code in a single line.
letnumber=
Parser.succeed Number.Create
|= Parser.sign
|= Parser.int32
// will be formatted asletnumber=
Parser.succeed Number.Create |= Parser.sign |= Parser.int32To prevent this, you can use fsharp_max_infix_operator_expression setting to minimize the chance of this happening.
Another solution is to add comments between the operators.
letnumber=
Parser.succeed Number.Create
//|= Parser.sign
//|= Parser.int32