Popularity
7.4
Stable
Activity
3.6
-
967
30
119

Programming language: Go
License: BSD 3-clause "New" or "Revised" License
Latest version: v1.0.0

peg alternatives and similar packages

Based on the "Other Software" category.
Alternatively, view peg alternatives based on common mentions on social networks and blogs.

  • syncthing

    Open Source Continuous File Synchronization
  • hugo

    10.0 9.8 peg VS hugo
    The world’s fastest framework for building websites.
  • Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
    Promo www.influxdata.com
    InfluxDB Logo
  • restic

    Fast, secure, efficient backup program
  • croc

    Easily and securely send things from one computer to another :crocodile: :package:
  • Gor

    9.8 4.8 peg VS Gor
    GoReplay is an open-source tool for capturing and replaying live HTTP traffic into a test environment in order to continuously test your system with real data. It can be used to increase confidence in code deployments, configuration changes and infrastructure changes.
  • Seaweed File System

    SeaweedFS is a fast distributed storage system for blobs, objects, files, and data lake, for billions of files! Blob store has O(1) disk seek, cloud tiering. Filer supports Cloud Drive, cross-DC active-active replication, Kubernetes, POSIX FUSE mount, S3 API, S3 Gateway, Hadoop, WebDAV, encryption, Erasure Coding. [Moved to: https://github.com/seaweedfs/seaweedfs]
  • rkt

    9.7 0.4 peg VS rkt
    An App Container runtime that integrates with init systems, is compatible with other container formats like Docker, and supports alternative execution engines like KVM.
  • limetext

    Open source API-compatible alternative to the text editor Sublime Text
  • toxiproxy

    :alarm_clock: :fire: A TCP proxy to simulate network and system conditions for chaos and resiliency testing
  • LiteIDE

    9.5 5.8 L1 peg VS LiteIDE
    LiteIDE is a simple, open source, cross-platform Go IDE.
  • confd

    Manage local application configuration files using templates and data from etcd or consul
  • Comcast

    Simulating shitty network connections so you can build better systems.
  • drive

    Google Drive client for the commandline
  • nes

    9.2 2.3 peg VS nes
    NES emulator written in Go.
  • scc

    9.1 8.2 peg VS scc
    Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go
  • Duplicacy

    A new generation cloud backup tool
  • heka

    DEPRECATED: Data collection and processing made easy.
  • fleet

    A Distributed init System.
  • blocky

    Fast and lightweight DNS proxy as ad-blocker for local network with many features
  • Docker

    Notary is a project that allows anyone to have trust over arbitrary collections of data
  • myLG

    Network Diagnostic Tool
  • Juju

    Orchestration engine that enables the deployment, integration and lifecycle management of applications at any scale, on any infrastructure (Kubernetes or otherwise).
  • snap

    The open telemetry framework
  • Stack Up

    Super simple deployment tool - think of it like 'make' for a network of servers
  • GoBoy

    Multi-platform Nintendo Game Boy Color emulator written in Go
  • lgo

    8.3 0.0 peg VS lgo
    Interactive Go programming with Jupyter
  • Documize

    Modern Confluence alternative designed for internal & external docs, built with Go + EmberJS
  • Circuit

    Circuit: Dynamic cloud orchestration http://gocircuit.org
  • GoDNS

    A dynamic DNS client tool that supports AliDNS, Cloudflare, Google Domains, DNSPod, HE.net & DuckDNS & DreamHost, etc, written in Go.
  • borg

    Search and save shell snippets without leaving your terminal
  • Plik

    Plik is a temporary file upload system (Wetransfer like) in Go.
  • vFlow

    Enterprise Network Flow Collector (IPFIX, sFlow, Netflow)
  • shell2http

    Executing shell commands via HTTP server
  • portal

    Portal is a quick and easy command-line file transfer utility from any computer to another.
  • Gokapi

    Lightweight selfhosted Firefox Send alternative without public upload. AWS S3 supported.
  • Go Package Store

    An app that displays updates for the Go packages in your GOPATH.
  • Guora

    🖖🏻 A self-hosted Quora like web application written in Go 基于 Golang 类似知乎的私有部署问答应用 包含问答、评论、点赞、管理后台等功能
  • Leaps

    A pair programming service using operational transforms
  • Postman

    CLI tool for batch-sending email via any SMTP server.
  • gfile

    Direct file transfer over WebRTC
  • gocc

    Parser / Scanner Generator
  • Gebug

    Debug Dockerized Go applications better
  • mockingjay

    Fake server, Consumer Driven Contracts and help with testing performance from one configuration file with zero system dependencies and no coding whatsoever
  • sake

    :robot: sake is a task runner for local and remote hosts
  • ipe

    6.4 0.0 peg VS ipe
    An open source Pusher server implementation compatible with Pusher client libraries written in GO
  • yai

    6.4 8.1 peg VS yai
    Your AI powered terminal assistant.
  • woke

    Detect non-inclusive language in your source code.
  • GoNB

    GoNB, a Go Notebook Kernel for Jupyter
  • ide

    6.0 0.0 peg VS ide
    A Go code editor. With debugging and Autocomplete. 一个 Go 代码编辑器,具有 DEBUGGING 和 AUTOCOMPLETE
  • tcpprobe

    Modern TCP tool and service for network performance observability.

Do you think we are missing an alternative of peg or a related project?

Add another 'Other Software' Package

README

PEG, an Implementation of a Packrat Parsing Expression Grammar in Go

GoDoc Go Report Card Coverage

A Parsing Expression Grammar ( hence peg) is a way to create grammars similar in principle to regular expressions but which allow better code integration. Specifically, peg is an implementation of the Packrat parser generator originally implemented as peg/leg by Ian Piumarta in C. A Packrat parser is a "descent recursive parser" capable of backtracking and negative look-ahead assertions which are problematic for regular expression engines .

See Also

Installing

go get -u github.com/pointlander/peg

Building

Using Pre-Generated Files

go install

Generating Files Yourself

You should only need to do this if you are contributing to the library, or if something gets messed up.

go run build.go or go generate

With tests:

go run build.go test

Usage

peg [<option>]... <file>

Usage of peg:
  -inline
      parse rule inlining
  -noast
      disable AST
  -output string
      specify name of output file
  -print
      directly dump the syntax tree
  -strict
      treat compiler warnings as errors
  -switch
      replace if-else if-else like blocks with switch blocks
  -syntax
      print out the syntax tree
  -version
      print the version and exit

Sample Makefile

This sample Makefile will convert any file ending with .peg into a .go file with the same name. Adjust as needed.

.SUFFIXES: .peg .go

.peg.go:
    peg -noast -switch -inline -strict -output $@ $<

all: grammar.go

Use caution when picking your names to avoid overwriting existing .go files. Since only one PEG grammar is allowed per Go package (currently) the use of the name grammar.peg is suggested as a convention:

grammar.peg
grammar.go

PEG File Syntax

First declare the package name and any import(s) required:

package <package name>

import <import name>

Then declare the parser:

type <parser name> Peg {
    <parser state variables>
}

Next declare the rules. Note that the main rules are described below but are based on the peg/leg rules which provide additional documentation.

The first rule is the entry point into the parser:

<rule name> <- <rule body>

The first rule should probably end with !. to indicate no more input follows.

first <- . !.

This is often set to END to make PEG rules more readable:

END <- !.

. means any character matches. For zero or more character matches, use:

repetition <- .*

For one or more character matches, use:

oneOrMore <- .+

For an optional character match, use:

optional <- .?

If specific characters are to be matched, use single quotes:

specific <- 'a'* 'bc'+ 'de'?

This will match the string "aaabcbcde".

For choosing between different inputs, use alternates:

prioritized <- 'a' 'a'* / 'bc'+ / 'de'?

This will match "aaaa" or "bcbc" or "de" or "". The matches are attempted in order.

If the characters are case insensitive, use double quotes:

insensitive <- "abc"

This will match "abc" or "Abc" or "ABc" and so on.

For matching a set of characters, use a character class:

class <- [a-z]

This will match "a" or "b" or all the way to "z".

For an inverse character class, start with a caret:

inverse <- [^a-z]

This will match anything but "a" or "b" or all the way to "z".

If the character class is case insensitive, use double brackets:

insensitive <- [[A-Z]]

(Note that this is not available in regular expression syntax.)

Use parentheses for grouping:

grouping <- (rule1 / rule2) rule3

For looking ahead a match (predicate), use:

lookAhead <- &rule1 rule2

For inverse look ahead, use:

inverse <- !rule1 rule2

Use curly braces for Go code:

gocode <- { fmt.Println("hello world") }

For string captures, use less than and greater than:

capture <- <'capture'> { fmt.Println(text) }

Will print out "capture". The captured string is stored in buffer[begin:end].

Testing Complex Grammars

Testing a grammar usually requires more than the average unit testing with multiple inputs and outputs. Grammars are also usually not for just one language implementation. Consider maintaining a list of inputs with expected outputs in a structured file format such as JSON or YAML and parsing it for testing or using one of the available options for Go such as Rob Muhlestein's tinout package.

Files

  • bootstrap/main.go - bootstrap syntax tree of peg
  • tree/peg.go - syntax tree and code generator
  • peg.peg - peg in its own language

Author

Andrew Snodgrass

Projects That Use peg

Here are some projects that use peg to provide further examples of PEG grammars: