forked from alecthomas/participle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
63 lines (63 loc) · 1.9 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Package participle constructs parsers from definitions in struct tags and parses directly into
// those structs. The approach is philosophically similar to how other marshallers work in Go,
// "unmarshalling" an instance of a grammar into a struct.
//
// The supported annotation syntax is:
//
// - `@<expr>` Capture expression into the field.
// - `@@` Recursively capture using the fields own type.
// - `<identifier>` Match named lexer token.
// - `{ ... }` Match 0 or more times.
// - `( ... )` Group.
// - `[ ... ]` Optional.
// - `"..."[:<identifier>]` Match the literal, optionally specifying the exact lexer token
// type to match.
// - `<expr> <expr> ...` Match expressions.
// - `<expr> | <expr>` Match one of the alternatives.
//
// Here's an example of an EBNF grammar.
//
// type Group struct {
// Expression *Expression `"(" @@ ")"`
// }
//
// type Option struct {
// Expression *Expression `"[" @@ "]"`
// }
//
// type Repetition struct {
// Expression *Expression `"{" @@ "}"`
// }
//
// type Literal struct {
// Start string `@String` // lexer.Lexer token "String"
// End string `[ "…" @String ]`
// }
//
// type Term struct {
// Name string `@Ident |`
// Literal *Literal `@@ |`
// Group *Group `@@ |`
// Option *Option `@@ |`
// Repetition *Repetition `@@`
// }
//
// type Sequence struct {
// Terms []*Term `@@ { @@ }`
// }
//
// type Expression struct {
// Alternatives []*Sequence `@@ { "|" @@ }`
// }
//
// type Expressions []*Expression
//
// type Production struct {
// Name string `@Ident "="`
// Expressions Expressions `@@ { @@ } "."`
// }
//
// type EBNF struct {
// Productions []*Production `{ @@ }`
// }
package participle