From 7bc2f224bb254463eec67058c4f3a9311b00c1e4 Mon Sep 17 00:00:00 2001 From: mhz1g21 <mhz1g21@soton.ac.uk> Date: Wed, 26 Apr 2023 14:08:25 +0100 Subject: [PATCH] added tile validation on join --- Grammar.y | 3 ++- Julio.hs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Grammar.y b/Grammar.y index 352da9b..ea6b8d5 100644 --- a/Grammar.y +++ b/Grammar.y @@ -3,7 +3,8 @@ module Grammar where import Tokens } -%name parseJulio +%name parse +Julio %tokentype { Token } %error { parseError } %token diff --git a/Julio.hs b/Julio.hs index 37ee4d5..8ebb54e 100644 --- a/Julio.hs +++ b/Julio.hs @@ -366,7 +366,11 @@ evaluateJoinH e1 e2 env = do return (TileValue joinedTile) _ -> error "Both operands of joinH should be a Tile" -joinTilesH t1 t2 = zipWith (++) t1 t2 +joinTilesH t1 t2 = do + let equal = length t1 == length t2 + case (equal) of + True -> zipWith (++) t1 t2 + False -> error "Tiles must have the same number of rows to be joined horizontally" --join tiles vertically evaluateJoinV e1 e2 env = do @@ -378,7 +382,12 @@ evaluateJoinV e1 e2 env = do return (TileValue joinedTile) _ -> error "Both operands of joinV should be a Tile" -joinTilesV t1 t2 = t1 ++ t2 +joinTilesV t1 t2 = do + let equal = length (head t1) == length (head t2) + case (equal) of + True -> t1 ++ t2 + False -> error "Tiles must have the same number of columns to be joined vertically" + --export tile -- GitLab