From 35b49454cdc6a1f08d7d3f2960a1f31ffd3f003d Mon Sep 17 00:00:00 2001 From: joshvera Date: Fri, 15 Dec 2017 16:12:40 -0800 Subject: [PATCH] Add require once --- src/Language/PHP/Assignment.hs | 7 +++++-- src/Language/PHP/Syntax.hs | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index 4d2ce02ba..09e2655c4 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -35,6 +35,7 @@ type Syntax = '[ , Declaration.VariableDeclaration , Syntax.Identifier , Syntax.VariableName + , Syntax.RequireOnce , [] ] type Term = Term.Term (Data.Union.Union Syntax) (Record Location) @@ -84,10 +85,12 @@ expression = choice [ -- includeExpression, -- includeOnceExpression, -- requireExpression, - -- requireOnceExpression + requireOnceExpression ] --- TODO: Does this keep the range of VariableName? +requireOnceExpression :: Assignment +requireOnceExpression = makeTerm <$> symbol RequireOnceExpression <*> children (Syntax.RequireOnce <$> expression) + variableName :: Assignment variableName = makeTerm <$> symbol VariableName <*> children (Syntax.VariableName <$> name) diff --git a/src/Language/PHP/Syntax.hs b/src/Language/PHP/Syntax.hs index 66973702a..29f101ecd 100644 --- a/src/Language/PHP/Syntax.hs +++ b/src/Language/PHP/Syntax.hs @@ -8,7 +8,6 @@ import Data.Functor.Classes.Generic import Data.Mergeable import GHC.Generics --- | Lookup type for a type-level key in a typescript map. newtype Text a = Text ByteString deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) @@ -16,10 +15,16 @@ 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 +newtype 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 + +newtype RequireOnce a = RequireOnce a + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable) + +instance Eq1 RequireOnce where liftEq = genericLiftEq +instance Ord1 RequireOnce where liftCompare = genericLiftCompare +instance Show1 RequireOnce where liftShowsPrec = genericLiftShowsPrec