Skip to content

Instantly share code, notes, and snippets.

@aycanirican
Created August 9, 2010 12:46
Show Gist options
  • Select an option

  • Save aycanirican/515367 to your computer and use it in GitHub Desktop.

Select an option

Save aycanirican/515367 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies #-}
module JS.Syntax where
import qualified JS.Ann as A
type Expr a = A.Fix (Expression a)
type LVal a = A.Fix (LValue a)
type Stmt a = A.Fix (Statement a)
-- | Js Syntax
data Id a = Id a String deriving (Show,Eq,Ord)
-- http://developer.mozilla.org/en/docs/
-- Core_JavaScript_1.5_Reference:Operators:Operator_Precedence
data InfixOp = OpLT | OpLEq | OpGT | OpGEq | OpIn | OpInstanceof | OpEq | OpNEq
| OpStrictEq | OpStrictNEq | OpLAnd | OpLOr
| OpMul | OpDiv | OpMod | OpSub | OpLShift | OpSpRShift
| OpZfRShift | OpBAnd | OpBXor | OpBOr | OpAdd
deriving (Show,Eq,Ord,Enum)
data AssignOp = OpAssign | OpAssignAdd | OpAssignSub | OpAssignMul | OpAssignDiv
| OpAssignMod | OpAssignLShift | OpAssignSpRShift | OpAssignZfRShift
| OpAssignBAnd | OpAssignBXor | OpAssignBOr
deriving (Show,Eq,Ord)
data UnaryAssignOp
= PrefixInc | PrefixDec | PostfixInc | PostfixDec
deriving (Show, Eq, Ord)
data PrefixOp = PrefixLNot | PrefixBNot | PrefixPlus
| PrefixMinus | PrefixTypeof | PrefixVoid | PrefixDelete
deriving (Show,Eq,Ord)
data Prop a
= PropId a (Id a) | PropString a String | PropNum a Integer
data LValue a r
= LVar a String
| LDot a r String
| LBracket a r r
deriving (Show, Eq, Ord)
data Expression a r
= StringLit a String
| RegexpLit a String Bool {- global? -} Bool {- case-insensitive? -}
| NumLit a Double
| IntLit a Int
| BoolLit a Bool
| NullLit a
| ArrayLit a [r]
| ObjectLit a [(Prop a, r)]
| ThisRef a
| VarRef a (Id a)
| DotRef a r (Id a)
| BracketRef a r {- container -} r {- key -}
| NewExpr a r {- constructor -} [r]
| PrefixExpr a PrefixOp r
| UnaryAssignExpr a UnaryAssignOp (LValue a r)
| InfixExpr a InfixOp r r
| CondExpr a r r r
| AssignExpr a AssignOp (LValue a r) r
| ParenExpr a r
| ListExpr a [r]
| CallExpr a r [r]
| FuncExpr a [(Id a)] (Stmt a)
data CaseClause a
= CaseClause a (Expr a) [Stmt a]
| CaseDefault a [Stmt a]
data CatchClause a
= CatchClause a (Id a) (Stmt a)
data VarDecl a
= VarDecl a (Id a) (Maybe (Expr a))
data ForInit a
= NoInit
| VarInit [VarDecl a]
| ExprInit (Expr a)
data ForInInit a
= ForInVar (Id a)
| ForInNoVar (Id a)
deriving (Show,Eq,Ord)
data Statement a r
= BlockStmt a [r]
| EmptyStmt a
| ExprStmt a (Expr a)
| IfStmt a (Expr a) r r
| IfSingleStmt a (Expr a) r
| SwitchStmt a (Expr a) [CaseClause a]
| WhileStmt a (Expr a) r
| DoWhileStmt a r (Expr a)
| BreakStmt a (Maybe (Id a))
| ContinueStmt a (Maybe (Id a))
| LabelledStmt a (Id a) r
| ForInStmt a (ForInInit a) (Expr a) r
| ForStmt a (ForInit a)
(Maybe (Expr a)) -- increment
(Maybe (Expr a)) -- test
r -- body
| TryStmt a r {-body-} [CatchClause a] {-catches-}
(Maybe r) {-finally-}
| ThrowStmt a (Expr a)
| ReturnStmt a (Maybe (Expr a))
| WithStmt a (Expr a) r
| VarDeclStmt a [VarDecl a]
| FunctionStmt a (Id a) {-name-} [(Id a)] {-args-} r {-body-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment