{-# OPTIONS_HADDOCK hide #-} {-# LANGUAGE CPP #-} {-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE UndecidableInstances #-} module Cubix.Language.JavaScript.Parametric.Common.Types where #ifndef ONLY_ONE_LANGUAGE import Data.List ( (\\) ) import Language.Haskell.TH ( mkName ) import Data.Comp.Multi ( Term, project', project, HFunctor, (:-<:), All, CxtS, AnnCxtS ) import Data.Comp.Trans ( runCompTrans, makeSumType ) import Cubix.Language.Info import Cubix.Language.JavaScript.Parametric.Full.Types as JS import Cubix.Language.Parametric.Derive import Cubix.Language.Parametric.InjF import Cubix.Language.Parametric.Syntax as P ----------------------------------------------------------------------------------- --------------- Variable declarations and blocks ------------------------ ----------------------------------------------------------------------------------- -- Biggest gotcha of JavaScript: Scopes are weird. See -- https://gist.github.com/jkoppel/3f65e316ec921a90ee5228f771da4a5d for an -- example of why. The big thing to know is that only new functions introduce -- scopes, and a variable is local if it is in a "var" decl anywhere within the scope, -- regardless of where that declaration is. Hence, the common "Block" fragment -- does not model general JS blocks, but does model function bodies -- -- The JS library we're using lets you put arbitrary expressions as LHSs. JS does not. -- I don't like this. -- -- Also note that it has separate "JSAssignStatement" and "JSAssign" (expression) constructors. -- It seems to somewhat arbitrarily parse an assign as either an AssignStatement or as an ExpressionStatement. -- The official grammar only has the latter. As an exception to my "isomorphism" rule, I am going to convert all such things -- to the latter because that's what they should have been in the first place. (Also, strictly speaking, it's still isomorphic -- to the original tree; it's just that the grammar's redundant) -- createSortInclusionTypes [ ''P.IdentL, ''JSExpressionL, ''JSExpressionL, ''P.MultiLocalVarDeclL, ''JSExpressionL, ''JSExpressionL, ''JSAssignOpL, ''P.AssignL, ''P.BlockL, ''JSStatementL, ''JSBlockL ] [ ''JSExpressionL, ''P.LocalVarInitL, ''P.VarDeclBinderL, ''JSStatementL, ''P.RhsL, ''P.LhsL, ''P.AssignOpL, ''JSExpressionL, ''JSStatementL, ''P.BlockItemL, ''JSASTL ]