forked from glayzzle/php-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
365 lines (347 loc) · 8.14 KB
/
index.d.ts
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*!
* Copyright (C) 2017 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
declare module "php-parser" {
/**
* Token items
*/
const enum TokenEnum {
T_HALT_COMPILER = 101,
T_USE = 102,
T_ENCAPSED_AND_WHITESPACE = 103,
T_OBJECT_OPERATOR = 104,
T_STRING = 105,
T_DOLLAR_OPEN_CURLY_BRACES = 106,
T_STRING_VARNAME = 107,
T_CURLY_OPEN = 108,
T_NUM_STRING = 109,
T_ISSET = 110,
T_EMPTY = 111,
T_INCLUDE = 112,
T_INCLUDE_ONCE = 113,
T_EVAL = 114,
T_REQUIRE = 115,
T_REQUIRE_ONCE = 116,
T_NAMESPACE = 117,
T_NS_SEPARATOR = 118,
T_AS = 119,
T_IF = 120,
T_ENDIF = 121,
T_WHILE = 122,
T_DO = 123,
T_FOR = 124,
T_SWITCH = 125,
T_BREAK = 126,
T_CONTINUE = 127,
T_RETURN = 128,
T_GLOBAL = 129,
T_STATIC = 130,
T_ECHO = 131,
T_INLINE_HTML = 132,
T_UNSET = 133,
T_FOREACH = 134,
T_DECLARE = 135,
T_TRY = 136,
T_THROW = 137,
T_GOTO = 138,
T_FINALLY = 139,
T_CATCH = 140,
T_ENDDECLARE = 141,
T_LIST = 142,
T_CLONE = 143,
T_PLUS_EQUAL = 144,
T_MINUS_EQUAL = 145,
T_MUL_EQUAL = 146,
T_DIV_EQUAL = 147,
T_CONCAT_EQUAL = 148,
T_MOD_EQUAL = 149,
T_AND_EQUAL = 150,
T_OR_EQUAL = 151,
T_XOR_EQUAL = 152,
T_SL_EQUAL = 153,
T_SR_EQUAL = 154,
T_INC = 155,
T_DEC = 156,
T_BOOLEAN_OR = 157,
T_BOOLEAN_AND = 158,
T_LOGICAL_OR = 159,
T_LOGICAL_AND = 160,
T_LOGICAL_XOR = 161,
T_SL = 162,
T_SR = 163,
T_IS_IDENTICAL = 164,
T_IS_NOT_IDENTICAL = 165,
T_IS_EQUAL = 166,
T_IS_NOT_EQUAL = 167,
T_IS_SMALLER_OR_EQUAL = 168,
T_IS_GREATER_OR_EQUAL = 169,
T_INSTANCEOF = 170,
T_INT_CAST = 171,
T_DOUBLE_CAST = 172,
T_STRING_CAST = 173,
T_ARRAY_CAST = 174,
T_OBJECT_CAST = 175,
T_BOOL_CAST = 176,
T_UNSET_CAST = 177,
T_EXIT = 178,
T_PRINT = 179,
T_YIELD = 180,
T_YIELD_FROM = 181,
T_FUNCTION = 182,
T_DOUBLE_ARROW = 183,
T_DOUBLE_COLON = 184,
T_ARRAY = 185,
T_CALLABLE = 186,
T_CLASS = 187,
T_ABSTRACT = 188,
T_TRAIT = 189,
T_FINAL = 190,
T_EXTENDS = 191,
T_INTERFACE = 192,
T_IMPLEMENTS = 193,
T_VAR = 194,
T_PUBLIC = 195,
T_PROTECTED = 196,
T_PRIVATE = 197,
T_CONST = 198,
T_NEW = 199,
T_INSTEADOF = 200,
T_ELSEIF = 201,
T_ELSE = 202,
T_ENDSWITCH = 203,
T_CASE = 204,
T_DEFAULT = 205,
T_ENDFOR = 206,
T_ENDFOREACH = 207,
T_ENDWHILE = 208,
T_CONSTANT_ENCAPSED_STRING = 209,
T_LNUMBER = 210,
T_DNUMBER = 211,
T_LINE = 212,
T_FILE = 213,
T_DIR = 214,
T_TRAIT_C = 215,
T_METHOD_C = 216,
T_FUNC_C = 217,
T_NS_C = 218,
T_START_HEREDOC = 219,
T_END_HEREDOC = 220,
T_CLASS_C = 221,
T_VARIABLE = 222,
T_OPEN_TAG = 223,
T_OPEN_TAG_WITH_ECHO = 224,
T_CLOSE_TAG = 225,
T_WHITESPACE = 226,
T_COMMENT = 227,
T_DOC_COMMENT = 228,
T_ELLIPSIS = 229,
T_COALESCE = 230,
T_POW = 231,
T_POW_EQUAL = 232,
T_SPACESHIP = 233,
T_COALESCE_EQUAL = 234
}
/**
* The tokens dictionnary
*/
interface TokenDefinition {
/** List of token names as texts */
values: String[],
/** Define tokens */
names: TokenEnum[]
}
/**
* The token structure
*/
interface Token extends Array<any> {
// token name
0: String;
// the token value
1: TokenEnum;
// the current line
2: Number
}
/**
* Each Position object consists of a line number (1-indexed) and a column number (0-indexed):
*/
interface Position {
line: Number;
column: Number;
offset: Number;
}
/**
* Defines the location of the node (with it's source contents as string)
*/
interface Location {
source: string;
start: Position;
end: Position;
}
/**
*
*/
interface Node {
kind: String;
loc: Location;
}
/**
* Error node
*/
interface ParserError extends Node {
message: String;
token: Token;
line: Number;
expected: any;
}
/**
* A block statement, i.e., a sequence of statements surrounded by braces.
*/
interface Block extends Node {
children: Node[];
}
/**
* The main root node
*/
interface Program extends Block {
errors: ParserError[];
}
interface Parser {
lexer: Lexer;
ast: AST;
token: TokenEnum;
prev: TokenEnum;
debug: Boolean;
extractDoc: Boolean;
suppressErrors: Boolean;
getTokenName(token:TokenEnum): String;
parse(code: String, filename: String): Program;
raiseError(message: String, msgExpect: String, expect: any, token: TokenEnum): ParserError;
error(expect: String): ParserError;
node(kind:String): Node;
expectEndOfStatement(): Boolean;
showlog(): Parser;
expect(token:TokenEnum): Boolean;
expect(tokens:TokenEnum[]): Boolean;
text(): String;
next(): Parser;
ignoreComments(): Parser;
nextWithComments(): Parser;
is(type: String): Boolean;
// @todo other parsing functions ...
}
interface KeywordsDictionnary {
[index: string]: TokenEnum
}
interface yylloc {
first_offset: Number;
first_line: Number;
first_column: Number;
last_line: Number;
last_column: Number;
}
interface LexerState {
yytext: String;
offset: Number;
yylineno: Number;
yyprevcol: Number;
yylloc: yylloc;
}
interface Lexer {
debug: Boolean;
all_tokens: Boolean;
comment_tokens: Boolean;
mode_eval: Boolean;
asp_tags: Boolean;
short_tags: Boolean;
keywords: KeywordsDictionnary;
castKeywords: KeywordsDictionnary;
setInput(input:String): Lexer;
input(size:Number): String;
unput(size:Number): Lexer;
tryMatch(match:String): Boolean;
tryMatchCaseless(match:String): Boolean;
ahead(size:Number): String;
consume(size:Number): Lexer;
getState(): LexerState;
setState(state:LexerState): Lexer;
appendToken(value:TokenEnum, ahead:Number): Lexer;
lex(): TokenEnum;
begin(state:String): Lexer;
popState(): String;
next(): TokenEnum;
// @todo other lexer functions ...
}
interface AST {
/**
*
*/
withPositions: Boolean;
/**
* Option, if true extracts original source code attached to the node (by default false)
*/
withSource: Boolean;
/**
* Constructor
*/
constructor(withPositions:Boolean, withSource:Boolean): AST;
constructor(withPositions:Boolean): AST;
constructor(): AST;
/**
* Create a position node from specified parser
* including it's lexer current state
*/
position(parser:Parser): Position;
/**
* Prepares an AST node
*/
prepare(kind:String, parser:Parser): Function;
}
/**
* List of options / extensions
*/
interface Options {
ast?: {
withPositions?: Boolean;
withSource?: Boolean;
};
lexer?: {
debug?: Boolean;
all_tokens?: Boolean;
comment_tokens?: Boolean;
mode_eval?: Boolean;
asp_tags?: Boolean;
short_tags?: Boolean;
};
parser?: {
debug?: Boolean;
extractDoc?: Boolean;
suppressErrors?: Boolean;
};
}
/**
* Initialise a new parser instance with the specified options
*/
export default class Engine {
// ----- STATIC HELPERS
static create(options?: Options) : Engine;
static parseEval(buffer: String, options: Options) : Program;
static parseEval(buffer: String) : Program;
static parseCode(buffer: String, filename: String, options: Options) : Program;
static parseCode(buffer: String, options: Options) : Program;
static parseCode(buffer: String) : Program;
static tokenGetAll(buffer: String, options: Options) : Token[];
static tokenGetAll(buffer: String) : Token[];
// ----- INSTANCE FUNCTIONS
ast: AST;
lexer: Lexer;
parser: Parser;
tokens: TokenDefinition;
constructor(options?: Options);
parseEval(buffer: String) : Program;
parseCode(buffer: String, filename: String) : Program;
parseCode(buffer: String) : Program;
tokenGetAll(buffer: String) : Token[];
}
}