This repository provides examples I referred to in "Parsing & Go" talk
Parsing phpdoc type expressions using several approaches:
- participle example uses alecthomas/participle with default lexer
- yacc example uses goyacc with text/scanner for lexing
- yacc_ragel example uses goyacc with a lexer generated with Ragel
- handwritten example shows a manually created parser from NoVerify static analyzer
These 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 defines the common AST constructed by every parser.
Package phpdoctest contains test cases that are used to test every parser.
Every parser package is a main
that can parse a command-line argument:
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:
# build all parsers (requires goyacc and ragel installed)
make all
# run all tests
make test
# run all benchmarks
make bench