-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxuji.shen
139 lines (103 loc) · 3.14 KB
/
xuji.shen
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
\\ These are just curlies for now until the lexer can be replaced
(defcc <lparen> { := skip;)
(defcc <rparen> } := skip;)
(defcc <conditional-operator>
= := =;
< := <;
> := >;
<= := <=;
>= := >=;
<> := <>;)
(defcc <binary-operator>
+ := +;
- := -;
* := *;
/ := /;
<conditional-operator> := <conditional-operator>;)
(defcc <expression>
<lparen> <expression> <rparen> as Name := [as <expression> Name];
Name1 <binary-operator> Name2 := [<binary-operator> Name1 Name2];
Name := Name;)
(defcc <conditional>
<lparen> <conditional1> <rparen> and <lparen> <conditional2> <rparen> := [and <conditional1> <conditional2>];
<lparen> <conditional1> <rparen> or <lparen> <conditional2> <rparen> := [or <conditional1> <conditional2>];
Name1 <conditional-operator> Name2 := [<conditional-operator> Name1 Name2];)
(defcc <conditional1> <conditional> := <conditional>;)
(defcc <conditional2> <conditional> := <conditional>;)
(defcc <selections>
<expression> , <selections> := [<expression> | <selections>];
<expression> := [<expression>];)
(defcc <joins>
join Name on <conditional> <joins> := [(@p Name <conditional>) | <joins>];
join Name on <conditional> := [(@p Name <conditional>)];)
(defcc <sources>
Name <joins> := [Name | <joins>];
Name := [Name];)
(defcc <target>
Name := Name;)
(defcc <assignments>
Column = <expression> , <assignments> := [(@p Column <expression>) | <assignments>];
Column = <expression> := [(@p Column <expression>)];)
(defcc <columns>
<rparen> := skip;
Name , <columns> := [Name | <columns>];
Name := [Name];)
(defcc <values>
<rparen> := skip;
<expression> , <values> := [<expression> | <values>];
<expression> := [<expression>])
(defcc <column-declarations>
<rparen> := skip;
Name Type , <column-declarations> := [(@p Name Type) | <column-declarations>];
Name Type := [(@p Name Type)];)
(defcc <select>
select <selections>
from <sources>
where <conditional>
:= [select
[selections <selections>]
[sources <sources>]
[conditional <conditional>]];
select <selections>
from <sources>
:= [select
[selections <selections>]
[sources <sources>]];
select <selections>
:= [select [selections <selections>]];)
(defcc <update>
update <target>
set <assignments>
where <conditional>
:= [update
[target <target>]
[assignments <assignments>]
[conditional <conditional>]];)
(defcc <insert>
insert into <target> <lparen> <columns> <rparen>
values <lparen> <values> <rparen>
:= [insert
[target <target>]
[columns <columns>]
[values <values>]];)
(defcc <delete>
delete from <target>
where <conditional>
:= [delete
[target <target>]
[conditional <conditional>]];)
(defcc <create-table>
create table Name <lparen> <column-declarations> <rparen>
:= [create
[name Name]
[columns <column-declarations>]];)
(defcc <sql>
<select> := <select>;
<update> := <update>;
<insert> := <insert>;
<delete> := <delete>;
<create-table> := <create-table>;)
(define parse-sql
Ast -> (compile (function <sql>) Ast))
(define parse-sql-from-string
String -> (parse-sql (read-from-string String)))