2016-02-04 21:59:33 +03:00
|
|
|
module Category where
|
2015-11-18 22:23:35 +03:00
|
|
|
|
2016-05-26 19:58:04 +03:00
|
|
|
import Prologue
|
2016-06-23 16:55:48 +03:00
|
|
|
import Data.Hashable
|
2016-07-13 21:32:53 +03:00
|
|
|
import Test.QuickCheck (oneof, Arbitrary, arbitrary, shrink)
|
2016-07-17 18:18:31 +03:00
|
|
|
import Test.QuickCheck.Arbitrary
|
|
|
|
import Data.Text (unpack)
|
2016-07-06 23:22:25 +03:00
|
|
|
import Data.Text.Arbitrary()
|
2015-11-18 22:23:35 +03:00
|
|
|
|
2016-02-05 00:35:42 +03:00
|
|
|
-- | A standardized category of AST node. Used to determine the semantics for
|
|
|
|
-- | semantic diffing and define comparability of nodes.
|
2016-06-04 01:32:21 +03:00
|
|
|
data Category
|
2016-06-04 01:34:42 +03:00
|
|
|
-- | The top-level branch node.
|
|
|
|
= Program
|
2016-06-04 01:37:40 +03:00
|
|
|
-- | A node indicating syntax errors.
|
|
|
|
| Error
|
2016-06-16 17:54:05 +03:00
|
|
|
-- | A boolean expression.
|
|
|
|
| Boolean
|
2016-02-06 00:59:38 +03:00
|
|
|
-- | An operator with 2 operands.
|
2016-06-04 01:34:42 +03:00
|
|
|
| BinaryOperator
|
2016-02-05 00:35:42 +03:00
|
|
|
-- | A literal key-value data structure.
|
2016-02-06 00:59:38 +03:00
|
|
|
| DictionaryLiteral
|
2016-02-14 05:01:52 +03:00
|
|
|
-- | A pair, e.g. of a key & value
|
|
|
|
| Pair
|
2016-02-06 00:54:08 +03:00
|
|
|
-- | A call to a function.
|
|
|
|
| FunctionCall
|
2016-06-10 22:19:29 +03:00
|
|
|
-- | A function declaration.
|
2016-06-10 20:11:32 +03:00
|
|
|
| Function
|
2016-06-10 22:19:29 +03:00
|
|
|
-- | An identifier.
|
|
|
|
| Identifier
|
2016-06-12 21:29:48 +03:00
|
|
|
-- | A function's parameters.
|
2016-06-10 22:10:50 +03:00
|
|
|
| Params
|
2016-06-12 21:29:48 +03:00
|
|
|
-- | A function's expression statements.
|
2016-06-10 22:10:50 +03:00
|
|
|
| ExpressionStatements
|
2016-06-13 00:26:20 +03:00
|
|
|
-- | A method call on an object.
|
|
|
|
| MethodCall
|
2016-06-14 19:53:35 +03:00
|
|
|
-- | A method's arguments.
|
|
|
|
| Args
|
2016-02-24 23:47:53 +03:00
|
|
|
-- | A string literal.
|
|
|
|
| StringLiteral
|
|
|
|
-- | An integer literal.
|
|
|
|
| IntegerLiteral
|
2016-06-15 19:09:52 +03:00
|
|
|
-- | A regex literal.
|
|
|
|
| Regex
|
2016-02-24 23:47:53 +03:00
|
|
|
-- | A symbol literal.
|
|
|
|
| SymbolLiteral
|
2016-06-15 18:38:16 +03:00
|
|
|
-- | A template string literal.
|
|
|
|
| TemplateString
|
2016-03-03 07:01:46 +03:00
|
|
|
-- | An array literal.
|
|
|
|
| ArrayLiteral
|
2016-06-14 01:31:45 +03:00
|
|
|
-- | An assignment expression.
|
2016-06-14 00:31:32 +03:00
|
|
|
| Assignment
|
2016-06-17 22:57:51 +03:00
|
|
|
-- | A math assignment expression.
|
|
|
|
| MathAssignment
|
2016-06-14 01:31:45 +03:00
|
|
|
-- | A member access expression.
|
|
|
|
| MemberAccess
|
2016-06-17 22:38:12 +03:00
|
|
|
-- | A subscript access expression.
|
|
|
|
| SubscriptAccess
|
2016-06-15 03:43:26 +03:00
|
|
|
-- | A variable assignment within a variable declaration.
|
|
|
|
| VarAssignment
|
|
|
|
-- | A variable declaration.
|
|
|
|
| VarDecl
|
2016-06-17 23:31:50 +03:00
|
|
|
-- | A switch expression.
|
2016-06-16 01:48:27 +03:00
|
|
|
| Switch
|
2016-06-17 23:31:40 +03:00
|
|
|
-- | A ternary expression.
|
|
|
|
| Ternary
|
2016-06-17 23:31:50 +03:00
|
|
|
-- | A case expression.
|
2016-06-16 01:48:27 +03:00
|
|
|
| Case
|
2016-06-18 01:02:54 +03:00
|
|
|
-- | An expression with an operator.
|
|
|
|
| Operator
|
2016-06-24 00:39:27 +03:00
|
|
|
-- | An object/dictionary/hash literal.
|
|
|
|
| Object
|
2016-02-05 00:35:42 +03:00
|
|
|
-- | A non-standard category, which can be used for comparability.
|
2016-06-06 22:45:44 +03:00
|
|
|
| Other Text
|
2016-06-23 16:55:43 +03:00
|
|
|
deriving (Eq, Generic, Ord, Show)
|
2016-06-23 16:55:48 +03:00
|
|
|
|
2016-06-23 23:25:49 +03:00
|
|
|
-- Instances
|
|
|
|
|
2016-06-23 16:55:48 +03:00
|
|
|
instance Hashable Category
|
2016-06-23 23:29:19 +03:00
|
|
|
|
2016-07-17 18:18:31 +03:00
|
|
|
instance CoArbitrary Text where
|
|
|
|
coarbitrary = coarbitrary . unpack
|
|
|
|
instance CoArbitrary Category where
|
|
|
|
coarbitrary = genericCoarbitrary
|
|
|
|
|
2016-06-23 23:29:19 +03:00
|
|
|
instance Arbitrary Category where
|
2016-07-13 21:32:53 +03:00
|
|
|
arbitrary = oneof [
|
2016-07-17 18:18:31 +03:00
|
|
|
pure Program
|
2016-06-23 23:29:19 +03:00
|
|
|
, pure Error
|
2016-07-13 21:32:53 +03:00
|
|
|
, pure Boolean
|
2016-06-23 23:29:19 +03:00
|
|
|
, pure BinaryOperator
|
|
|
|
, pure DictionaryLiteral
|
|
|
|
, pure Pair
|
|
|
|
, pure FunctionCall
|
2016-07-13 21:32:53 +03:00
|
|
|
, pure Function
|
|
|
|
, pure Identifier
|
|
|
|
, pure Params
|
|
|
|
, pure ExpressionStatements
|
|
|
|
, pure MethodCall
|
|
|
|
, pure Args
|
2016-06-23 23:29:19 +03:00
|
|
|
, pure StringLiteral
|
|
|
|
, pure IntegerLiteral
|
2016-07-13 21:32:53 +03:00
|
|
|
, pure Regex
|
2016-06-23 23:29:19 +03:00
|
|
|
, pure SymbolLiteral
|
2016-07-13 21:32:53 +03:00
|
|
|
, pure TemplateString
|
2016-06-23 23:29:19 +03:00
|
|
|
, pure ArrayLiteral
|
2016-07-13 21:32:53 +03:00
|
|
|
, pure Assignment
|
|
|
|
, pure MathAssignment
|
|
|
|
, pure MemberAccess
|
|
|
|
, pure SubscriptAccess
|
|
|
|
, pure VarAssignment
|
|
|
|
, pure VarDecl
|
|
|
|
, pure Switch
|
|
|
|
, pure Ternary
|
|
|
|
, pure Case
|
|
|
|
, pure Operator
|
|
|
|
, pure Object
|
2016-06-23 23:29:19 +03:00
|
|
|
, Other <$> arbitrary
|
|
|
|
]
|
|
|
|
|
|
|
|
shrink (Other s) = Other <$> shrink s
|
|
|
|
shrink _ = []
|