From 6f185f7d0e4cfd45b2cf21f3469945b8858ee2e1 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 4 Oct 2017 11:27:27 -0700 Subject: [PATCH 1/5] ++haskell-tree-sitter --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index c9970d5fc..bdbdafe80 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit c9970d5fcccc0ffd3e1337304e6646f6c0730f5c +Subproject commit bdbdafe80096c9305e01563b7f6b110ea9674cb9 From 92d12ef455a6df1a6c93b85f875cb8610c039483 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 4 Oct 2017 12:28:33 -0700 Subject: [PATCH 2/5] ++haskell-tree-sitter --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index bdbdafe80..2f2cea06e 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit bdbdafe80096c9305e01563b7f6b110ea9674cb9 +Subproject commit 2f2cea06e6b1341304b0e8c43b1ac878fd9f2799 From d8f7f45fdb9aadd1bbadcbbb3340ececc58ce487 Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 4 Oct 2017 13:04:12 -0700 Subject: [PATCH 3/5] ++haskell-tree-sitter --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 2f2cea06e..4c1c8643a 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 2f2cea06e6b1341304b0e8c43b1ac878fd9f2799 +Subproject commit 4c1c8643aa1d5a3e0aee87effc2cc2529cb17535 From 48ff06cafe21b1c92c93deb41ff178cc532eadee Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 4 Oct 2017 13:25:34 -0700 Subject: [PATCH 4/5] Add decorator support --- src/Language/TypeScript/Syntax.hs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Language/TypeScript/Syntax.hs b/src/Language/TypeScript/Syntax.hs index 6ab69fdc0..1fbd48dd1 100644 --- a/src/Language/TypeScript/Syntax.hs +++ b/src/Language/TypeScript/Syntax.hs @@ -171,6 +171,7 @@ type Syntax = '[ , Language.TypeScript.Syntax.This , Language.TypeScript.Syntax.Update , Language.TypeScript.Syntax.ComputedPropertyName + , Language.TypeScript.Syntax.Decorator , [] ] @@ -269,6 +270,13 @@ instance Eq1 Annotation where liftEq = genericLiftEq instance Ord1 Annotation where liftCompare = genericLiftCompare instance Show1 Annotation where liftShowsPrec = genericLiftShowsPrec +newtype Decorator a = Decorator { _decoratorTerm :: a } + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 Decorator where liftEq = genericLiftEq +instance Ord1 Decorator where liftCompare = genericLiftCompare +instance Show1 Decorator where liftShowsPrec = genericLiftShowsPrec + newtype ComputedPropertyName a = ComputedPropertyName a deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) @@ -728,7 +736,7 @@ ternaryExpression :: Assignment ternaryExpression = makeTerm <$> symbol Grammar.TernaryExpression <*> children (Statement.If <$> expression <*> expression <*> expression) memberExpression :: Assignment -memberExpression = makeTerm <$> symbol Grammar.MemberExpression <*> children (Expression.MemberAccess <$> postContextualize comment expression <*> propertyIdentifier) +memberExpression = makeTerm <$> (symbol Grammar.MemberExpression <|> symbol Grammar.MemberExpression') <*> children (Expression.MemberAccess <$> postContextualize comment expression <*> propertyIdentifier) newExpression :: Assignment newExpression = makeTerm <$> symbol Grammar.NewExpression <*> children (Expression.New <$> expression) @@ -878,7 +886,10 @@ methodSignature = makeMethodSignature <$> symbol Grammar.MethodSignature <*> chi where makeMethodSignature loc (modifier, readonly, propertyName, (typeParams, params, annotation)) = makeTerm loc (Language.TypeScript.Syntax.MethodSignature [modifier, readonly, typeParams, annotation] propertyName params) formalParameters :: HasCallStack => Assignment.Assignment [] Grammar [Term] -formalParameters = symbol FormalParameters *> children (many (term parameter)) +formalParameters = symbol FormalParameters *> children ((++) <$> many (term decorator) <*> many (term parameter)) + +decorator :: Assignment +decorator = makeTerm <$> symbol Grammar.Decorator <*> children (Language.TypeScript.Syntax.Decorator <$> (identifier <|> memberExpression <|> callExpression)) typeParameters :: Assignment typeParameters = makeTerm <$> symbol TypeParameters <*> children (Type.TypeParameters <$> many (term typeParameter')) @@ -1093,7 +1104,7 @@ ambientDeclaration :: Assignment ambientDeclaration = makeTerm <$> symbol Grammar.AmbientDeclaration <*> children (Language.TypeScript.Syntax.AmbientDeclaration <$> choice [declaration, statementBlock]) exportStatement :: Assignment -exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (Language.TypeScript.Syntax.Export <$> (((\a b -> [a, b]) <$> exportClause <*> fromClause) <|> (pure <$> (fromClause <|> exportClause <|> declaration <|> expression <|> identifier <|> importAlias')))) +exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (Language.TypeScript.Syntax.Export <$> (((\a b -> [a, b]) <$> exportClause <*> fromClause) <|> ((++) <$> many decorator <*> (pure <$> (fromClause <|> exportClause <|> declaration <|> expression <|> identifier <|> importAlias'))))) fromClause :: Assignment fromClause = string @@ -1181,7 +1192,7 @@ pair :: Assignment pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> propertyName <*> expression) callExpression :: Assignment -callExpression = makeCall <$> symbol CallExpression <*> children ((,,,) <$> (expression <|> super <|> function) <*> (typeArguments <|> pure []) <*> (arguments <|> (pure <$> templateString)) <*> emptyTerm) +callExpression = makeCall <$> (symbol CallExpression <|> symbol CallExpression') <*> children ((,,,) <$> (expression <|> super <|> function) <*> (typeArguments <|> pure []) <*> (arguments <|> (pure <$> templateString)) <*> emptyTerm) where makeCall loc (subject, typeArgs, args, body) = makeTerm loc (Expression.Call typeArgs subject args body) arguments = symbol Arguments *> children (many (term (expression <|> spreadElement))) typeArguments = symbol Grammar.TypeArguments *> children (some (term ty)) From 973d13618805f26076d8b427117fa04cbbadfb7a Mon Sep 17 00:00:00 2001 From: joshvera Date: Wed, 4 Oct 2017 14:29:36 -0700 Subject: [PATCH 5/5] one or more decorators --- src/Language/TypeScript/Syntax.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Language/TypeScript/Syntax.hs b/src/Language/TypeScript/Syntax.hs index 1fbd48dd1..0aee0eca9 100644 --- a/src/Language/TypeScript/Syntax.hs +++ b/src/Language/TypeScript/Syntax.hs @@ -808,8 +808,8 @@ identifier :: Assignment identifier = (makeTerm <$> symbol Identifier' <*> (Syntax.Identifier <$> source)) <|> (makeTerm <$> symbol Identifier <*> (Syntax.Identifier <$> source)) class' :: Assignment -class' = makeClass <$> symbol Class <*> children ((,,,) <$> identifier <*> ((symbol TypeParameters *> children (many (term typeParameter'))) <|> pure []) <*> (classHeritage' <|> pure []) <*> classBodyStatements) - where makeClass loc (expression, typeParams, classHeritage, statements) = makeTerm loc (Declaration.Class typeParams expression classHeritage statements) +class' = makeClass <$> symbol Class <*> children ((,,,,) <$> many (term decorator) <*> identifier <*> ((symbol TypeParameters *> children (many (term typeParameter'))) <|> pure []) <*> (classHeritage' <|> pure []) <*> classBodyStatements) + where makeClass loc (decorators, expression, typeParams, classHeritage, statements) = makeTerm loc (Declaration.Class (decorators ++ typeParams) expression classHeritage statements) object :: Assignment object = (makeTerm <$> (symbol Object <|> symbol ObjectPattern) <*> children (Literal.Hash <$> many (term ((pair <|> spreadElement <|> methodDefinition <|> assignmentPattern <|> shorthandPropertyIdentifier))))) @@ -886,7 +886,7 @@ methodSignature = makeMethodSignature <$> symbol Grammar.MethodSignature <*> chi where makeMethodSignature loc (modifier, readonly, propertyName, (typeParams, params, annotation)) = makeTerm loc (Language.TypeScript.Syntax.MethodSignature [modifier, readonly, typeParams, annotation] propertyName params) formalParameters :: HasCallStack => Assignment.Assignment [] Grammar [Term] -formalParameters = symbol FormalParameters *> children ((++) <$> many (term decorator) <*> many (term parameter)) +formalParameters = symbol FormalParameters *> children (concat <$> many ((\as b -> as ++ [b]) <$> many (term decorator) <*> term parameter)) decorator :: Assignment decorator = makeTerm <$> symbol Grammar.Decorator <*> children (Language.TypeScript.Syntax.Decorator <$> (identifier <|> memberExpression <|> callExpression)) @@ -984,7 +984,7 @@ statementBlock :: Assignment statementBlock = makeTerm <$> symbol StatementBlock <*> children (many statement) classBodyStatements :: HasCallStack => Assignment.Assignment [] Grammar [Term] -classBodyStatements = symbol ClassBody *> children (many (term (methodDefinition <|> publicFieldDefinition <|> methodSignature <|> indexSignature))) +classBodyStatements = symbol ClassBody *> children (concat <$> many ((\as b -> as ++ [b]) <$> many (term decorator) <*> term (methodDefinition <|> publicFieldDefinition <|> methodSignature <|> indexSignature))) publicFieldDefinition :: Assignment publicFieldDefinition = makeField <$> symbol Grammar.PublicFieldDefinition <*> children ((,,,,) <$> (accessibilityModifier' <|> emptyTerm) <*> (readonly' <|> emptyTerm) <*> propertyName <*> (typeAnnotation' <|> emptyTerm) <*> (expression <|> emptyTerm)) @@ -1104,7 +1104,7 @@ ambientDeclaration :: Assignment ambientDeclaration = makeTerm <$> symbol Grammar.AmbientDeclaration <*> children (Language.TypeScript.Syntax.AmbientDeclaration <$> choice [declaration, statementBlock]) exportStatement :: Assignment -exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (Language.TypeScript.Syntax.Export <$> (((\a b -> [a, b]) <$> exportClause <*> fromClause) <|> ((++) <$> many decorator <*> (pure <$> (fromClause <|> exportClause <|> declaration <|> expression <|> identifier <|> importAlias'))))) +exportStatement = makeTerm <$> symbol Grammar.ExportStatement <*> children (Language.TypeScript.Syntax.Export <$> (((\a b -> [a, b]) <$> exportClause <*> fromClause) <|> ((++) <$> many (term decorator) <*> (pure <$> (fromClause <|> exportClause <|> declaration <|> expression <|> identifier <|> importAlias'))))) fromClause :: Assignment fromClause = string