From 8728b28761718fd686b105e68c856aa3e0d91a26 Mon Sep 17 00:00:00 2001 From: joshvera Date: Fri, 15 Dec 2017 16:46:46 -0800 Subject: [PATCH] Add global declaration and simple variable --- src/Language/PHP/Assignment.hs | 13 +++++++++++-- src/Language/PHP/Syntax.hs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index 95a6425b2..ca48f7349 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -40,6 +40,8 @@ type Syntax = '[ , Syntax.RequireOnce , Syntax.Require , Statement.Yield + , Syntax.SimpleVariable + , Syntax.GlobalDeclaration , Syntax.ArrayElement , [] ] @@ -77,8 +79,8 @@ statement = handleError everything -- , traitDeclaration -- , namespaceDefinition -- , namespaceUseDeclaration - -- , globalDeclaration - functionStaticDeclaration + globalDeclaration + , functionStaticDeclaration ] expression :: Assignment @@ -93,6 +95,13 @@ expression = choice [ requireOnceExpression ] +globalDeclaration :: Assignment +globalDeclaration = makeTerm <$> symbol GlobalDeclaration <*> children (Syntax.GlobalDeclaration <$> manyTerm simpleVariable) + +simpleVariable :: Assignment +simpleVariable = makeTerm <$> symbol SimpleVariable <*> children (Syntax.SimpleVariable <$> (variableName <|> simpleVariable <|> expression)) + + yieldExpression :: Assignment yieldExpression = makeTerm <$> symbol YieldExpression <*> children (Statement.Yield <$> (arrayElementInitializer <|> expression)) diff --git a/src/Language/PHP/Syntax.hs b/src/Language/PHP/Syntax.hs index 9c7121daa..696603e07 100644 --- a/src/Language/PHP/Syntax.hs +++ b/src/Language/PHP/Syntax.hs @@ -56,3 +56,17 @@ newtype ArrayElement a = ArrayElement a instance Eq1 ArrayElement where liftEq = genericLiftEq instance Ord1 ArrayElement where liftCompare = genericLiftCompare instance Show1 ArrayElement where liftShowsPrec = genericLiftShowsPrec + +newtype GlobalDeclaration a = GlobalDeclaration [a] + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 GlobalDeclaration where liftEq = genericLiftEq +instance Ord1 GlobalDeclaration where liftCompare = genericLiftCompare +instance Show1 GlobalDeclaration where liftShowsPrec = genericLiftShowsPrec + +newtype SimpleVariable a = SimpleVariable a + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 SimpleVariable where liftEq = genericLiftEq +instance Ord1 SimpleVariable where liftCompare = genericLiftCompare +instance Show1 SimpleVariable where liftShowsPrec = genericLiftShowsPrec