You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

Pegasus

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons

Pegasus

A PEG (Parsing Expression Grammar) parser compiler that integrates with MSBuild / Visual Studio. Features selective packrat parsing and syntax-highlighting output.

4.121.0-alpha0022
unpublished
Source
nugetNuGet
Maintainers
1
Created
Source

Pegasus

Pegasus is a PEG-style parser generator for C# that integrates with MSBuild and Visual Studio.

Join the Chat

MIT Licensed Get it on NuGet

Appveyor Build Test Coverage Pre-release packages available

Visual Studio Extension

Getting Started

The easiest way to get a copy of Pegasus is to install the Pegasus NuGet package in Visual Studio.

PM> Install-Package Pegasus

Due to a limitation in Visual Studio, you will need to reload your project for the 'PegGrammar' build action to be recognized.

Once you have the package installed, files in your project marked as 'PegGrammar' in the properties window will be compiled to their respective .peg.g.cs parser classes before every build. These parser classes will be automatically included in compilation.

For help with grammar syntax, see the syntax guide wiki entry

Example

Here is an example of a simple parser for mathematical expressions:

@namespace MyProject
@classname ExpressionParser

additive <double> -memoize
    = left:additive "+" right:multiplicative { left + right }
    / left:additive "-" right:multiplicative { left - right }
    / multiplicative

multiplicative <double> -memoize
    = left:multiplicative "*" right:power { left * right }
    / left:multiplicative "/" right:power { left / right }
    / power

power <double>
    = left:primary "^" right:power { Math.Pow(left, right) }
    / primary

primary <double> -memoize
    = decimal
    / "-" primary:primary { -primary }
    / "(" additive:additive ")" { additive }

decimal <double>
    = value:([0-9]+ ("." [0-9]+)?) { double.Parse(value) }

This will take mathematical expressions as strings and evaluate them with the proper order of operations and associativity to produce a result as a decimal.

The above parser would be used like so:

var parser = new MyProject.ExpressionParser();
var result = parser.Parse("5.1+2*3");
Console.WriteLine(result); // Outputs "11.1".

Keywords

parser

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts