https://github.com/quasilyte/parsing-and-go
https://github.com/quasilyte/parsing-and-go
go golang lexer lexing parsing phpdoc ragel yacc
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/quasilyte/parsing-and-go
- Owner: quasilyte
- License: mit
- Created: 2021-08-02T20:31:40.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-05T09:03:30.000Z (about 4 years ago)
- Last Synced: 2025-03-17T06:22:14.404Z (7 months ago)
- Topics: go, golang, lexer, lexing, parsing, phpdoc, ragel, yacc
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 19
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Parsing & Go
> This repository provides examples I referred to in "Parsing & Go" talk
Parsing phpdoc type expressions using several approaches:
* [participle](/participle) example uses [alecthomas/participle](https://github.com/alecthomas/participle) with default lexer
* [yacc](/yacc) example uses [goyacc](https://pkg.go.dev/golang.org/x/tools/cmd/goyacc) with [text/scanner](https://pkg.go.dev/text/scanner) for lexing
* [yacc_ragel](/yacc_ragel) example uses [goyacc](https://pkg.go.dev/golang.org/x/tools/cmd/goyacc) with a lexer generated with [Ragel](https://github.com/adrian-thurston/ragel)
* [handwritten](/handwritten) example shows a manually created parser from [NoVerify](https://github.com/VKCOM/noverify) static analyzerThese example parsers understand these types (and their combinations):
| Type | Example |
|---|---|
| primitive type | `int`, `float`, `null`, ... |
| type name | `Foo`, `Foo\Bar` |
| nullable type | `?T` |
| optional key type | `T?` |
| array type | `T[]` |
| union type | `X\|Y` |
| intersection type | `X&Y` |Package [phpdoc](/phpdoc) defines the common AST constructed by every parser.
Package [phpdoctest](/phpdoctest) contains test cases that are used to test every parser.
Every parser package is a `main` that can parse a command-line argument:
```bash
go run ./participle 'int|Foo\Bar'go run ./yacc 'int|Foo\Bar'
go run ./yacc_ragel 'int|Foo\Bar'
go run ./handwritten 'int|Foo\Bar'
```Some useful `make` commands:
```bash
# build all parsers (requires goyacc and ragel installed)
make all# run all tests
make test# run all benchmarks
make bench
```