summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreyChudnov <>2013-05-03 21:27:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2013-05-03 21:27:00 (GMT)
commit720ebc4cb5e3bbeec357ed43a968ba9c84ddad09 (patch)
treeb7d9a3c1b7a66774dc83407e05a6dad87d2d9cd9
parent91ea23cf566b75a73841ae6d42c871bbae823c1e (diff)
version 0.120.12
-rw-r--r--CHANGELOG8
-rw-r--r--language-ecmascript.cabal6
-rw-r--r--src/Language/ECMAScript3/Syntax/Annotations.hs67
3 files changed, 76 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 85f051a..a4f0798 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,7 +1,11 @@
Version change log.
+=0.12=
+Added a 'setAnnotation' function to the 'HasAnnotation' class. Added
+a 'withAnnotation' helper function to modify the top level annotation.
+
=0.11.1=
-Fixed binary operator precedence in the parser. See
+Fixed binary operator precedence in the parser.
=0.11=
Added a simple quasi-quoter for ECMAScript (see
@@ -15,6 +19,6 @@ precedence. Added a (beta quality) arbitrary instance for all the
AST's to generate random JavaScript programs (useful for testing).
-=0.9.1=
+=0.9.1=
Increased the upper bound on data-default in dependencies. See
https://github.com/jswebtools/language-ecmascript/pull/5
diff --git a/language-ecmascript.cabal b/language-ecmascript.cabal
index cd0870a..82c89ef 100644
--- a/language-ecmascript.cabal
+++ b/language-ecmascript.cabal
@@ -1,8 +1,8 @@
Name: language-ecmascript
-Version: 0.11.1
+Version: 0.12
Cabal-Version: >= 1.10
Copyright: (c) 2007-2012 Brown University, (c) 2008-2010 Claudiu Saftoiu,
- (c) 2012 Stevens Institute of Technology
+ (c) 2012-2013 Stevens Institute of Technology
License: BSD3
License-file: LICENSE
Author: Andrey Chudnov, Arjun Guha, Spiridon Aristides Eliopoulos,
@@ -30,7 +30,7 @@ Source-repository head
Source-repository this
type: git
location: git://github.com/jswebtools/language-ecmascript.git
- tag: 0.11.1
+ tag: 0.12
Library
Hs-Source-Dirs:
diff --git a/src/Language/ECMAScript3/Syntax/Annotations.hs b/src/Language/ECMAScript3/Syntax/Annotations.hs
index bacc9b9..2b34320 100644
--- a/src/Language/ECMAScript3/Syntax/Annotations.hs
+++ b/src/Language/ECMAScript3/Syntax/Annotations.hs
@@ -40,9 +40,17 @@ assignUniqueIds first tree =
put (i+1)
return (a, i)
+-- | Things that have annotations -- for example, nodes in a syntax
+-- tree
class HasAnnotation a where
-- | Returns the annotation of the root of the tree
getAnnotation :: a b -> b
+ -- | Sets the annotation of the root of the tree
+ setAnnotation :: b -> a b -> a b
+
+-- | Modify the annotation of the root node of the syntax tree
+withAnnotation :: (HasAnnotation a) => (b -> b) -> a b -> a b
+withAnnotation f x = setAnnotation (f $ getAnnotation x) x
instance HasAnnotation Expression where
getAnnotation e = case e of
@@ -67,6 +75,28 @@ instance HasAnnotation Expression where
(ListExpr a es) -> a
(CallExpr a fn params) -> a
(FuncExpr a mid args s) -> a
+ setAnnotation a e = case e of
+ (StringLit _ s) -> (StringLit a s)
+ (RegexpLit _ s g ci) -> (RegexpLit a s g ci)
+ (NumLit _ d) -> (NumLit a d)
+ (IntLit _ i) -> (IntLit a i)
+ (BoolLit _ b) -> (BoolLit a b)
+ (NullLit _) -> (NullLit a)
+ (ArrayLit _ exps) -> (ArrayLit a exps)
+ (ObjectLit _ props) -> (ObjectLit a props)
+ (ThisRef _) -> (ThisRef a)
+ (VarRef _ id) -> (VarRef a id)
+ (DotRef _ exp id) -> (DotRef a exp id)
+ (BracketRef _ container key) -> (BracketRef a container key)
+ (NewExpr _ ctor params) -> (NewExpr a ctor params)
+ (PrefixExpr _ op e) -> (PrefixExpr a op e)
+ (UnaryAssignExpr _ op lv) -> (UnaryAssignExpr a op lv)
+ (InfixExpr _ op e1 e2) -> (InfixExpr a op e1 e2)
+ (CondExpr _ g et ef) -> (CondExpr a g et ef)
+ (AssignExpr _ op lv e) -> (AssignExpr a op lv e)
+ (ListExpr _ es) -> (ListExpr a es)
+ (CallExpr _ fn params) -> (CallExpr a fn params)
+ (FuncExpr _ mid args s) -> (FuncExpr a mid args s)
instance HasAnnotation Statement where
getAnnotation s = case s of
@@ -89,26 +119,63 @@ instance HasAnnotation Statement where
WithStmt a _ _ -> a
VarDeclStmt a _ -> a
FunctionStmt a _ _ _ -> a
+ setAnnotation a s = case s of
+ BlockStmt _ ss -> BlockStmt a ss
+ EmptyStmt _ -> EmptyStmt a
+ ExprStmt _ e -> ExprStmt a e
+ IfStmt _ g t e -> IfStmt a g t e
+ IfSingleStmt _ g t -> IfSingleStmt a g t
+ SwitchStmt _ g cs -> SwitchStmt a g cs
+ WhileStmt _ g ss -> WhileStmt a g ss
+ DoWhileStmt _ ss g -> DoWhileStmt a ss g
+ BreakStmt _ l -> BreakStmt a l
+ ContinueStmt _ l -> ContinueStmt a l
+ LabelledStmt _ l s -> LabelledStmt a l s
+ ForInStmt _ i o ss -> ForInStmt a i o ss
+ ForStmt _ i t inc ss -> ForStmt a i t inc ss
+ TryStmt _ tb mcb mfb -> TryStmt a tb mcb mfb
+ ThrowStmt _ e -> ThrowStmt a e
+ ReturnStmt _ e -> ReturnStmt a e
+ WithStmt _ o b -> WithStmt a o b
+ VarDeclStmt _ vds -> VarDeclStmt a vds
+ FunctionStmt _ n as b-> FunctionStmt a n as b
instance HasAnnotation LValue where
getAnnotation lv = case lv of
LVar a _ -> a
LDot a _ _ -> a
LBracket a _ _ -> a
+ setAnnotation a lv = case lv of
+ LVar _ n -> LVar a n
+ LDot _ o f -> LDot a o f
+ LBracket a o fe -> LBracket a o fe
instance HasAnnotation VarDecl where
getAnnotation (VarDecl a _ _) = a
+ setAnnotation a (VarDecl _ vn e) = VarDecl a vn e
instance HasAnnotation Prop where
getAnnotation p = case p of
PropId a _ -> a
PropString a _ -> a
PropNum a _ -> a
+ setAnnotation a p = case p of
+ PropId _ id -> PropId a id
+ PropString _ s -> PropString a s
+ PropNum _ n -> PropNum a n
instance HasAnnotation CaseClause where
getAnnotation c = case c of
CaseClause a _ _ -> a
CaseDefault a _ -> a
+ setAnnotation a c = case c of
+ CaseClause _ e b -> CaseClause a e b
+ CaseDefault _ b -> CaseDefault a b
instance HasAnnotation CatchClause where
getAnnotation (CatchClause a _ _) = a
+ setAnnotation a (CatchClause _ id b) = CatchClause a id b
+
+instance HasAnnotation Id where
+ getAnnotation (Id a _) = a
+ setAnnotation a (Id _ s) = Id a s