-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoSql.pegjs
More file actions
64 lines (49 loc) · 1.65 KB
/
autoSql.pegjs
File metadata and controls
64 lines (49 loc) · 1.65 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
declaration
= _ type:declareType _ name:declareName _ comment:comment _ '(' _ fields:fieldList _ ')' _ { return { type, name, comment, fields } }
declareType =
'simple'/
'object'/
'table'
declareName
= name /
name indexType /
name 'auto' /
name indexType 'auto'
indexType =
'primary' /
'index' /
'unique'
comment =
nonQuotedString / _
fieldList =
f1:field _ fds:(_ w:field { return w; })* _ {
if(f1.name) {
fds.unshift(f1);
}
return fds;
}
commentStart = '#'
internalComment = _ commentStart nonQuotedString _
field =
type:fieldType _ name:fieldName _ ';' _ comment:comment { return { type, name, comment } } /
type:fieldType _ '[' _ size:fieldSize _ ']' _ name:name _ ';' _ comment:comment { return { type, size, name, comment } } /
type:fieldType _ '(' _ vals:fieldValues _ ')' _ name:name _ ';' _ comment:comment { return { type, vals, name, comment } } /
internalComment
fieldName = name
fieldValues =
f1:name fds:(',' _ w:name { return w; })* {
fds.unshift(f1);
return fds;
}
fieldType =
"int"/"uint"/"short"/"ushort"/"byte"/"ubyte"/"float"/"char"/"string"/"lstring"/"enum"/"double"/"bigint"/"set"/
t:declareType _ n:declareName { return t+' '+n }
fieldSize = number /
fieldName
name = t:([a-zA-Z_][a-zA-Z0-9_]*) { return text() }
quotedString = '"' t:(([^"]*)) '"' { return t.join('') }
nonQuotedString = t:(([^\n\r]*)) { return t.join('').replace(/^"/,'').replace(/"$/,'') }
number "integer"
= _ [0-9]+ { return parseInt(text(), 10); }
_ "whitespace"
= [ \t\n\r]*