From c2ccf00aa28f56a2cd139383016b080c37e4482e Mon Sep 17 00:00:00 2001 From: joshvera Date: Fri, 15 Dec 2017 16:10:30 -0800 Subject: [PATCH] Add assignment, variable declaration, identifier, and variable name --- src/Language/PHP/Assignment.hs | 50 +++++++++++++++++++++++++++++++++- src/Language/PHP/Syntax.hs | 8 ++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index b1b5528a0..4d2ce02ba 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -31,6 +31,10 @@ type Syntax = '[ , Syntax.Context , Syntax.Program , Syntax.Text + , Statement.Assignment + , Declaration.VariableDeclaration + , Syntax.Identifier + , Syntax.VariableName , [] ] type Term = Term.Term (Data.Union.Union Syntax) (Record Location) @@ -50,7 +54,51 @@ text = makeTerm <$> symbol Text <*> (Syntax.Text <$> source) statement :: Assignment statement = handleError everything - where everything = choice [ string ] + where + everything = choice [ + -- compoundStatement + -- , namedLabelStatement + -- , expressionStatement + -- , selectionStatement + -- , jumpStatement + -- , tryStatement + -- , declareStatement + -- , echoStatement + -- , constDeclaration + -- , functionDefinition + -- , classDeclaration + -- , interfaceDeclaration + -- , traitDeclaration + -- , namespaceDefinition + -- , namespaceUseDeclaration + -- , globalDeclaration + functionStaticDeclaration + ] + +expression :: Assignment +expression = choice [ + -- assignmentExpression, + -- yieldExpression, + -- unaryExpression, + -- binaryExpression, + -- includeExpression, + -- includeOnceExpression, + -- requireExpression, + -- requireOnceExpression + ] + +-- TODO: Does this keep the range of VariableName? +variableName :: Assignment +variableName = makeTerm <$> symbol VariableName <*> children (Syntax.VariableName <$> name) + +name :: Assignment +name = makeTerm <$> symbol Name <*> (Syntax.Identifier <$> source) + +functionStaticDeclaration :: Assignment +functionStaticDeclaration = makeTerm <$> symbol FunctionStaticDeclaration <*> children (Declaration.VariableDeclaration . pure <$> staticVariableDeclaration) + +staticVariableDeclaration :: Assignment +staticVariableDeclaration = makeTerm <$> symbol StaticVariableDeclaration <*> children (Statement.Assignment <$> pure [] <*> variableName <*> (expression <|> emptyTerm)) comment :: Assignment comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source) diff --git a/src/Language/PHP/Syntax.hs b/src/Language/PHP/Syntax.hs index 02cc02433..66973702a 100644 --- a/src/Language/PHP/Syntax.hs +++ b/src/Language/PHP/Syntax.hs @@ -15,3 +15,11 @@ newtype Text a = Text ByteString instance Eq1 Text where liftEq = genericLiftEq instance Ord1 Text where liftCompare = genericLiftCompare instance Show1 Text where liftShowsPrec = genericLiftShowsPrec + +-- | Lookup type for a type-level key in a typescript map. +data VariableName a = VariableName a + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 VariableName where liftEq = genericLiftEq +instance Ord1 VariableName where liftCompare = genericLiftCompare +instance Show1 VariableName where liftShowsPrec = genericLiftShowsPrec