From 090e09e4caa66d0b488837a4ee4143fcccefcad6 Mon Sep 17 00:00:00 2001
From: Vidar Holen <spam@vidarholen.net>
Date: Sat, 22 Aug 2015 14:20:20 -0700
Subject: [PATCH] Support nested trinary expressions.

---
 ShellCheck/Parser.hs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs
index 400472b..0c02222 100644
--- a/ShellCheck/Parser.hs
+++ b/ShellCheck/Parser.hs
@@ -553,6 +553,8 @@ prop_a16= isOk readArithmeticContents "$foo$bar"
 prop_a17= isOk readArithmeticContents "i<(0+(1+1))"
 prop_a18= isOk readArithmeticContents "a?b:c"
 prop_a19= isOk readArithmeticContents "\\\n3 +\\\n  2"
+prop_a20= isOk readArithmeticContents "a ? b ? c : d : e"
+prop_a21= isOk readArithmeticContents "a ? b : c ? d : e"
 readArithmeticContents =
     readSequence
   where
@@ -618,16 +620,15 @@ readArithmeticContents =
 
     readAssignment = readTrinary `splitBy` ["=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|="]
     readTrinary = do
-        let part = readLogicalOr
-        x <- part
+        x <- readLogicalOr
         do
             id <- getNextId
             string "?"
             spacing
-            y <- part
+            y <- readTrinary
             string ":"
             spacing
-            z <- part
+            z <- readTrinary
             return $ TA_Trinary id x y z
          <|>
           return x