From eb87b3a000ef3019d99828b71068c8cfcd9d3caa Mon Sep 17 00:00:00 2001
From: Neil Smith <neil.git@njae.me.uk>
Date: Fri, 23 Dec 2016 18:40:04 +0000
Subject: [PATCH] Tidying, especially the parser

---
 adventofcode16/app/advent23.hs | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/adventofcode16/app/advent23.hs b/adventofcode16/app/advent23.hs
index 20c4a15..dfb98cd 100644
--- a/adventofcode16/app/advent23.hs
+++ b/adventofcode16/app/advent23.hs
@@ -162,15 +162,14 @@ writeValue m (Register r) v =
 instructionFile = instructionLine `sepEndBy` newline 
 instructionLine = incL <|> decL <|> cpyL <|> jnzL <|> tglL
 
-incL = (Inc . Register) <$> (string "inc" *> spaces *> (oneOf "abcd"))
-decL = (Dec . Register) <$> (string "dec" *> spaces *> (oneOf "abcd"))
-cpyL = cpyify <$> (string "cpy" *> spaces *> ((Literal <$> int) <|> ((Register . head) <$> (many1 letter))))
-              <*> (spaces *> (oneOf "abcd"))
-        where cpyify s r = Cpy s (Register r)
-jnzL = jnzify <$> (string "jnz" *> spaces *> ((Literal <$> int) <|> ((Register . head) <$> (many1 letter))))
-              <*> (spaces *> ((Literal <$> int) <|> ((Register . head) <$> (many1 letter))))
-        where jnzify r o = Jnz r o
-tglL = Tgl <$> (string "tgl" *> spaces *> ((Literal <$> int) <|> ((Register . head) <$> (many1 letter)))) 
+incL = Inc <$> (string "inc" *> spaces *> register)
+decL = Dec <$> (string "dec" *> spaces *> register)
+cpyL = Cpy <$> (string "cpy" *> spaces *> location) <*> (spaces *> register)
+jnzL = Jnz <$> (string "jnz" *> spaces *> location) <*> (spaces *> location)
+tglL = Tgl <$> (string "tgl" *> spaces *> location)
+
+location = (Literal <$> int) <|> register
+register = Register <$> (oneOf "abcd")
 
 parseIfile :: String -> Either ParseError [Instruction]
 parseIfile input = parse instructionFile "(unknown)" input
-- 
2.43.0