1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 07:25:44 +03:00

Assign module exports including:

- Constructor Operators
- Type Operators
- Variable Operators
- Module Exports (exporting a module)
- Constructor Symbols
- Variable Symbols
- Qualified Module Identifiers
This commit is contained in:
Rick Winfrey 2018-06-07 14:17:39 -07:00
parent b9d7f5fe46
commit 5c0191378b
35 changed files with 354 additions and 21 deletions

View File

@ -33,13 +33,16 @@ type Syntax = '[
, Literal.Float
, Literal.Integer
, Literal.TextElement
, Syntax.AllConstructors
, Syntax.AnnotatedTypeVariable
, Syntax.Class
, Syntax.ConstructorOperator
, Syntax.Context
, Syntax.Context'
, Syntax.Deriving
, Syntax.Empty
, Syntax.Error
, Syntax.Export
, Syntax.Field
, Syntax.FunctionConstructor
, Syntax.FunctionType
@ -52,7 +55,9 @@ type Syntax = '[
, Syntax.KindSignature
, Syntax.ListConstructor
, Syntax.Module
, Syntax.ModuleExport
, Syntax.Pragma
, Syntax.QualifiedModuleIdentifier
, Syntax.QualifiedTypeConstructorIdentifier
, Syntax.RecordDataConstructor
, Syntax.Star
@ -60,9 +65,11 @@ type Syntax = '[
, Syntax.StrictTypeVariable
, Syntax.TupleConstructor
, Syntax.Type
, Syntax.TypeConstructorExport
, Syntax.TypeSignature
, Syntax.TypeSynonym
, Syntax.UnitConstructor
, Syntax.VariableOperator
, Type.TypeParameters
, []
]
@ -84,6 +91,9 @@ algebraicDatatypeDeclaration = makeTerm
<|> pure [])
<*> (derivingClause <|> emptyTerm))
allConstructors :: Assignment
allConstructors = makeTerm <$> token AllConstructors <*> pure Syntax.AllConstructors
annotatedTypeVariable :: Assignment
annotatedTypeVariable = makeTerm <$> symbol AnnotatedTypeVariable <*> children (Syntax.AnnotatedTypeVariable <$> typeVariableIdentifier <* token Annotation <*> (kind <|> type'))
@ -103,6 +113,12 @@ constructor = (makeTerm <$> symbol DataConstructor <*> children (Declaration.Co
constructorIdentifier :: Assignment
constructorIdentifier = makeTerm <$> symbol ConstructorIdentifier <*> (Syntax.Identifier . Name.name <$> source)
constructorOperator :: Assignment
constructorOperator = makeTerm <$> symbol ConstructorOperator <*> children (Syntax.ConstructorOperator <$> expression)
constructorSymbol :: Assignment
constructorSymbol = makeTerm <$> symbol ConstructorSymbol <*> (Syntax.Identifier . Name.name <$> source)
context' :: Assignment
context' = makeTerm <$> symbol Context <*> children (Syntax.Context' <$> many (type' <|> contextPattern))
@ -112,6 +128,9 @@ contextPattern = symbol ContextPattern *> children type'
derivingClause :: Assignment
derivingClause = makeTerm <$> symbol Deriving <*> children (Syntax.Deriving <$> many typeConstructor)
export :: Assignment
export = makeTerm <$> symbol Export <*> children (Syntax.Export <$> expressions)
expressions :: Assignment
expressions = makeTerm'' <$> location <*> many expression
@ -121,11 +140,14 @@ expression = term (handleError (choice expressionChoices))
expressionChoices :: [Assignment.Assignment [] Grammar Term]
expressionChoices = [
algebraicDatatypeDeclaration
, allConstructors
, annotatedTypeVariable
, character
, comment
, context'
, constructorIdentifier
, constructorOperator
, constructorSymbol
, derivingClause
, float
, functionConstructor
@ -139,12 +161,15 @@ expressionChoices = [
, listConstructor
, listExpression
, listType
, moduleExport
, moduleIdentifier
, qualifiedModuleIdentifier
, qualifiedTypeConstructorIdentifier
, star
, strictType
, string
, type'
, typeConstructorExport
, typeConstructorIdentifier
, typeSignature
, typeSynonymDeclaration
@ -152,6 +177,8 @@ expressionChoices = [
, tuplingConstructor
, unitConstructor
, variableIdentifier
, variableOperator
, variableSymbol
, where'
]
@ -242,7 +269,13 @@ listType = makeTerm <$> symbol ListType <*> children (Literal.Array <$> many typ
module' :: Assignment
module' = makeTerm
<$> symbol Module
<*> children (Syntax.Module <$> (moduleIdentifier <|> emptyTerm) <*> pure [] <*> (where' <|> expressions <|> emptyTerm))
<*> children (Syntax.Module <$> (term moduleIdentifier <|> emptyTerm) <*> moduleExports <*> (where' <|> expressions <|> emptyTerm))
where
moduleExports = symbol ModuleExports *> children (many export)
<|> pure []
moduleExport :: Assignment
moduleExport = makeTerm <$> symbol ModuleExport <*> children (Syntax.ModuleExport <$> expressions)
moduleIdentifier :: Assignment
moduleIdentifier = makeTerm <$> symbol ModuleIdentifier <*> (Syntax.Identifier . Name.name <$> source)
@ -253,6 +286,9 @@ parenthesizedTypePattern = symbol ParenthesizedTypePattern *> children typeParam
pragma :: Assignment
pragma = makeTerm <$> symbol Pragma <*> (Syntax.Pragma <$> source)
qualifiedModuleIdentifier :: Assignment
qualifiedModuleIdentifier = makeTerm <$> symbol QualifiedModuleIdentifier <*> children (Syntax.QualifiedModuleIdentifier <$> many expression)
qualifiedTypeConstructorIdentifier :: Assignment
qualifiedTypeConstructorIdentifier = makeTerm <$> symbol QualifiedTypeConstructorIdentifier <*> children (Syntax.QualifiedTypeConstructorIdentifier <$> many expression)
@ -271,6 +307,9 @@ string = makeTerm <$> symbol String <*> (Literal.TextElement <$> source)
typeClassIdentifier :: Assignment
typeClassIdentifier = makeTerm <$> symbol TypeClassIdentifier <*> (Syntax.Identifier . Name.name <$> source)
typeConstructorExport :: Assignment
typeConstructorExport = makeTerm <$> symbol TypeConstructorExport <*> children (Syntax.TypeConstructorExport <$> expression)
typeConstructorIdentifier :: Assignment
typeConstructorIdentifier = makeTerm <$> symbol TypeConstructorIdentifier <*> (Syntax.Identifier . Name.name <$> source)
@ -311,6 +350,7 @@ typeConstructor = constructorIdentifier
<|> functionConstructor
<|> listConstructor
<|> listType
<|> qualifiedModuleIdentifier
<|> qualifiedTypeConstructorIdentifier
<|> typeClassIdentifier
<|> typeConstructorIdentifier
@ -332,6 +372,12 @@ unitConstructor = makeTerm <$> token UnitConstructor <*> pure Syntax.UnitConstru
variableIdentifier :: Assignment
variableIdentifier = makeTerm <$> symbol VariableIdentifier <*> (Syntax.Identifier . Name.name <$> source)
variableOperator :: Assignment
variableOperator = makeTerm <$> symbol VariableOperator <*> children (Syntax.VariableOperator <$> expression)
variableSymbol :: Assignment
variableSymbol = makeTerm <$> (symbol VariableSymbol <|> symbol VariableSymbol') <*> (Syntax.Identifier . Name.name <$> source)
variableIdentifiers :: Assignment
variableIdentifiers = makeTerm <$> location <*> many variableIdentifier

View File

@ -243,3 +243,66 @@ instance Ord1 AnnotatedTypeVariable where liftCompare = genericLiftCompare
instance Show1 AnnotatedTypeVariable where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable AnnotatedTypeVariable
newtype QualifiedModuleIdentifier a = QualifiedModuleIdentifier { qualifiedModuleIdentifierName :: [a] }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 QualifiedModuleIdentifier where liftEq = genericLiftEq
instance Ord1 QualifiedModuleIdentifier where liftCompare = genericLiftCompare
instance Show1 QualifiedModuleIdentifier where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable QualifiedModuleIdentifier
newtype Export a = Export { exportContent :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 Export where liftEq = genericLiftEq
instance Ord1 Export where liftCompare = genericLiftCompare
instance Show1 Export where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Export
newtype ModuleExport a = ModuleExport { moduleExportContent :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 ModuleExport where liftEq = genericLiftEq
instance Ord1 ModuleExport where liftCompare = genericLiftCompare
instance Show1 ModuleExport where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable ModuleExport
newtype TypeConstructorExport a = TypeConstructorExport { typeConstructorExportContent :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 TypeConstructorExport where liftEq = genericLiftEq
instance Ord1 TypeConstructorExport where liftCompare = genericLiftCompare
instance Show1 TypeConstructorExport where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable TypeConstructorExport
newtype VariableOperator a = VariableOperator { variableOperatorContent :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 VariableOperator where liftEq = genericLiftEq
instance Ord1 VariableOperator where liftCompare = genericLiftCompare
instance Show1 VariableOperator where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable VariableOperator
data AllConstructors a = AllConstructors
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 AllConstructors where liftEq = genericLiftEq
instance Ord1 AllConstructors where liftCompare = genericLiftCompare
instance Show1 AllConstructors where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable AllConstructors
newtype ConstructorOperator a = ConstructorOperator { constructorOperatorContent :: a }
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
instance Eq1 ConstructorOperator where liftEq = genericLiftEq
instance Ord1 ConstructorOperator where liftCompare = genericLiftCompare
instance Show1 ConstructorOperator where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable ConstructorOperator

View File

@ -80,20 +80,26 @@
{ (Identifier)
->(Identifier) }
(TypeParameters))
(Constructor
(Empty)
{ (Identifier)
->(Identifier) }
(TypeParameters))
{+(Constructor
{+(Empty)+}
{+(Identifier)+}
{+(TypeParameters)+})+}
(Constructor
(Empty)
{ (Identifier)
->(Identifier) }
(TypeParameters))
{+(Constructor
{+(Empty)+}
{+(Identifier)+}
{+(TypeParameters)+})+}
{+(Constructor
{+(Empty)+}
{+(Identifier)+}
{+(TypeParameters)+})+}
{-(Constructor
{-(Empty)-}
{-(Identifier)-}
{-(TypeParameters)-})-}
{-(Constructor
{-(Empty)-}
{-(Identifier)-}
{-(TypeParameters)-})-}
{-(Constructor
{-(Empty)-}
{-(Identifier)-}

View File

@ -80,6 +80,10 @@
{ (Identifier)
->(Identifier) }
(TypeParameters))
{+(Constructor
{+(Empty)+}
{+(Identifier)+}
{+(TypeParameters)+})+}
(Constructor
(Empty)
{ (Identifier)
@ -89,10 +93,6 @@
{+(Empty)+}
{+(Identifier)+}
{+(TypeParameters)+})+}
{+(Constructor
{+(Empty)+}
{+(Identifier)+}
{+(TypeParameters)+})+}
{-(Constructor
{-(Empty)-}
{-(Identifier)-}

View File

@ -49,12 +49,10 @@
{+(Identifier)+}
{+(Statements
{+(Float)+})+})+}
(Function
{ (Identifier)
->(Identifier) }
(Statements
{+(Float)+}
{-(Integer)-}))
{+(Function
{+(Identifier)+}
{+(Statements
{+(Float)+})+})+}
{+(Function
{+(Identifier)+}
{+(Statements
@ -285,6 +283,10 @@
{-(Identifier)-}
{-(Statements
{-(Integer)-})-})-}
{-(Function
{-(Identifier)-}
{-(Statements
{-(Integer)-})-})-}
{-(Function
{-(Identifier)-}
{-(Statements

View File

@ -0,0 +1 @@
module A where

View File

@ -0,0 +1 @@
module B where

View File

@ -0,0 +1,4 @@
(Module
{ (Identifier)
->(Identifier) }
(Statements))

View File

@ -0,0 +1,4 @@
(Module
{ (Identifier)
->(Identifier) }
(Statements))

View File

@ -0,0 +1,3 @@
(Module
(Identifier)
(Statements))

View File

@ -0,0 +1,3 @@
(Module
(Identifier)
(Statements))

View File

@ -0,0 +1 @@
module A () where

View File

@ -0,0 +1 @@
module B () where

View File

@ -0,0 +1,4 @@
(Module
{ (Identifier)
->(Identifier) }
(Statements))

View File

@ -0,0 +1,4 @@
(Module
{ (Identifier)
->(Identifier) }
(Statements))

View File

@ -0,0 +1,3 @@
(Module
(Identifier)
(Statements))

View File

@ -0,0 +1,3 @@
(Module
(Identifier)
(Statements))

View File

@ -0,0 +1 @@
module A.B' where

View File

@ -0,0 +1 @@
module B.A' where

View File

@ -0,0 +1,9 @@
(Module
(Empty)
(Statements
(QualifiedModuleIdentifier
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) })
(Statements)))

View File

@ -0,0 +1,9 @@
(Module
(Empty)
(Statements
(QualifiedModuleIdentifier
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) })
(Statements)))

View File

@ -0,0 +1,7 @@
(Module
(Empty)
(Statements
(QualifiedModuleIdentifier
(Identifier)
(Identifier))
(Statements)))

View File

@ -0,0 +1,7 @@
(Module
(Empty)
(Statements
(QualifiedModuleIdentifier
(Identifier)
(Identifier))
(Statements)))

View File

@ -0,0 +1 @@
module A (type(+), (+)) where

View File

@ -0,0 +1 @@
module A (type(-), (-)) where

View File

@ -0,0 +1,12 @@
(Module
(Identifier)
(Export
(TypeConstructorExport
(VariableOperator
{ (Identifier)
->(Identifier) })))
(Export
(VariableOperator
{ (Identifier)
->(Identifier) }))
(Statements))

View File

@ -0,0 +1,12 @@
(Module
(Identifier)
(Export
(TypeConstructorExport
(VariableOperator
{ (Identifier)
->(Identifier) })))
(Export
(VariableOperator
{ (Identifier)
->(Identifier) }))
(Statements))

View File

@ -0,0 +1,10 @@
(Module
(Identifier)
(Export
(TypeConstructorExport
(VariableOperator
(Identifier))))
(Export
(VariableOperator
(Identifier)))
(Statements))

View File

@ -0,0 +1,10 @@
(Module
(Identifier)
(Export
(TypeConstructorExport
(VariableOperator
(Identifier))))
(Export
(VariableOperator
(Identifier)))
(Statements))

View File

@ -0,0 +1 @@
module A (Maybe(..), type(:<), type(+), maybe', module A, type Foo,) where

View File

@ -0,0 +1 @@
module B (Maybe(..), type(:+), type(-), maybe', module B, type Bar,) where

View File

@ -0,0 +1,28 @@
(Module
{ (Identifier)
->(Identifier) }
(Export
(Statements
(Identifier)
(AllConstructors)))
(Export
(TypeConstructorExport
(ConstructorOperator
{ (Identifier)
->(Identifier) })))
(Export
(TypeConstructorExport
(VariableOperator
{ (Identifier)
->(Identifier) })))
(Export
(Identifier))
(Export
(ModuleExport
{ (Identifier)
->(Identifier) }))
(Export
(TypeConstructorExport
{ (Identifier)
->(Identifier) }))
(Statements))

View File

@ -0,0 +1,28 @@
(Module
{ (Identifier)
->(Identifier) }
(Export
(Statements
(Identifier)
(AllConstructors)))
(Export
(TypeConstructorExport
(ConstructorOperator
{ (Identifier)
->(Identifier) })))
(Export
(TypeConstructorExport
(VariableOperator
{ (Identifier)
->(Identifier) })))
(Export
(Identifier))
(Export
(ModuleExport
{ (Identifier)
->(Identifier) }))
(Export
(TypeConstructorExport
{ (Identifier)
->(Identifier) }))
(Statements))

View File

@ -0,0 +1,23 @@
(Module
(Identifier)
(Export
(Statements
(Identifier)
(AllConstructors)))
(Export
(TypeConstructorExport
(ConstructorOperator
(Identifier))))
(Export
(TypeConstructorExport
(VariableOperator
(Identifier))))
(Export
(Identifier))
(Export
(ModuleExport
(Identifier)))
(Export
(TypeConstructorExport
(Identifier)))
(Statements))

View File

@ -0,0 +1,23 @@
(Module
(Identifier)
(Export
(Statements
(Identifier)
(AllConstructors)))
(Export
(TypeConstructorExport
(ConstructorOperator
(Identifier))))
(Export
(TypeConstructorExport
(VariableOperator
(Identifier))))
(Export
(Identifier))
(Export
(ModuleExport
(Identifier)))
(Export
(TypeConstructorExport
(Identifier)))
(Statements))