Skip to content
프로젝트

소개

Peg(Parsing Expression Grammar)는 Packrat 파서 생성기의 구현입니다.

개발 도구

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
+2
in 1 month
+2

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

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

Go Reference Go Report Card

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.

PEG file syntax

See peg-file-syntax.md for creating your own *.peg file.

Usage

  1. Add peg as a tool dependency

    go get -tool github.com/pointlander/peg@main
    
  2. Create your mygrammar.peg

  3. Add a //go:generate line in a Go source of your package

    //go:generate go tool peg mygrammar.peg
    

    Widespread community design pattern: Add lines like this in doc.go.

  4. Generate mygrammar.peg.go from mygrammar.peg

    go generate
    

Example

This creates the file peg.peg.go

go tool peg -inline -switch peg.peg

Help

go tool peg -h

Development

Requirements

Generate

Bootstrap and generate grammar *.peg.go. This commands should initially be executed once before other commands.

go generate

Build

go build

(go generate required once beforehand)

Set version

Use the version from the tag if the current commit has a tag. If not use the current commit hash.

go build -ldflags "-X main.Version=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)"

Additionally, since Go 1.18 the go command embeds version control information. Read the information:

go version -m peg

Test

go test -short ./...

(go generate required once beforehand)

Lint

golangci-lint run

(go generate required once beforehand)

Format

golangci-lint fmt

Benchmark

go test -benchmem -bench .

(go generate required once beforehand)

Author

Andrew Snodgrass

관련 프로젝트 살펴보기

불러오는 중…