Skip to content

Commit

Permalink
Switch to participle/v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Nov 26, 2020
1 parent 036731d commit 6fd6e8c
Show file tree
Hide file tree
Showing 46 changed files with 106 additions and 100 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A dead simple parser package for Go

[![Godoc](https://godoc.org/github.com/alecthomas/participle?status.svg)](http://godoc.org/github.com/alecthomas/participle) [![CircleCI](https://img.shields.io/circleci/project/github/alecthomas/participle.svg)](https://circleci.com/gh/alecthomas/participle)
[![Go Report Card](https://goreportcard.com/badge/github.com/alecthomas/participle)](https://goreportcard.com/report/github.com/alecthomas/participle) [![Slack chat](https://img.shields.io/static/v1?logo=slack&style=flat&label=slack&color=green&message=gophers)](https://gophers.slack.com/messages/CN9DS8YF3)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/alecthomas/participle/v2)](https://pkg.go.dev/github.com/alecthomas/participle/v2) [![CircleCI](https://img.shields.io/circleci/project/github/alecthomas/participle.svg)](https://circleci.com/gh/alecthomas/participle)
[![Go Report Card](https://goreportcard.com/badge/github.com/alecthomas/participle/v2)](https://goreportcard.com/report/github.com/alecthomas/participle/v2) [![Slack chat](https://img.shields.io/static/v1?logo=slack&style=flat&label=slack&color=green&message=gophers)](https://gophers.slack.com/messages/CN9DS8YF3)

<!-- TOC depthFrom:2 insertAnchor:true updateOnSave:true -->

Expand Down Expand Up @@ -208,8 +208,8 @@ your own lexer.
Configure your parser with a lexer via `participle.Lexer()`.

To use your own Lexer you will need to implement two interfaces:
[Definition](https://godoc.org/github.com/alecthomas/participle/lexer#Definition)
and [Lexer](https://godoc.org/github.com/alecthomas/participle/lexer#Lexer).
[Definition](https://pkg.go.dev/github.com/alecthomas/participle/v2#Definition)
and [Lexer](https://pkg.go.dev/github.com/alecthomas/participle/v2#Lexer).

<a id="markdown-experimental---code-generation" name="experimental---code-generation"></a>
### Experimental - code generation
Expand All @@ -224,25 +224,25 @@ while producing O(1) garbage.
<a id="markdown-options" name="options"></a>
## Options

The Parser's behaviour can be configured via [Options](https://godoc.org/github.com/alecthomas/participle#Option).
The Parser's behaviour can be configured via [Options](https://pkg.go.dev/github.com/alecthomas/participle/v2#Option).

<a id="markdown-examples" name="examples"></a>
## Examples

There are several [examples](https://github.com/alecthomas/participle/tree/master/_examples) included:
There are several [examples](https://github.com/alecthomas/participle/v2/tree/master/_examples) included:

Example | Description
--------|---------------
[BASIC](https://github.com/alecthomas/participle/tree/master/_examples/basic) | A lexer, parser and interpreter for a [rudimentary dialect](https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora058.html) of BASIC.
[EBNF](https://github.com/alecthomas/participle/tree/master/_examples/ebnf) | Parser for the form of EBNF used by Go.
[Expr](https://github.com/alecthomas/participle/tree/master/_examples/expr) | A basic mathematical expression parser and evaluator.
[GraphQL](https://github.com/alecthomas/participle/tree/master/_examples/graphql) | Lexer+parser for GraphQL schemas
[HCL](https://github.com/alecthomas/participle/tree/master/_examples/hcl) | A parser for the [HashiCorp Configuration Language](https://github.com/hashicorp/hcl).
[INI](https://github.com/alecthomas/participle/tree/master/_examples/ini) | An INI file parser.
[Protobuf](https://github.com/alecthomas/participle/tree/master/_examples/protobuf) | A full [Protobuf](https://developers.google.com/protocol-buffers/) version 2 and 3 parser.
[SQL](https://github.com/alecthomas/participle/tree/master/_examples/sql) | A *very* rudimentary SQL SELECT parser.
[Thrift](https://github.com/alecthomas/participle/tree/master/_examples/thrift) | A full [Thrift](https://thrift.apache.org/docs/idl) parser.
[TOML](https://github.com/alecthomas/participle/blob/master/_examples/toml/main.go) | A [TOML](https://github.com/toml-lang/toml) parser.
[BASIC](https://github.com/alecthomas/participle/v2/tree/master/_examples/basic) | A lexer, parser and interpreter for a [rudimentary dialect](https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora058.html) of BASIC.
[EBNF](https://github.com/alecthomas/participle/v2/tree/master/_examples/ebnf) | Parser for the form of EBNF used by Go.
[Expr](https://github.com/alecthomas/participle/v2/tree/master/_examples/expr) | A basic mathematical expression parser and evaluator.
[GraphQL](https://github.com/alecthomas/participle/v2/tree/master/_examples/graphql) | Lexer+parser for GraphQL schemas
[HCL](https://github.com/alecthomas/participle/v2/tree/master/_examples/hcl) | A parser for the [HashiCorp Configuration Language](https://github.com/hashicorp/hcl).
[INI](https://github.com/alecthomas/participle/v2/tree/master/_examples/ini) | An INI file parser.
[Protobuf](https://github.com/alecthomas/participle/v2/tree/master/_examples/protobuf) | A full [Protobuf](https://developers.google.com/protocol-buffers/) version 2 and 3 parser.
[SQL](https://github.com/alecthomas/participle/v2/tree/master/_examples/sql) | A *very* rudimentary SQL SELECT parser.
[Thrift](https://github.com/alecthomas/participle/v2/tree/master/_examples/thrift) | A full [Thrift](https://thrift.apache.org/docs/idl) parser.
[TOML](https://github.com/alecthomas/participle/v2/blob/master/_examples/toml/main.go) | A [TOML](https://github.com/toml-lang/toml) parser.

Included below is a full GraphQL lexer and parser:

Expand All @@ -256,9 +256,9 @@ import (
"github.com/alecthomas/kong"
"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"
)

type File struct {
Expand Down Expand Up @@ -377,7 +377,7 @@ A compiled `Parser` instance can be used concurrently. A `LexerDefinition` can b

There are a few areas where Participle can provide useful feedback to users of your parser.

1. Errors returned by [Parser.Parse*()](https://godoc.org/github.com/alecthomas/participle#Parser.ParseReader) will be of type [Error](https://godoc.org/github.com/alecthomas/participle#Error). This will contain positional information where available.
1. Errors returned by [Parser.Parse*()](https://pkg.go.dev/github.com/alecthomas/participle/v2#Parser.ParseReader) will be of type [Error](https://pkg.go.dev/github.com/alecthomas/participle/v2#Error). This will contain positional information where available.
2. Participle will make a best effort to return as much of the AST up to the error location as possible.
3. Any node in the AST containing a field `Pos lexer.Position` will be automatically
populated from the nearest matching token.
Expand All @@ -403,7 +403,7 @@ recursion must be eliminated by restructuring your grammar.
Participle supports outputting an EBNF grammar from a Participle parser. Once
the parser is constructed simply call `String()`.

eg. The [GraphQL example](https://github.com/alecthomas/participle/blob/cbe0cc62a3ad95955311002abd642f11543cb8ed/_examples/graphql/main.go#L14-L61)
eg. The [GraphQL example](https://github.com/alecthomas/participle/v2/blob/cbe0cc62a3ad95955311002abd642f11543cb8ed/_examples/graphql/main.go#L14-L61)
gives in the following EBNF:

```ebnf
Expand All @@ -416,4 +416,4 @@ TypeRef = "[" TypeRef "]" | ident "!"? .
Value = ident .
Schema = "schema" "{" Field* "}" .
Enum = "enum" ident "{" ident* "}" .
```
```
2 changes: 1 addition & 1 deletion _examples/basic/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"strings"

"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/v2/lexer"
)

// Parse a BASIC program.
Expand Down
2 changes: 1 addition & 1 deletion _examples/basic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

type Evaluatable interface {
Expand Down
6 changes: 3 additions & 3 deletions _examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/alecthomas/kong"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion _examples/ebnf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"gopkg.in/alecthomas/kingpin.v2"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion _examples/expr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/alecthomas/kong"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

var cli struct {
Expand Down
2 changes: 1 addition & 1 deletion _examples/expr2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/alecthomas/kong"
"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

// Based on http://www.craftinginterpreters.com/parsing-expressions.html
Expand Down
6 changes: 3 additions & 3 deletions _examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/alecthomas/participle/_examples
module github.com/alecthomas/participle/v2/_examples

go 1.14

require (
github.com/alecthomas/go-thrift v0.0.0-20170109061633-7914173639b2
github.com/alecthomas/kong v0.2.11
github.com/alecthomas/participle v0.4.1
github.com/alecthomas/participle/v2 v2.0.0-alpha1
github.com/alecthomas/repr v0.0.0-20200325044227-4184120f674c
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/stretchr/testify v1.5.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

replace github.com/alecthomas/participle => ../
replace github.com/alecthomas/participle/v2 => ../
4 changes: 2 additions & 2 deletions _examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/alecthomas/kong v0.2.8 h1:VSWWkD1TZij2967FcfVwgRwlp3khCA0liZIkUI9hTdU
github.com/alecthomas/kong v0.2.8/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
github.com/alecthomas/kong v0.2.11 h1:RKeJXXWfg9N47RYfMm0+igkxBCTF4bzbneAxaqid0c4=
github.com/alecthomas/kong v0.2.11/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
github.com/alecthomas/participle v0.4.1 h1:P2PJWzwrSpuCWXKnzqvw0b0phSfH1kJo4p2HvLynVsI=
github.com/alecthomas/participle v0.4.1/go.mod h1:T8u4bQOSMwrkTWOSyt8/jSFPEnRtd0FKFMjVfYBlqPs=
github.com/alecthomas/participle/v2 v0.4.1 h1:P2PJWzwrSpuCWXKnzqvw0b0phSfH1kJo4p2HvLynVsI=
github.com/alecthomas/participle/v2 v0.4.1/go.mod h1:T8u4bQOSMwrkTWOSyt8/jSFPEnRtd0FKFMjVfYBlqPs=
github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/alecthomas/repr v0.0.0-20200325044227-4184120f674c h1:MVVbswUlqicyj8P/JljoocA7AyCo62gzD0O7jfvrhtE=
github.com/alecthomas/repr v0.0.0-20200325044227-4184120f674c/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
Expand Down
6 changes: 3 additions & 3 deletions _examples/graphql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/alecthomas/kong"
"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"
)

type File struct {
Expand Down
2 changes: 1 addition & 1 deletion _examples/hcl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

type Bool bool
Expand Down
6 changes: 3 additions & 3 deletions _examples/ini/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"os"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"

"github.com/alecthomas/repr"
)
Expand Down
2 changes: 1 addition & 1 deletion _examples/json/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

type pathExpr struct {
Expand Down
4 changes: 2 additions & 2 deletions _examples/precedenceclimbing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
)

type opInfo struct {
Expand Down
4 changes: 2 additions & 2 deletions _examples/protobuf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/alecthomas/kong"
"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
)

type Proto struct {
Expand Down
6 changes: 3 additions & 3 deletions _examples/sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package main
import (
"github.com/alecthomas/kong"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"

"github.com/alecthomas/repr"
)
Expand Down
6 changes: 3 additions & 3 deletions _examples/stateful/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"
)

type Terminal struct {
Expand Down
4 changes: 2 additions & 2 deletions _examples/thrift/lexer_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions _examples/thrift/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (

"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/experimental/codegen"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/experimental/codegen"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion _examples/thrift/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
thriftparser "github.com/alecthomas/go-thrift/parser"
"github.com/stretchr/testify/require"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions _examples/toml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/alecthomas/kong"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"

"github.com/alecthomas/repr"
)
Expand Down
6 changes: 3 additions & 3 deletions _examples/µc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package main
import (
"github.com/alecthomas/repr"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/lexer/stateful"
"github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer"
"github.com/alecthomas/participle/v2/lexer/stateful"
)

// https://www.it.uu.se/katalog/aleji304/CompilersProject/uc.html
Expand Down
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package participle

import (
"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/v2/lexer"
)

// Capture can be implemented by fields in order to transform captured tokens into field values.
Expand Down
2 changes: 1 addition & 1 deletion cmd/railroad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/alecthomas/repr"

"github.com/alecthomas/participle/ebnf"
"github.com/alecthomas/participle/v2/ebnf"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package participle
import (
"reflect"

"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/v2/lexer"
)

type contextFieldSet struct {
Expand Down
2 changes: 1 addition & 1 deletion ebnf/ebnf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"fmt"
"io"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

var parser = participle.MustBuild(&EBNF{})
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package participle
import (
"fmt"

"github.com/alecthomas/participle/lexer"
"github.com/alecthomas/participle/v2/lexer"
)

// Error represents an error while parsing.
Expand Down
2 changes: 1 addition & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle/v2"
)

func TestErrorReporting(t *testing.T) {
Expand Down
Loading

0 comments on commit 6fd6e8c

Please sign in to comment.