Skip to content

Commit c43a3e4

Browse files
committed
Added comma parsing to make more SQL like
1 parent 4cf0eab commit c43a3e4

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

lib/lexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ rule read =
5151
| ">=" { GEQ }
5252
| "<" { LT }
5353
| ">" { GT }
54+
| "," { COMMA }
5455
| white { read lexbuf}
5556
| int { INT (int_of_string(Lexing.lexeme lexbuf))}
5657
| float { FLOAT (float_of_string(Lexing.lexeme lexbuf))}

lib/parser.mly

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/* Operators */
1313
%token LPAREN "("
1414
%token RPAREN ")"
15+
%token COMMA
1516
%token SUM
1617
%token MULT
1718
%token DIV
@@ -68,7 +69,7 @@ constant:
6869

6970
constant_list:
7071
| constant { [$1] }
71-
| constant constant_list {$1 :: $2}
72+
| constant COMMA constant_list {$1 :: $3}
7273

7374

7475
statement:
@@ -80,7 +81,7 @@ statement:
8081

8182
field_list:
8283
| field { [$1] }
83-
| field field_list { $1 :: $2 }
84+
| field COMMA field_list { $1 :: $3 }
8485
;
8586

8687

test/interpreter_test.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ let test_insert_statement_recognized () =
146146
let res =
147147
test_helper
148148
(Interpreter.interpret
149-
"INSERT INTO Mbta (Id stop_name rail_line) VALUES (1 'f' 'g') ")
149+
"INSERT INTO Mbta (Id, stop_name, rail_line) VALUES (1, 'f', 'g') ")
150150
in
151151
Alcotest.(check bool)
152152
"insert accepted for execution" true
@@ -155,7 +155,7 @@ let test_insert_statement_recognized () =
155155

156156
let test_select_statement_recognized () =
157157
let res =
158-
test_helper (Interpreter.interpret "SELECT stop_name rail_line FROM Mbta")
158+
test_helper (Interpreter.interpret "SELECT stop_name, rail_line FROM Mbta")
159159
in
160160
Alcotest.(check bool)
161161
"select accepted for execution" true

0 commit comments

Comments
 (0)