diff --git a/src/Category.hs b/src/Category.hs index bbf5456b9..88298819a 100644 --- a/src/Category.hs +++ b/src/Category.hs @@ -17,6 +17,8 @@ data Category | Pair -- | A call to a function. | FunctionCall + -- | A function declaration + | Function -- | A string literal. | StringLiteral -- | An integer literal. diff --git a/src/DiffSummary.hs b/src/DiffSummary.hs index ffbbff986..b2d2511e7 100644 --- a/src/DiffSummary.hs +++ b/src/DiffSummary.hs @@ -23,6 +23,7 @@ toTermName term = case runCofree term of (_ :< Indexed children) -> fromMaybe "EmptyIndexedNode" $ (toCategoryName . category) . extract <$> head children (_ :< Fixed children) -> fromMaybe "EmptyFixedNode" $ (toCategoryName . category) . extract <$> head children (_ :< Syntax.FunctionCall i _) -> toTermName i + (_ :< Syntax.Function _) -> "anonymous function" class HasCategory a where toCategoryName :: a -> Text diff --git a/src/Parser.hs b/src/Parser.hs index d9a1cd490..921bec288 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -30,6 +30,10 @@ fixedCategories = Set.fromList [ BinaryOperator, Pair ] functionCallCategories :: Set.Set Category functionCallCategories = Set.singleton Category.FunctionCall +-- | Categories that are treated as functionCall nodes. +functionCategories :: Set.Set Category +functionCategories = Set.singleton Category.Function + -- | Should these categories be treated as keyed nodes? isKeyed :: Category -> Bool isKeyed = flip Set.member keyedCategories @@ -41,6 +45,9 @@ isFixed = flip Set.member fixedCategories isFunctionCall :: Category -> Bool isFunctionCall = flip Set.member functionCallCategories +isFunction :: Category -> Bool +isFunction = flip Set.member functionCategories + -- | Given a function that maps production names to sets of categories, produce -- | a Constructor. termConstructor :: Constructor @@ -50,6 +57,7 @@ termConstructor source info children = cofree (info :< syntax) construct :: [Term Text Info] -> Syntax Text (Term Text Info) construct [] = Leaf . pack . toString $ slice (characterRange info) source construct children | isFunctionCall (category info), (x:xs) <- children = Syntax.FunctionCall x xs + construct children | isFunction (category info) = Syntax.Function children construct children | isFixed (category info) = Fixed children construct children | isKeyed (category info) = Keyed . Map.fromList $ assignKey <$> children construct children = Indexed children diff --git a/src/Syntax.hs b/src/Syntax.hs index e767637f7..22feaa6b7 100644 --- a/src/Syntax.hs +++ b/src/Syntax.hs @@ -19,4 +19,6 @@ data Syntax | Keyed (OrderedMap T.Text f) -- | A function call has an identifier where f is a (Leaf a) and a list of arguments. | FunctionCall f [f] + -- | A function has a list of expressions. + | Function [f] deriving (Functor, Show, Eq, Foldable, Traversable)