Skip to content

Commit

Permalink
Merge pull request cornucopia-rs#82 from Virgiel/new_parser
Browse files Browse the repository at this point in the history
New parser
  • Loading branch information
LouisGariepy authored Jun 9, 2022
2 parents d439aa5 + 7f6ae31 commit 2883d95
Show file tree
Hide file tree
Showing 17 changed files with 1,922 additions and 593 deletions.
246 changes: 85 additions & 161 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ time = { version = "0.3.9", features = ["parsing"] }

thiserror = "1.0.31"
clap = { version = "3.1.18", features = ["derive"] }
pest = "2.1.3"
pest_derive = "2.1.0"
heck = "0.4.0"
indexmap = "1.8.2"

prettyplease = "0.1.11"
syn = { version = "1.0.95", features = ["parsing"] }
chumsky = "0.8.0"
5 changes: 5 additions & 0 deletions codegen_test/migrations/1648515058_syntax.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Write your migration SQL here
CREATE TABLE Syntax (
"trick:y" TEXT,
price FLOAT
);
6 changes: 3 additions & 3 deletions codegen_test/queries/stress.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
SELECT * FROM Everything;

--! select_everything_null: (bool_?, boolean_?, char_?, smallint_?, int2_?, smallserial_?, serial2_?, int_?, int4_?, serial_?, serial4_?, bingint_?, int8_?, bigserial_?, serial8_?, float4_?, real_?, float8_?, double_precision_?, text_?, varchar_?, bytea_?, timestamp_?, timestamp_without_time_zone_?, timestamptz_?, timestamp_with_time_zone_?, date_?, time_?, json_?, jsonb_?, uuid_?, inet_?, macaddr_?)
SELECT * FROM Everything
SELECT * FROM Everything;

--! insert_everything
INSERT INTO Everything (bool_, boolean_, char_, smallint_, int2_, smallserial_, serial2_, int_, int4_, serial_, serial4_, bingint_, int8_, bigserial_, serial8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_)
VALUES (:bool_, :boolean_, :char_, :smallint_, :int2_, :smallserial_, :serial2_, :int_, :int4_, :serial_, :serial4_, :bingint_, :int8_, :bigserial_, :serial8_, :float4_, :real_, :float8_, :double_precision_, :text_, :varchar_, :bytea_, :timestamp_, :timestamp_without_time_zone_, :timestamptz_, :timestamp_with_time_zone_, :date_, :time_, :json_, :jsonb_, :uuid_, :inet_, :macaddr_);

--! select_everything_array
SELECT * FROM EverythingArray
SELECT * FROM EverythingArray;

--! select_everything_array_null: (bool_?, boolean_?, char_?, smallint_?, int2_?, int_?, int4_?, bingint_?, int8_?, float4_?, real_?, float8_?, double_precision_?, text_?, varchar_?, bytea_?, timestamp_?, timestamp_without_time_zone_?, timestamptz_?, timestamp_with_time_zone_?, date_?, time_?, json_?, jsonb_?, uuid_?, inet_?, macaddr_?)
SELECT * FROM EverythingArray
SELECT * FROM EverythingArray;

--! insert_everything_array
INSERT INTO EverythingArray (bool_, boolean_, char_, smallint_, int2_, int_, int4_, bingint_, int8_, float4_, real_, float8_, double_precision_, text_, varchar_, bytea_, timestamp_, timestamp_without_time_zone_, timestamptz_, timestamp_with_time_zone_, date_, time_, json_, jsonb_, uuid_, inet_, macaddr_)
Expand Down
54 changes: 54 additions & 0 deletions codegen_test/queries/syntax.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

--:row CompactRow()
--: row SpaceRow ()
--:param CompactField(a?,b?,c?)
--:param SpaceField ( a? , b? , c? )

--simple comment

--! select_compact
SELECT * FROM clone;
--! select_spaced
SELECT * FROM clone ;

-- spaced comment

--!implicit_compact(name?,price?):(id?)
INSERT INTO item (name, price, show) VALUES (:name, :price, false) RETURNING id;
--! implicit_spaced ( name? , price? ) : ( id? )
INSERT INTO item (name, price, show) VALUES (:name, :price, false) RETURNING id;

-- Multi line
-- Comment

--!named_compact Params:Row
INSERT INTO item (name, price, show) VALUES (:name, :price, false) RETURNING id;
--! named_spaced Params : Row
INSERT INTO item (name, price, show) VALUES (:name, :price, false) RETURNING id;

--! tricky_sql
INSERT INTO syntax ("trick:y", price) VALUES ('this is not a bind_param\', :price);
--! tricky_sql1
INSERT INTO syntax ("trick:y", price) VALUES ('this is not a :bind_param', :price);
--! tricky_sql2
INSERT INTO syntax ("trick:y", price) VALUES ('this is not a '':bind_param''', :price);
--! tricky_sql3
INSERT INTO syntax ("trick:y", price) VALUES ($$this is not a :bind_param$$, :price);
--! tricky_sql4
INSERT INTO syntax ("trick:y", price) VALUES ($tag$this is not a :bind_param$tag$, :price);
--! tricky_sql6
INSERT INTO syntax ("trick:y", price) VALUES (e'this is not a '':bind_param''', :price);
--! tricky_sql7
INSERT INTO syntax ("trick:y", price) VALUES (E'this is not a \':bind_param\'', :price);
--! tricky_sql8
INSERT INTO syntax ("trick:y", price) VALUES (e'this is ''not'' a \':bind_param\'', :price);
--! tricky_sql9
INSERT INTO syntax ("trick:y", price) VALUES (E'this is \'not\' a \':bind_param\'', :price);

--! syntax
SELECT * FROM syntax;


-- Multi

-- Comment
Loading

0 comments on commit 2883d95

Please sign in to comment.