-
Notifications
You must be signed in to change notification settings - Fork 2
/
tlparser.go
142 lines (109 loc) · 2.97 KB
/
tlparser.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2022 V Kontakte LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package tlast
const ContactAuthorsString = "please check/create issue with example https://github.com/VKCOM/tl/issues" // TODO move to better place
type Name struct {
Namespace string
Name string
}
type Modifier struct {
Name string
PR PositionRange
}
type Constructor struct {
Name Name
ID *uint32 // TODO - uint32 + bool IsExplicit
NamePR PositionRange
IDPR PositionRange
}
type TemplateArgument struct {
FieldName string
IsNat bool
PR PositionRange // TODO - split into type and name
}
type TypeDeclaration struct {
Name Name
Arguments []string
PR PositionRange
NamePR PositionRange
ArgumentsPR []PositionRange
}
type Arithmetic struct {
Nums []uint32
Res uint32
}
type ArithmeticOrType struct {
IsArith bool
Arith Arithmetic
T TypeRef // PR of T can also be used for Arith
}
type ScaleFactor struct {
IsArith bool
Arith Arithmetic
Scale string
PR PositionRange
}
type RepeatWithScale struct {
ExplicitScale bool
Scale ScaleFactor
Rep []Field
PR PositionRange
}
type FieldMask struct {
MaskName string
BitNumber uint32
PRName PositionRange
PRBits PositionRange
}
type TypeRef struct { // due to complexity, parsing of TypeRef defined in separate tlparser_typeref.go file
Type Name
Args []ArithmeticOrType
Bare bool
PR PositionRange
PRArgs PositionRange
}
type Field struct {
FieldName string
Mask *FieldMask
Excl bool
IsRepeated bool
ScaleRepeat RepeatWithScale
FieldType TypeRef
PR PositionRange
PRName PositionRange
CommentBefore string // comment before field
CommentRight string // comment to the right of field
}
type Combinator struct {
Builtin bool
IsFunction bool
Modifiers []Modifier // TODO - rename to annotations
Construct Constructor
TemplateArguments []TemplateArgument
Fields []Field
TypeDecl TypeDeclaration
FuncDecl TypeRef
OriginalDescriptor *Combinator // hack - if some replacements were made, original descriptor is saved here
OriginalOrderIndex int // declaration order index (needed in TLO generation)
TemplateArgumentsPR PositionRange // especially useful when 0 arguments
PR PositionRange
CommentBefore string // comment before combinator
CommentRight string // comment to the right of combinator
}
type TL []*Combinator
// only trivial methods below, parsing is in tlparser_code.go and tlparser_typeref.go files
func (n Name) IsEmpty() bool {
return n.Namespace == "" && n.Name == ""
}
func (t TypeRef) IsEmpty() bool {
return t.Type.IsEmpty()
}
func (a Arithmetic) IsEmpty() bool {
return len(a.Nums) == 0
}
func (sf ScaleFactor) IsEmpty() bool {
return sf.Arith.IsEmpty() && sf.Scale == ""
}