From 0f1ee09d6903b11c0bbb229660f93762cd74da62 Mon Sep 17 00:00:00 2001 From: joshvera Date: Tue, 26 Dec 2017 15:24:34 -0500 Subject: [PATCH] Add variable and member access expressions --- src/Language/PHP/Assignment.hs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index c443432e3..33d9c16be 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -75,6 +75,7 @@ type Syntax = '[ , Declaration.Function , Expression.New , Literal.Array + , Expression.MemberAccess , [] ] type Term = Term.Term (Data.Union.Union Syntax) (Record Location) @@ -149,7 +150,7 @@ cloneExpression = makeTerm <$> symbol CloneExpression <*> children (Syntax.Clone primaryExpression :: Assignment primaryExpression = choice [ - -- variable, + variable, -- classConstantAccessExpression, qualifiedName, literal, @@ -162,6 +163,32 @@ primaryExpression = choice [ expression ] +variable :: Assignment +variable = callableVariable <|> scopedPropertyAccessExpression <|> memberAccessExpression + +callableVariable :: Assignment +callableVariable = simpleVariable + -- subscriptExpression, + -- memberCallExpression, + -- scopedCallExpression, + -- functionCallExpression + +memberAccessExpression :: Assignment +memberAccessExpression = makeTerm <$> symbol MemberAccessExpression <*> children (Expression.MemberAccess <$> dereferencableExpression <*> memberName) + +dereferencableExpression :: Assignment +dereferencableExpression = symbol DereferencableExpression *> children (variable <|> expression <|> arrayCreationExpression <|> string) + +scopedPropertyAccessExpression :: Assignment +scopedPropertyAccessExpression = makeTerm <$> symbol ScopedPropertyAccessExpression <*> children (Expression.MemberAccess <$> scopeResolutionQualifier <*> simpleVariable) + +scopeResolutionQualifier :: Assignment +scopeResolutionQualifier = choice [ + relativeScope, + qualifiedName, + dereferencableExpression + ] + arrayCreationExpression :: Assignment arrayCreationExpression = makeTerm <$> symbol ArrayCreationExpression <*> children (Literal.Array <$> manyTerm arrayElementInitializer)