forked from protobufjs/protobuf.js
/
Lang.js
64 lines (45 loc) · 1.61 KB
/
Lang.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
/**
* Language expressions.
* @type {!Object.<string,!RegExp>}
* @expose
*/
ProtoBuf.Lang = {
// Characters always ending a statement
DELIM: /[\s\{\}=;:\[\],'"\(\)<>]/g,
// Field rules
RULE: /^(?:required|optional|repeated|map)$/,
// Field types
TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,
// Names
NAME: /^[a-zA-Z_][a-zA-Z_0-9]*$/,
// Type definitions
TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/,
// Type references
TYPEREF: /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
// Fully qualified type references
FQTYPEREF: /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,
// All numbers
NUMBER: /^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,
// Decimal numbers
NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/,
// Hexadecimal numbers
NUMBER_HEX: /^0[xX][0-9a-fA-F]+$/,
// Octal numbers
NUMBER_OCT: /^0[0-7]+$/,
// Floating point numbers
NUMBER_FLT: /^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,
// Booleans
BOOL: /^(?:true|false)$/i,
// Id numbers
ID: /^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,
// Negative id numbers (enum values)
NEGID: /^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,
// Whitespaces
WHITESPACE: /\s/,
// All strings
STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,
// Double quoted strings
STRING_DQ: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,
// Single quoted strings
STRING_SQ: /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g
};