Tobias Dammers avatar Tobias Dammers committed 03499be

Concatenation test passes for PHP, JS, run

Comments (0)

Files changed (7)

hpaco-lib/Data/Variant.hs

 import Data.Maybe
 import Safe
 import Text.Printf
+import Data.Monoid
 
 data Variant = Null
              | Integer Integer
         compare _ Null = GT
         compare _ _ = EQ
 
+instance Monoid Variant
+    where
+        mempty = Null
+        mappend Null a = a
+        mappend a Null = a
+        mappend (List xs) (List ys) = List (xs ++ ys)
+        mappend (AList xs) (AList ys) = AList (xs ++ ys)
+        mappend (List xs) (AList ys) = List (xs ++ map snd ys)
+        mappend (AList xs) (List ys) = List (map snd xs ++ ys)
+        mappend a b = String (flatten a ++ flatten b)
+
 flatten :: Variant -> String
 flatten (String s) = s
 flatten (Integer i) = show i

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

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

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

 
 additiveExpression =
     binaryExpression
-        [("+", OpPlus), ("-", OpMinus)]
+        [("++", OpConcat),
+         ("+", OpPlus),
+         ("-", OpMinus)]
         multiplicativeExpression
 
 multiplicativeExpression =

hpaco-lib/Text/HPaco/Writers/Javascript.hs

                             OpNotLess -> ">="
                             OpBooleanAnd -> "&&"
                             OpBooleanOr -> "||"
-            if o `elem` numericOps
-                then write "(Number("
-                else write "(("
-            writeExpression left
-            write ")"
+                            OpConcat -> "+"
+            write "("
+            wrappedArg o left
             write opstr
-            if o `elem` numericOps
-                then write "Number("
-                else write "("
-            writeExpression right
-            write "))"
-            where numericOps = [
-                     OpPlus,
-                     OpMinus,
-                     OpMul,
-                     OpDiv,
-                     OpMod,
-                     OpGreater,
-                     OpLess,
-                     OpNotGreater,
-                     OpNotLess ]
+            wrappedArg o right
+            write ")"
+            where
+                numericOps = [
+                    OpPlus,
+                    OpMinus,
+                    OpMul,
+                    OpDiv,
+                    OpMod,
+                    OpGreater,
+                    OpLess,
+                    OpNotGreater,
+                    OpNotLess ]
+                stringOps = [
+                    OpConcat ]
+                wrappedArg o i =
+                    let wrapWord =
+                            if o `elem` numericOps
+                                then "Number"
+                                else if o `elem` stringOps
+                                then "String"
+                                else ""
+                    in write wrapWord >> write "(" >> writeExpression i >> write ")"
+               
+
 
         UnaryExpression o e -> do
             let opstr = case o of

hpaco-lib/Text/HPaco/Writers/JsonLisp.hs

             binaryOperatorToken OpBooleanOr = "or"
             binaryOperatorToken OpBooleanXor = "xor"
             binaryOperatorToken OpInList = "in"
+            binaryOperatorToken OpConcat = "join"
             unaryOperatorToken :: UnaryOperator -> String
             unaryOperatorToken OpNot = "not"
 

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

                             OpBooleanAnd -> "&&"
                             OpBooleanOr -> "||"
                             OpBooleanXor -> " xor "
+                            OpConcat -> "."
             withParens $ do
                 writeExpression left
                 write opstr

hpaco-lib/Text/HPaco/Writers/Run.hs

 import Data.Variant
 import qualified Data.Variant as V
 import Data.Maybe
+import Data.Monoid
 import qualified Data.List as List
 import qualified Data.List.Split as Split
 import Control.Monad.State
 
 applyBinaryOperation OpMember = flip V.lookup
 applyBinaryOperation OpInList = V.elem
+applyBinaryOperation OpConcat = mappend
 
 applyBinaryOperation OpBooleanAnd = \l -> \r ->
     Bool $ toBool l && toBool r
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.