Skip to content
Browse files

Merge pull request #8 from arvidj/issue/4-late-static-binding

Issue/4 late static binding
  • Loading branch information...
2 parents e437c29 + 10c07f5 commit 4e6d906336925b77fb840643d3d83c0b17794284 @dancor dancor committed
Showing with 14 additions and 7 deletions.
  1. +9 −3 src/Lang/Php/Ast/ExprParse.hs
  2. +4 −3 src/Lang/Php/Ast/ExprTypes.hs
  3. +1 −1 src/Lang/Php/Ast/StmtParse.hs
View
12 src/Lang/Php/Ast/ExprParse.hs
@@ -36,6 +36,8 @@ instance Unparse LRVal where
unparse e ++ tokRBracket
unparse (LRValMemb v (ws1, ws2) m) =
unparse v ++ unparse ws1 ++ tokArrow ++ unparse ws2 ++ unparse m
+ unparse (LRValStaMemb v (ws1, ws2) m) =
+ unparse v ++ unparse ws1 ++ tokDubColon ++ unparse ws2 ++ unparse m
instance Unparse LOnlyVal where
unparse (LOnlyValList w args) = tokList ++ unparse w ++ tokLParen ++
@@ -97,7 +99,7 @@ dynConstOrConstParser :: Parser (Either DynConst Const, WS)
dynConstOrConstParser = do
(statics, cOrD) <-
first (map (\ ((a, b), c) -> (a, (b, c)))) <$>
- parseABPairsUntilAOrC (liftM2 (,) identifierParser parse)
+ parseABPairsUntilAOrC (liftM2 (,) (tokStaticP <|> identifierParser) parse)
(tokDubColonP >> parse) parse
return $ case cOrD of
Left c -> first (Right . Const statics) c
@@ -175,10 +177,14 @@ valExtend v@(state, ws) = case state of
<|> return v
valExtendMemb :: RVal -> WS -> Parser (Val, WS)
-valExtendMemb a ws = tokArrowP >> do
+valExtendMemb a ws = (tokArrowP >> do
ws2 <- parse
(memb, wsEnd) <- parse
- valExtend (ValLRVal $ LRValMemb a (ws, ws2) memb, wsEnd)
+ valExtend (ValLRVal $ LRValMemb a (ws, ws2) memb, wsEnd))
+ <|> (tokDubColonP >> do
+ ws2 <- parse
+ (memb, wsEnd) <- parse
+ valExtend (ValLRVal $ LRValStaMemb a (ws, ws2) memb, wsEnd))
instance Parse (Memb, WS) where
parse =
View
7 src/Lang/Php/Ast/ExprTypes.hs
@@ -43,9 +43,10 @@ data DynConst = DynConst [(String, WS2)] Var -- "a::$a"
deriving (Eq, Show, Typeable, Data)
data LRVal =
- LRValVar DynConst |
- LRValInd RVal WS (WSCap Expr) | -- "$a->a[0]"
- LRValMemb RVal WS2 Memb -- $a->a
+ LRValVar DynConst |
+ LRValInd RVal WS (WSCap Expr) | -- "$a->a[0]"
+ LRValMemb RVal WS2 Memb | -- $a->a
+ LRValStaMemb RVal WS2 Memb -- $a::a
deriving (Eq, Show, Typeable, Data)
data LOnlyVal =
View
2 src/Lang/Php/Ast/StmtParse.hs
@@ -205,6 +205,7 @@ simpleStmtParser =
StmtDeclare <$> parse <|>
StmtDoWhile <$> parse <|>
liftM2 StmtEcho (tokEchoP >> sepBy1 parse tokCommaP) parse <|>
+ (try $ liftM2 StmtStatic (tokStaticP >> sepBy1 parse tokCommaP) parse) <|>
liftM2 (uncurry StmtExpr) parse parse <|>
StmtFuncDef <$> parse <|>
liftM2 StmtGlobal (tokGlobalP >> sepBy1 parse tokCommaP) parse <|>
@@ -213,7 +214,6 @@ simpleStmtParser =
StmtInterface <$> parse <|>
StmtNothing <$> parse <|>
liftM3 StmtReturn (tokReturnP >> parse) (optionMaybe parse) parse <|>
- liftM2 StmtStatic (tokStaticP >> sepBy1 parse tokCommaP) parse <|>
StmtSwitch <$> parse <|>
liftM2 StmtThrow (tokThrowP >> parse) parse <|>
liftM2 StmtUnset

0 comments on commit 4e6d906

Please sign in to comment.
Something went wrong with that request. Please try again.