Skip to content

Commit

Permalink
Parse constraints not separated by comma
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Jan 8, 2024
1 parent d8b32c0 commit 51157d5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
15 changes: 10 additions & 5 deletions Language/SQL/SimpleSQL/Parse.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,12 +1509,17 @@ TODO: change style
> CreateSchema <$> names

> createTable :: Parser Statement
> createTable = keyword_ "table" >>
> createTable = do
> let
> parseColumnDef = TableColumnDef <$> columnDef
> parseConstraintDef = uncurry TableConstraintDef <$> tableConstraintDef
> constraints = sepBy parseConstraintDef (optional comma)
> entries = ((:) <$> parseColumnDef <*> ((comma >> entries) <|> pure [])) <|> constraints
>
> keyword_ "table" >>
> CreateTable
> <$> names
> -- todo: is this order mandatory or is it a perm?
> <*> parens (commaSep1 (uncurry TableConstraintDef <$> tableConstraintDef
> <|> TableColumnDef <$> columnDef))
> <$> names
> <*> parens entries

> createIndex :: Parser Statement
> createIndex =
Expand Down
3 changes: 2 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
with import <nixpkgs> {};
with import <nixpkgs> { };
stdenv.mkDerivation rec {
name = "env";
env = buildEnv { name = name; paths = buildInputs; };
buildInputs = [
ghc
cabal-install
glibcLocales
gnumake
];
shellHook = "export LANG=en_GB.UTF-8";
}
Expand Down
22 changes: 22 additions & 0 deletions tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,28 @@ defintely skip
> DefaultReferentialAction DefaultReferentialAction
> ])

> ,(TestStatement ansi2011
> "create table t (a int, b int,\n\
> \ foreign key (a) references u(c)\n\
> \ foreign key (b) references v(d));"
> $ CreateTable [Name Nothing "t"]
> [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing []
> ,TableColumnDef $ ColumnDef (Name Nothing "b") (TypeName [Name Nothing "int"]) Nothing []
> ,TableConstraintDef Nothing $
> TableReferencesConstraint
> [Name Nothing "a"]
> [Name Nothing "u"]
> (Just [Name Nothing "c"])
> DefaultReferenceMatch
> DefaultReferentialAction DefaultReferentialAction
> ,TableConstraintDef Nothing $
> TableReferencesConstraint
> [Name Nothing "b"]
> [Name Nothing "v"]
> (Just [Name Nothing "d"])
> DefaultReferenceMatch
> DefaultReferentialAction DefaultReferentialAction
> ])


<references specification> ::=
Expand Down

0 comments on commit 51157d5

Please sign in to comment.