forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-basic.pegjs
More file actions
70 lines (68 loc) · 1.71 KB
/
string-basic.pegjs
File metadata and controls
70 lines (68 loc) · 1.71 KB
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
// Unified literal_string covering all SQL dialects
// Includes: hex, bit, full_hex, natural (N), unicode (u&), regex (R), newline continuation
literal_string
= b:('_binary'i / '_latin1'i)? __ r:'X'i ca:("'" [0-9A-Fa-f]* "'") {
return {
type: 'hex_string',
prefix: b,
value: ca[1].join('')
};
}
/ b:('_binary'i / '_latin1'i)? __ r:'b'i ca:("'" [0-9A-Fa-f]* "'") {
return {
type: 'bit_string',
prefix: b,
value: ca[1].join('')
};
}
/ b:('_binary'i / '_latin1'i)? __ r:'0x'i ca:([0-9A-Fa-f]*) {
return {
type: 'full_hex_string',
prefix: b,
value: ca.join('')
};
}
/ r:'N'i ca:("'" single_char* "'") {
return {
type: 'natural_string',
value: ca[1].join('')
};
}
/ r:'u&'i ca:("'" single_char* "'") {
return {
type: 'unicode_string',
value: ca[1].join('')
};
}
/ r:'R'i __ ca:("'" single_char* "'") {
return {
type: 'regex_string',
value: ca[1].join('')
};
}
/ r:'R'i __ ca:("\"" single_quote_char* "\"") {
return {
type: 'regex_string',
value: ca[1].join('')
};
}
/ ca:("'" single_char* "'") [\n]+ __ fs:("'" single_char* "'") {
return {
type: 'single_quote_string',
value: `${ca[1].join('')}${fs[1].join('')}`
};
}
/ ca:("'" single_char* "'") {
return {
type: 'single_quote_string',
value: ca[1].join('')
};
}
/ literal_double_quoted_string
literal_double_quoted_string
= ca:("\"" single_quote_char* "\"") __ !(DOT / LPAREN) {
return {
type: 'double_quote_string',
value: ca[1].join('')
};
}