Commits

Tobias Dammers  committed 2c9ed5d

PHP mode passes coalesce test

  • Participants
  • Parent commits 6bcb086

Comments (0)

Files changed (3)

File hpaco-lib/Text/HPaco/AST/Expression.hs

                     | OpBooleanXor
                     | OpInList
                     | OpConcat
+                    | OpCoalesce
                     | Flipped BinaryOperator
                     deriving (Show, Eq)

File hpaco-lib/Text/HPaco/Readers/Paco/Expressions.hs

 multiplicativeExpression =
     binaryExpression
         [("*", OpMul), ("/", OpDiv), ("%", OpMod)]
+        coalesceExpression
+
+coalesceExpression =
+    binaryExpression
+        [("??", OpCoalesce)]
         (try traditionalFunctionCallExpression <|> postfixExpression)
 
 binaryExpression :: [(String, BinaryOperator)] -> Parser s Expression -> Parser s Expression

File hpaco-lib/Text/HPaco/Writers/PHP.hs

             writeExpressionPair left right
             write ")"
 
+        BinaryExpression OpCoalesce left right -> do
+            write "(is_null("
+            writeExpression left
+            write ") ? ("
+            writeExpression right
+            write ") : ("
+            writeExpression left
+            write "))"
+
         BinaryExpression o left right -> do
             let opstr = case o of
                             OpPlus -> "+"