This repository has been archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
144 lines (135 loc) · 5.17 KB
/
index.js
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
// TODO: Make it similar to babel-types
import luaparse from 'luaparse';
export const types = [
'LabelStatement',
'BreakStatement',
'GotoStatement',
'ReturnStatement',
'IfStatement',
'IfClause',
'ElseifClause',
'ElseClause',
'WhileStatement',
'DoStatement',
'RepeatStatement',
'LocalStatement',
'AssignmentStatement',
'CallStatement',
'FunctionDeclaration',
'ForNumericStatement',
'ForGenericStatement',
'Chunk',
'Identifier',
'StringLiteral',
'NumericLiteral',
'BooleanLiteral',
'NilLiteral',
'VarargLiteral',
'TableKey',
'TableKeyString',
'TableValue',
'TableConstructorExpression',
'LogicalExpression',
'BinaryExpression',
'UnaryExpression',
'MemberExpression',
'IndexExpression',
'CallExpression',
'TableCallExpression',
'StringCallExpression',
'Comment',
'LuaRaw',
];
export const isLabelStatement = node => node.type === 'LabelStatement';
export const isBreakStatement = node => node.type === 'BreakStatement';
export const isGotoStatement = node => node.type === 'GotoStatement';
export const isReturnStatement = node => node.type === 'ReturnStatement';
export const isIfStatement = node => node.type === 'IfStatement';
export const isIfClause = node => node.type === 'IfClause';
export const isElseifClause = node => node.type === 'ElseifClause';
export const isElseClause = node => node.type === 'ElseClause';
export const isWhileStatement = node => node.type === 'WhileStatement';
export const isDoStatement = node => node.type === 'DoStatement';
export const isRepeatStatement = node => node.type === 'RepeatStatement';
export const isLocalStatement = node => node.type === 'LocalStatement';
export const isAssignmentStatement = node => node.type === 'AssignmentStatement';
export const isCallStatement = node => node.type === 'CallStatement';
export const isFunctionDeclaration = node => node.type === 'FunctionDeclaration';
export const isForNumericStatement = node => node.type === 'ForNumericStatement';
export const isForGenericStatement = node => node.type === 'ForGenericStatement';
export const isChunk = node => node.type === 'Chunk';
export const isIdentifier = node => node.type === 'Identifier';
export const isStringLiteral = node => node.type === 'StringLiteral';
export const isNumericLiteral = node => node.type === 'NumericLiteral';
export const isBooleanLiteral = node => node.type === 'BooleanLiteral';
export const isNilLiteral = node => node.type === 'NilLiteral';
export const isVarargLiteral = node => node.type === 'VarargLiteral';
export const isTableKey = node => node.type === 'TableKey';
export const isTableKeyString = node => node.type === 'TableKeyString';
export const isTableValue = node => node.type === 'TableValue';
export const isTableConstructorExpression = node => node.type === 'TableConstructorExpression';
export const isLogicalExpression = node => node.type === 'LogicalExpression';
export const isBinaryExpression = node => node.type === 'BinaryExpression';
export const isUnaryExpression = node => node.type === 'UnaryExpression';
export const isMemberExpression = node => node.type === 'MemberExpression';
export const isIndexExpression = node => node.type === 'IndexExpression';
export const isCallExpression = node => node.type === 'CallExpression';
export const isTableCallExpression = node => node.type === 'TableCallExpression';
export const isStringCallExpression = node => node.type === 'StringCallExpression';
export const isComment = node => node.type === 'Comment';
export const isLuaRaw = node => node.type === 'LuaRaw';
export const isBinary = node => isLogicalExpression(node) || isBinaryExpression(node);
export const isConditional = node => isIfClause(node) || isElseifClause(node);
export const tokenTypes = {
EOF: luaparse.tokenTypes.EOF,
StringLiteral: luaparse.tokenTypes.StringLiteral,
Keyword: luaparse.tokenTypes.Keyword,
Identifier: luaparse.tokenTypes.Identifier,
NumericLiteral: luaparse.tokenTypes.NumericLiteral,
Punctuator: luaparse.tokenTypes.Punctuator,
BooleanLiteral: luaparse.tokenTypes.BooleanLiteral,
NilLiteral: luaparse.tokenTypes.NilLiteral,
VarargLiteral: luaparse.tokenTypes.VarargLiteral,
};
export const {
labelStatement,
breakStatement,
gotoStatement,
returnStatement,
ifStatement,
ifClause,
elseifClause,
elseClause,
whileStatement,
doStatement,
repeatStatement,
localStatement,
assignmentStatement,
callStatement,
functionStatement,
forNumericStatement,
forGenericStatement,
chunk,
identifier,
literal,
tableKey,
tableKeyString,
tableValue,
tableConstructorExpression,
binaryExpression,
unaryExpression,
memberExpression,
indexExpression,
callExpression,
tableCallExpression,
stringCallExpression,
comment,
} = luaparse.ast;
export function luaRaw(code) {
return { type: 'LuaRaw', code };
}
export const stringLiteral = (value, raw) => literal(tokenTypes.StringLiteral, value, raw);
export const numericLiteral = (value, raw) => literal(tokenTypes.NumericLiteral, value, raw);
export const booleanLiteral = (value, raw) => literal(tokenTypes.BooleanLiteral, value, raw);
export const nilLiteral = () => literal(tokenTypes.NilLiteral, null);
export const varargLiteral = () => literal(tokenTypes.VarargLiteral, '...');