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

Extract TSX.Syntax into a new module.

This commit is contained in:
Rob Rix 2019-10-18 16:04:04 -04:00
parent b3516fda6a
commit 148b94c368
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7
3 changed files with 190 additions and 176 deletions

View File

@ -192,6 +192,7 @@ library
, Language.TSX.Assignment
, Language.TSX.Syntax
, Language.TSX.Syntax.JSX
, Language.TSX.Term
, Language.TypeScript.Assignment
, Language.TypeScript.Resolution
, Language.TypeScript.Syntax

View File

@ -2,7 +2,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME
module Language.TSX.Assignment
( assignment
, Syntax
, TSX.Syntax
, Grammar
, Term
) where
@ -34,181 +34,11 @@ import qualified Data.Syntax.Type as Type
import qualified Data.Term as Term
import qualified Language.TSX.Syntax as TSX.Syntax
import qualified Language.TypeScript.Resolution as TypeScript.Resolution
import qualified Language.TSX.Term as TSX
import Prologue
import TreeSitter.TSX as Grammar
-- | The type of TSX syntax.
type Syntax = '[
Comment.Comment
, Comment.HashBang
, Declaration.Class
, Declaration.Function
, Declaration.Method
, Declaration.MethodSignature
, Declaration.InterfaceDeclaration
, Declaration.PublicFieldDefinition
, Declaration.VariableDeclaration
, Declaration.TypeAlias
, Expression.Plus
, Expression.Minus
, Expression.Times
, Expression.DividedBy
, Expression.Modulo
, Expression.Power
, Expression.Negate
, Expression.FloorDivision
, Expression.BAnd
, Expression.BOr
, Expression.BXOr
, Expression.LShift
, Expression.RShift
, Expression.UnsignedRShift
, Expression.Complement
, Expression.And
, Expression.Not
, Expression.Or
, Expression.XOr
, Expression.Call
, Expression.Cast
, Expression.LessThan
, Expression.LessThanEqual
, Expression.GreaterThan
, Expression.GreaterThanEqual
, Expression.Equal
, Expression.StrictEqual
, Expression.Comparison
, Expression.Enumeration
, Expression.MemberAccess
, Expression.NonNullExpression
, Expression.ScopeResolution
, Expression.SequenceExpression
, Expression.Subscript
, Expression.Member
, Expression.Delete
, Expression.Void
, Expression.Typeof
, Expression.InstanceOf
, Expression.New
, Expression.Await
, Expression.This
, Literal.Array
, Literal.Boolean
, Literal.Float
, Literal.Hash
, Literal.Integer
, Literal.KeyValue
, Literal.Null
, Literal.String
, Literal.TextElement
, Literal.Regex
, Statement.Assignment
, Statement.Break
, Statement.Catch
, Statement.Continue
, Statement.DoWhile
, Statement.Else
, Statement.Finally
, Statement.For
, Statement.ForEach
, Statement.If
, Statement.Match
, Statement.Pattern
, Statement.Retry
, Statement.Return
, Statement.ScopeEntry
, Statement.ScopeExit
, Statement.Statements
, Statement.Throw
, Statement.Try
, Statement.While
, Statement.Yield
, Syntax.AccessibilityModifier
, Syntax.Empty
, Syntax.Error
, Syntax.Identifier
, Syntax.Context
, Type.Readonly
, Type.TypeParameters
, TSX.Syntax.TypeParameter
, TSX.Syntax.Constraint
, TSX.Syntax.ParenthesizedType
, TSX.Syntax.DefaultType
, TSX.Syntax.PredefinedType
, TSX.Syntax.TypeIdentifier
, TSX.Syntax.NestedIdentifier
, TSX.Syntax.NestedTypeIdentifier
, TSX.Syntax.GenericType
, TSX.Syntax.TypeArguments
, TSX.Syntax.TypePredicate
, TSX.Syntax.CallSignature
, TSX.Syntax.ConstructSignature
, TSX.Syntax.ArrayType
, TSX.Syntax.LookupType
, TSX.Syntax.FlowMaybeType
, TSX.Syntax.TypeQuery
, TSX.Syntax.IndexTypeQuery
, TSX.Syntax.ThisType
, TSX.Syntax.ExistentialType
, TSX.Syntax.AbstractMethodSignature
, TSX.Syntax.IndexSignature
, TSX.Syntax.ObjectType
, TSX.Syntax.LiteralType
, TSX.Syntax.Union
, TSX.Syntax.Intersection
, TSX.Syntax.Module
, TSX.Syntax.InternalModule
, TSX.Syntax.FunctionType
, TSX.Syntax.Tuple
, TSX.Syntax.Constructor
, TSX.Syntax.TypeAssertion
, TSX.Syntax.ImportAlias
, TSX.Syntax.Debugger
, TSX.Syntax.ShorthandPropertyIdentifier
, TSX.Syntax.Super
, TSX.Syntax.Undefined
, TSX.Syntax.ClassHeritage
, TSX.Syntax.AbstractClass
, TSX.Syntax.ImplementsClause
, TSX.Syntax.JsxElement
, TSX.Syntax.JsxSelfClosingElement
, TSX.Syntax.JsxOpeningElement
, TSX.Syntax.JsxText
, TSX.Syntax.JsxClosingElement
, TSX.Syntax.JsxExpression
, TSX.Syntax.JsxAttribute
, TSX.Syntax.JsxFragment
, TSX.Syntax.JsxNamespaceName
, TSX.Syntax.OptionalParameter
, TSX.Syntax.RequiredParameter
, TSX.Syntax.RestParameter
, TSX.Syntax.PropertySignature
, TSX.Syntax.AmbientDeclaration
, TSX.Syntax.EnumDeclaration
, TSX.Syntax.ExtendsClause
, TSX.Syntax.AmbientFunction
, TSX.Syntax.ImportRequireClause
, TSX.Syntax.ImportClause
, TSX.Syntax.LabeledStatement
, TSX.Syntax.Annotation
, TSX.Syntax.With
, TSX.Syntax.ForOf
, TSX.Syntax.Update
, TSX.Syntax.ComputedPropertyName
, TSX.Syntax.Decorator
, TSX.Syntax.Import
, TSX.Syntax.QualifiedAliasedImport
, TSX.Syntax.SideEffectImport
, TSX.Syntax.DefaultExport
, TSX.Syntax.QualifiedExport
, TSX.Syntax.QualifiedExportFrom
, TSX.Syntax.JavaScriptRequire
, []
, Statement.StatementBlock
, TSX.Syntax.MetaProperty
, TSX.Syntax.AnnotatedExpression
]
type Term = Term.Term (Sum Syntax)
type Term = Term.Term (Sum TSX.Syntax)
type Assignment = Assignment.Assignment [] Grammar
-- | Assignment from AST in TSXs grammar onto a program in TSXs syntax.
@ -276,7 +106,7 @@ augmentedAssignmentExpression = makeTerm' <$> symbol AugmentedAssignmentExpressi
, assign Expression.UnsignedRShift <$ symbol AnonRAngleRAngleRAngleEqual
, assign Expression.LShift <$ symbol AnonLAngleLAngleEqual
, assign Expression.BOr <$ symbol AnonPipeEqual ])
where assign :: (f :< Syntax) => (Term Loc -> Term Loc -> f (Term Loc)) -> Term Loc -> Term Loc -> Sum Syntax (Term Loc)
where assign :: (f :< TSX.Syntax) => (Term Loc -> Term Loc -> f (Term Loc)) -> Term Loc -> Term Loc -> Sum TSX.Syntax (Term Loc)
assign c l r = inject (Statement.Assignment [] l (makeTerm1 (c l r)))
@ -958,6 +788,6 @@ emptyStatement = makeTerm <$> symbol EmptyStatement <*> (Syntax.Empty <$ rawSour
-- | Match infix terms separated by any of a list of operators, assigning any comments following each operand.
infixTerm :: Assignment (Term Loc)
-> Assignment (Term Loc)
-> [Assignment (Term Loc -> Term Loc -> Sum Syntax (Term Loc))]
-> Assignment (Sum Syntax (Term Loc))
-> [Assignment (Term Loc -> Term Loc -> Sum TSX.Syntax (Term Loc))]
-> Assignment (Sum TSX.Syntax (Term Loc))
infixTerm = infixContext comment

183
src/Language/TSX/Term.hs Normal file
View File

@ -0,0 +1,183 @@
{-# LANGUAGE DataKinds #-}
module Language.TSX.Term
( Syntax
) where
import qualified Data.Syntax as Syntax
import qualified Data.Syntax.Comment as Comment
import qualified Data.Syntax.Declaration as Declaration
import qualified Data.Syntax.Expression as Expression
import qualified Data.Syntax.Literal as Literal
import qualified Data.Syntax.Statement as Statement
import qualified Data.Syntax.Type as Type
import qualified Language.TSX.Syntax as TSX.Syntax
type Syntax =
[ Comment.Comment
, Comment.HashBang
, Declaration.Class
, Declaration.Function
, Declaration.Method
, Declaration.MethodSignature
, Declaration.InterfaceDeclaration
, Declaration.PublicFieldDefinition
, Declaration.VariableDeclaration
, Declaration.TypeAlias
, Expression.Plus
, Expression.Minus
, Expression.Times
, Expression.DividedBy
, Expression.Modulo
, Expression.Power
, Expression.Negate
, Expression.FloorDivision
, Expression.BAnd
, Expression.BOr
, Expression.BXOr
, Expression.LShift
, Expression.RShift
, Expression.UnsignedRShift
, Expression.Complement
, Expression.And
, Expression.Not
, Expression.Or
, Expression.XOr
, Expression.Call
, Expression.Cast
, Expression.LessThan
, Expression.LessThanEqual
, Expression.GreaterThan
, Expression.GreaterThanEqual
, Expression.Equal
, Expression.StrictEqual
, Expression.Comparison
, Expression.Enumeration
, Expression.MemberAccess
, Expression.NonNullExpression
, Expression.ScopeResolution
, Expression.SequenceExpression
, Expression.Subscript
, Expression.Member
, Expression.Delete
, Expression.Void
, Expression.Typeof
, Expression.InstanceOf
, Expression.New
, Expression.Await
, Expression.This
, Literal.Array
, Literal.Boolean
, Literal.Float
, Literal.Hash
, Literal.Integer
, Literal.KeyValue
, Literal.Null
, Literal.String
, Literal.TextElement
, Literal.Regex
, Statement.Assignment
, Statement.Break
, Statement.Catch
, Statement.Continue
, Statement.DoWhile
, Statement.Else
, Statement.Finally
, Statement.For
, Statement.ForEach
, Statement.If
, Statement.Match
, Statement.Pattern
, Statement.Retry
, Statement.Return
, Statement.ScopeEntry
, Statement.ScopeExit
, Statement.Statements
, Statement.Throw
, Statement.Try
, Statement.While
, Statement.Yield
, Syntax.AccessibilityModifier
, Syntax.Empty
, Syntax.Error
, Syntax.Identifier
, Syntax.Context
, Type.Readonly
, Type.TypeParameters
, TSX.Syntax.TypeParameter
, TSX.Syntax.Constraint
, TSX.Syntax.ParenthesizedType
, TSX.Syntax.DefaultType
, TSX.Syntax.PredefinedType
, TSX.Syntax.TypeIdentifier
, TSX.Syntax.NestedIdentifier
, TSX.Syntax.NestedTypeIdentifier
, TSX.Syntax.GenericType
, TSX.Syntax.TypeArguments
, TSX.Syntax.TypePredicate
, TSX.Syntax.CallSignature
, TSX.Syntax.ConstructSignature
, TSX.Syntax.ArrayType
, TSX.Syntax.LookupType
, TSX.Syntax.FlowMaybeType
, TSX.Syntax.TypeQuery
, TSX.Syntax.IndexTypeQuery
, TSX.Syntax.ThisType
, TSX.Syntax.ExistentialType
, TSX.Syntax.AbstractMethodSignature
, TSX.Syntax.IndexSignature
, TSX.Syntax.ObjectType
, TSX.Syntax.LiteralType
, TSX.Syntax.Union
, TSX.Syntax.Intersection
, TSX.Syntax.Module
, TSX.Syntax.InternalModule
, TSX.Syntax.FunctionType
, TSX.Syntax.Tuple
, TSX.Syntax.Constructor
, TSX.Syntax.TypeAssertion
, TSX.Syntax.ImportAlias
, TSX.Syntax.Debugger
, TSX.Syntax.ShorthandPropertyIdentifier
, TSX.Syntax.Super
, TSX.Syntax.Undefined
, TSX.Syntax.ClassHeritage
, TSX.Syntax.AbstractClass
, TSX.Syntax.ImplementsClause
, TSX.Syntax.JsxElement
, TSX.Syntax.JsxSelfClosingElement
, TSX.Syntax.JsxOpeningElement
, TSX.Syntax.JsxText
, TSX.Syntax.JsxClosingElement
, TSX.Syntax.JsxExpression
, TSX.Syntax.JsxAttribute
, TSX.Syntax.JsxFragment
, TSX.Syntax.JsxNamespaceName
, TSX.Syntax.OptionalParameter
, TSX.Syntax.RequiredParameter
, TSX.Syntax.RestParameter
, TSX.Syntax.PropertySignature
, TSX.Syntax.AmbientDeclaration
, TSX.Syntax.EnumDeclaration
, TSX.Syntax.ExtendsClause
, TSX.Syntax.AmbientFunction
, TSX.Syntax.ImportRequireClause
, TSX.Syntax.ImportClause
, TSX.Syntax.LabeledStatement
, TSX.Syntax.Annotation
, TSX.Syntax.With
, TSX.Syntax.ForOf
, TSX.Syntax.Update
, TSX.Syntax.ComputedPropertyName
, TSX.Syntax.Decorator
, TSX.Syntax.Import
, TSX.Syntax.QualifiedAliasedImport
, TSX.Syntax.SideEffectImport
, TSX.Syntax.DefaultExport
, TSX.Syntax.QualifiedExport
, TSX.Syntax.QualifiedExportFrom
, TSX.Syntax.JavaScriptRequire
, []
, Statement.StatementBlock
, TSX.Syntax.MetaProperty
, TSX.Syntax.AnnotatedExpression
]