-
Notifications
You must be signed in to change notification settings - Fork 41
/
main.ne
72 lines (65 loc) · 1.73 KB
/
main.ne
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
@preprocessor typescript
@{%
import {lexerAny, LOCATION} from '../lexer';
%}
@lexer lexerAny
@include "base.ne"
@include "expr.ne"
@include "select.ne"
@include "create-table.ne"
@include "create-index.ne"
@include "create-extension.ne"
@include "simple-statements.ne"
@include "insert.ne"
@include "update.ne"
@include "alter-table.ne"
@include "delete.ne"
@include "sequence.ne"
@include "drop.ne"
@include "with.ne"
@include "create-type.ne"
@include "union.ne"
@include "prepare.ne"
@include "create-view.ne"
# list of statements, separated by ";"
main -> statement_separator:* statement (statement_separator:+ statement):* statement_separator:* {% ([_, head, _tail]) => {
const tail = _tail; // && _tail[0];
const first = unwrap(head);
first[LOCATION] = { start: 0 };
if (!tail || !tail.length) {
return first;
}
const ret = [first];
let prev = first;
for (const t of tail) {
const firstSep = unwrap(t[0][0]);
prev[LOCATION].end = firstSep.offset;
const lastSep = unwrap(last(t[0]));
const statement = unwrap(t[1]);
statement[LOCATION] = {
start: lastSep.offset,
};
prev = statement;
ret.push(statement);
}
return ret;
} %}
statement_separator -> %semicolon
statement -> statement_noprep | prepare
statement_noprep
-> select_statement
| createtable_statement
| createextension_statement
| createindex_statement
| simplestatements_all
| insert_statement
| update_statement
| altertable_statement
| delete_statement
| create_sequence_statement
| alter_sequence_statement
| drop_statement
| createtype_statement
| with_statement
| union_statement
| create_view_statements