ref: ccaaf5e5e5e2660778cbb9390f8cb81a6b245a41 fastpeg/internal/ast/ast.go -rw-r--r-- 1.6 KiB View raw
                                                                                
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package ast

import (
	"git.sr.ht/~mna/fastpeg/internal/bootstrap/token"
)

type Expression interface{}

// Grammar represents a parsed fastpeg grammar.
type Grammar struct {
	Definitions []*Definition
}

type Definition struct {
	// Ident is the required identifier in a definition, i.e.:
	// identifier <- expression
	Ident *Identifier

	// Arrow indicates the location and type of arrow in the
	// definition.
	Arrow *Punctuation

	// Expr is the expression associated with this definition's
	// identifier.
	Expr Expression

	// EOS is the end-of-statement if present for this
	// definition, nil otherwise.
	EOS *Punctuation
}

type Choice struct {
	// Exprs is the list of options, one expression for each
	// choice.
	Exprs []Expression

	// Seps is the list of choice separators between each option.
	Seps []*Punctuation
}

type Sequence struct {
	// Exprs is the list of expressions in this sequence.
	Exprs []Expression
}

type Coderef struct {
	Pos   token.Pos
	Type  token.Token
	Ident string
}

type Label struct {
	Ident *Identifier
	Colon *Punctuation
	Expr  Expression
}

type Prefix struct {
	Prefix *Punctuation
	Expr   Expression
}

type Suffix struct {
	Suffix *Punctuation
	Expr   Expression
}

type Ruleref struct {
	Ident *Identifier
}

type Literal struct {
}

type CharClass struct {
}

type Any struct {
	Dot *Punctuation
}

type Identifier struct {
	Pos   token.Pos
	Value string
}

type Punctuation struct {
	// Pos is the FileSet-dependent position of the start of
	// this punctuation.
	Pos token.Pos

	// Value is the representation of this punctuation.
	Value string
}