git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #180 from garyb/master
1331d04Phil Freeman
docs/source/prelude.rst+3−3
@@ -52,7 +52,7 @@ Type Classes
52 (<$>) :: forall b. forall a. (a -> b) -> f a -> f b
52 (<$>) :: forall b. forall a. (a -> b) -> f a -> f b
53
53
54 class Monad m where
54 class Monad m where
55− $return :: forall a. a -> m a
55+ return :: forall a. a -> m a
56 (>>=) :: forall b. forall a. m a -> (a -> m b) -> m b
56 (>>=) :: forall b. forall a. m a -> (a -> m b) -> m b
57
57
58 class Num a where
58 class Num a where
@@ -119,8 +119,6 @@ Values
119
119
120::
120::
121
121
122− $const :: forall b. forall a. a -> b -> a
123−
124 (!!) :: forall a. [a] -> Prim.Number -> a
122 (!!) :: forall a. [a] -> Prim.Number -> a
125
123
126 (#) :: forall b. forall a. a -> (a -> b) -> b
124 (#) :: forall b. forall a. a -> (a -> b) -> b
@@ -135,6 +133,8 @@ Values
135
133
136 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
134 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
137
135
136+ const :: forall b. forall a. a -> b -> a
137+
138 flip :: forall c. forall b. forall a. (a -> b -> c) -> b -> a -> c
138 flip :: forall c. forall b. forall a. (a -> b -> c) -> b -> a -> c
139
139
140 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
140 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
examples/passing/Functions2.pursnew file+17
@@ -0,0 +1,17 @@
1+module Functions2 where
2+
3+ import Prelude
4+
5+ test :: forall a b. a -> b -> a
6+ test = \const _ -> const
7+
8+module Main where
9+
10+ import Prelude
11+ import Functions2
12+
13+ main = do
14+ let value = test "Done" {}
15+ if value == "Done"
16+ then Trace.trace "Done"
17+ else Errors.throwError "Not done"
examples/passing/JSReserved.purs+20−7
@@ -1,11 +1,11 @@
1−module Main where
1+module JSReserved where
2
2
3 import Prelude
3 import Prelude
4
4
5− yield = "test"
5+ yield = 0
6− member = "test"
6+ member = 1
7
7
8− fortest = {
8+ this = {
9 var function = 0;
9 var function = 0;
10 for (i <- 0 until 10) {
10 for (i <- 0 until 10) {
11 function = function + i;
11 function = function + i;
@@ -13,7 +13,7 @@ module Main where
13 return function;
13 return function;
14 }
14 }
15
15
16− whiletest = {
16+ catch = {
17 var for = 0;
17 var for = 0;
18 while (for > 0) {
18 while (for > 0) {
19 for = for - 1;
19 for = for - 1;
@@ -21,10 +21,23 @@ module Main where
21 return for;
21 return for;
22 }
22 }
23
23
24− vartest = {
24+ instanceof = {
25 var var = 1;
25 var var = 1;
26 var = var + 1;
26 var = var + 1;
27 return var;
27 return var;
28 }
28 }
29+
30+ public = \return -> return
31+
32+module Main where
33+
34+ import Prelude
35+ import Arrays
36+ import JSReserved
29
37
30− main = Trace.trace "Done"
38+ main = Trace.print [ yield
39+ , member
40+ , this
41+ , catch
42+ , instanceof
43+ , public 1 ]
examples/passing/Operators.purs+3
@@ -50,6 +50,8 @@ module Operators2 where
50 test11 = [1, 2, 3] ... [4, 5, 6]
50 test11 = [1, 2, 3] ... [4, 5, 6]
51
51
52 test12 (<%>) a b = a <%> b
52 test12 (<%>) a b = a <%> b
53+
54+ test13 = \(<%>) a b -> a <%> b
53
55
54module Main where
56module Main where
55
57
@@ -75,4 +77,5 @@ main =
75 , show test10
77 , show test10
76 , show test11
78 , show test11
77 , show (test12 k 1 2)
79 , show (test12 k 1 2)
80+ , show (test13 k 1 2)
78 ]
81 ]
libraries/prelude/README.md+3−3
@@ -44,7 +44,7 @@
44 (<$>) :: forall b. forall a. (a -> b) -> f a -> f b
44 (<$>) :: forall b. forall a. (a -> b) -> f a -> f b
45
45
46 class Monad m where
46 class Monad m where
47− $return :: forall a. a -> m a
47+ return :: forall a. a -> m a
48 (>>=) :: forall b. forall a. m a -> (a -> m b) -> m b
48 (>>=) :: forall b. forall a. m a -> (a -> m b) -> m b
49
49
50 class Num a where
50 class Num a where
@@ -107,8 +107,6 @@
107
107
108### Values
108### Values
109
109
110− $const :: forall b. forall a. a -> b -> a
111−
112 (!!) :: forall a. [a] -> Prim.Number -> a
110 (!!) :: forall a. [a] -> Prim.Number -> a
113
111
114 (#) :: forall b. forall a. a -> (a -> b) -> b
112 (#) :: forall b. forall a. a -> (a -> b) -> b
@@ -123,6 +121,8 @@
123
121
124 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
122 boolOr :: Prim.Boolean -> Prim.Boolean -> Prim.Boolean
125
123
124+ const :: forall b. forall a. a -> b -> a
125+
126 flip :: forall c. forall b. forall a. (a -> b -> c) -> b -> a -> c
126 flip :: forall c. forall b. forall a. (a -> b -> c) -> b -> a -> c
127
127
128 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
128 numAdd :: Prim.Number -> Prim.Number -> Prim.Number
src/Language/PureScript/CodeGen/Common.hs+74−2
@@ -21,15 +21,22 @@ import Language.PureScript.Names
21-- |
21-- |
22-- Convert an Ident into a valid Javascript identifier:
22-- Convert an Ident into a valid Javascript identifier:
23--
23--
24−-- * Alphanumeric characters are kept unmodified
24+-- * Alphanumeric characters are kept unmodified.
25--
25--
26+-- * Reserved javascript identifiers are prefixed with '$$'.
27+--
26−-- * Symbols are encoded as a dollar symbol ($) followed by their ordinal value
28+-- * Symbols are prefixed with '$' followed by a symbol name or their ordinal value.
27--
29--
28identToJs :: Ident -> String
30identToJs :: Ident -> String
31+identToJs (Ident name) | nameIsJsReserved name = "$$" ++ name
29identToJs (Ident name) = concatMap identCharToString name
32identToJs (Ident name) = concatMap identCharToString name
30identToJs (Op op) = concatMap identCharToString op
33identToJs (Op op) = concatMap identCharToString op
31identToJs (Escaped name) = name
34identToJs (Escaped name) = name
32
35
36+-- |
37+-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
38+-- ordinal value.
39+--
33identCharToString :: Char -> String
40identCharToString :: Char -> String
34identCharToString c | isAlphaNum c = [c]
41identCharToString c | isAlphaNum c = [c]
35identCharToString '_' = "_"
42identCharToString '_' = "_"
@@ -54,3 +61,68 @@ identCharToString '\\' = "$bslash"
54identCharToString '?' = "$qmark"
61identCharToString '?' = "$qmark"
55identCharToString '@' = "$at"
62identCharToString '@' = "$at"
56identCharToString c = '$' : show (ord c)
63identCharToString c = '$' : show (ord c)
64+
65+-- |
66+-- Checks whether an identifier name is reserved in Javascript.
67+--
68+nameIsJsReserved :: String -> Bool
69+nameIsJsReserved name =
70+ elem name [ "abstract"
71+ , "boolean"
72+ , "break"
73+ , "byte"
74+ , "case"
75+ , "catch"
76+ , "char"
77+ , "class"
78+ , "const"
79+ , "continue"
80+ , "debugger"
81+ , "default"
82+ , "delete"
83+ , "do"
84+ , "double"
85+ , "else"
86+ , "enum"
87+ , "export"
88+ , "extends"
89+ , "final"
90+ , "finally"
91+ , "float"
92+ , "for"
93+ , "function"
94+ , "goto"
95+ , "if"
96+ , "implements"
97+ , "import"
98+ , "in"
99+ , "instanceof"
100+ , "int"
101+ , "interface"
102+ , "let"
103+ , "long"
104+ , "native"
105+ , "new"
106+ , "package"
107+ , "private"
108+ , "protected"
109+ , "public"
110+ , "return"
111+ , "short"
112+ , "static"
113+ , "super"
114+ , "switch"
115+ , "synchronized"
116+ , "this"
117+ , "throw"
118+ , "throws"
119+ , "transient"
120+ , "try"
121+ , "typeof"
122+ , "var"
123+ , "void"
124+ , "volatile"
125+ , "while"
126+ , "with"
127+ , "yield" ]
128+
src/Language/PureScript/CodeGen/JS.hs+67−13
@@ -41,11 +41,12 @@ import Language.PureScript.Options
41import Language.PureScript.CodeGen.JS.AST as AST
41import Language.PureScript.CodeGen.JS.AST as AST
42import Language.PureScript.Types
42import Language.PureScript.Types
43import Language.PureScript.CodeGen.Optimize
43import Language.PureScript.CodeGen.Optimize
44−import Language.PureScript.CodeGen.Common (identToJs)
44+import Language.PureScript.CodeGen.Common
45import Language.PureScript.TypeChecker.Monad (canonicalizeDataConstructor)
45import Language.PureScript.TypeChecker.Monad (canonicalizeDataConstructor)
46
46
47-- |
47-- |
48−-- Generate code in the simplified Javascript intermediate representation for all declarations in a module
48+-- Generate code in the simplified Javascript intermediate representation for all declarations in a
49+-- module.
49--
50--
50moduleToJs :: Options -> Module -> Environment -> [JS]
51moduleToJs :: Options -> Module -> Environment -> [JS]
51moduleToJs opts (Module pname@(ProperName name) decls) env =
52moduleToJs opts (Module pname@(ProperName name) decls) env =
@@ -85,16 +86,36 @@ declToJs _ mp (ExternDeclaration importTy ident (Just js) _) _ =
85 Just $ js : setProperty ident (var ident) mp
86 Just $ js : setProperty ident (var ident) mp
86declToJs _ _ _ _ = Nothing
87declToJs _ _ _ _ = Nothing
87
88
89+-- |
90+-- Generate code in the simplified Javascript intermediate representation for setting the property
91+-- of an object.
92+--
88setProperty :: Ident -> JS -> ModuleName -> [JS]
93setProperty :: Ident -> JS -> ModuleName -> [JS]
89setProperty ident@(Op op) val (ModuleName (ProperName moduleName)) =
94setProperty ident@(Op op) val (ModuleName (ProperName moduleName)) =
90− [ JSAssignment (JSAccessor (identToJs ident) (JSVar moduleName)) val
95+ [ JSAssignment (accessor ident (JSVar moduleName)) val
91− , JSAssignment (JSIndexer (JSStringLiteral op) (JSVar moduleName)) (JSAccessor (identToJs ident) (JSVar moduleName)) ]
96+ , JSAssignment (JSIndexer (JSStringLiteral op) (JSVar moduleName)) (accessor ident (JSVar moduleName)) ]
92setProperty ident val (ModuleName (ProperName moduleName)) =
97setProperty ident val (ModuleName (ProperName moduleName)) =
93− [ JSAssignment (JSAccessor (identToJs ident) (JSVar moduleName)) val ]
98+ [ JSAssignment (accessor ident (JSVar moduleName)) val ]
94
99
100+-- |
101+-- Generate code in the simplified Javascript intermediate representation for a variable based on a
102+-- PureScript identifier.
103+--
95var :: Ident -> JS
104var :: Ident -> JS
96var = JSVar . identToJs
105var = JSVar . identToJs
97
106
107+-- |
108+-- Generate code in the simplified Javascript intermediate representation for an accessor based on
109+-- a PureScript identifier. If the name is not valid in Javascript (symbol based, reserved name) an
110+-- indexer is returned.
111+--
112+accessor :: Ident -> JS -> JS
113+accessor (Ident name) | nameIsJsReserved name = JSIndexer (JSStringLiteral name)
114+accessor ident = JSAccessor (identToJs ident)
115+
116+-- |
117+-- Generate code in the simplified Javascript intermediate representation for a value or expression.
118+--
98valueToJs :: Options -> ModuleName -> Environment -> Value -> JS
119valueToJs :: Options -> ModuleName -> Environment -> Value -> JS
99valueToJs _ _ _ (NumericLiteral n) = JSNumericLiteral n
120valueToJs _ _ _ (NumericLiteral n) = JSNumericLiteral n
100valueToJs _ _ _ (StringLiteral s) = JSStringLiteral s
121valueToJs _ _ _ (StringLiteral s) = JSStringLiteral s
@@ -104,21 +125,31 @@ valueToJs opts m e (ObjectLiteral ps) = JSObjectLiteral (map (second (valueToJs
104valueToJs opts m e (ObjectUpdate o ps) = JSApp (JSAccessor "extend" (JSVar "Object")) [ valueToJs opts m e o, JSObjectLiteral (map (second (valueToJs opts m e)) ps)]
125valueToJs opts m e (ObjectUpdate o ps) = JSApp (JSAccessor "extend" (JSVar "Object")) [ valueToJs opts m e o, JSObjectLiteral (map (second (valueToJs opts m e)) ps)]
105valueToJs _ m e (Constructor (Qualified Nothing name)) =
126valueToJs _ m e (Constructor (Qualified Nothing name)) =
106 case M.lookup (m, name) (dataConstructors e) of
127 case M.lookup (m, name) (dataConstructors e) of
107− Just (_, Alias aliasModule aliasIdent) -> qualifiedToJS identToJs (Qualified (Just aliasModule) aliasIdent)
128+ Just (_, Alias aliasModule aliasIdent) -> qualifiedToJS id (Qualified (Just aliasModule) aliasIdent)
108 _ -> JSVar . runProperName $ name
129 _ -> JSVar . runProperName $ name
109−valueToJs _ _ _ (Constructor name) = qualifiedToJS runProperName name
130+valueToJs _ _ _ (Constructor name) = qualifiedToJS (Ident . runProperName) name
110valueToJs opts m e (Block sts) = JSApp (JSFunction Nothing [] (JSBlock (map (statementToJs opts m e) sts))) []
131valueToJs opts m e (Block sts) = JSApp (JSFunction Nothing [] (JSBlock (map (statementToJs opts m e) sts))) []
111valueToJs opts m e (Case values binders) = bindersToJs opts m e binders (map (valueToJs opts m e) values)
132valueToJs opts m e (Case values binders) = bindersToJs opts m e binders (map (valueToJs opts m e) values)
112valueToJs opts m e (IfThenElse cond th el) = JSConditional (valueToJs opts m e cond) (valueToJs opts m e th) (valueToJs opts m e el)
133valueToJs opts m e (IfThenElse cond th el) = JSConditional (valueToJs opts m e cond) (valueToJs opts m e th) (valueToJs opts m e el)
113valueToJs opts m e (Accessor prop val) = JSAccessor prop (valueToJs opts m e val)
134valueToJs opts m e (Accessor prop val) = JSAccessor prop (valueToJs opts m e val)
114valueToJs opts m e (App val arg) = JSApp (valueToJs opts m e val) [valueToJs opts m e arg]
135valueToJs opts m e (App val arg) = JSApp (valueToJs opts m e val) [valueToJs opts m e arg]
115−valueToJs opts m e (Abs arg val) = JSFunction Nothing [identToJs arg] (JSBlock [JSReturn (valueToJs opts m e val)])
136+valueToJs opts m e (Abs arg val) = JSFunction Nothing [identToJs arg] (JSBlock [JSReturn (valueToJs opts m (bindName m arg e) val)])
116valueToJs opts m e (TypedValue _ (Abs arg val) ty) | optionsPerformRuntimeTypeChecks opts = let arg' = identToJs arg in JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn (valueToJs opts m e val)])
137valueToJs opts m e (TypedValue _ (Abs arg val) ty) | optionsPerformRuntimeTypeChecks opts = let arg' = identToJs arg in JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn (valueToJs opts m e val)])
117valueToJs _ m e (Var ident) = varToJs m e ident
138valueToJs _ m e (Var ident) = varToJs m e ident
118valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
139valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
119valueToJs _ _ _ (TypeClassDictionary _ _) = error "Type class dictionary was not replaced"
140valueToJs _ _ _ (TypeClassDictionary _ _) = error "Type class dictionary was not replaced"
120valueToJs _ _ _ _ = error "Invalid argument to valueToJs"
141valueToJs _ _ _ _ = error "Invalid argument to valueToJs"
121
142
143+-- |
144+-- Temporarily extends the environment to include a local variable name introduced by a lambda
145+-- abstraction.
146+--
147+bindName :: ModuleName -> Ident -> Environment -> Environment
148+bindName m ident env = env { names = M.insert (m, ident) (error "Temporary lambda variable type was read", LocalVariable) $ names env }
149+
150+-- |
151+-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
152+--
122runtimeTypeChecks :: String -> Type -> [JS]
153runtimeTypeChecks :: String -> Type -> [JS]
123runtimeTypeChecks arg ty =
154runtimeTypeChecks arg ty =
124 let
155 let
@@ -148,6 +179,10 @@ runtimeTypeChecks arg ty =
148 arrayCheck :: JS -> JS
179 arrayCheck :: JS -> JS
149 arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing
180 arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing
150
181
182+-- |
183+-- Generate code in the simplified Javascript intermediate representation for a reference to a
184+-- variable.
185+--
151varToJs :: ModuleName -> Environment -> Qualified Ident -> JS
186varToJs :: ModuleName -> Environment -> Qualified Ident -> JS
152varToJs m e qual@(Qualified _ ident) = go qual
187varToJs m e qual@(Qualified _ ident) = go qual
153 where
188 where
@@ -156,18 +191,25 @@ varToJs m e qual@(Qualified _ ident) = go qual
156 Just (_, Alias aliasModule aliasIdent) -> go (Qualified (Just aliasModule) aliasIdent)
191 Just (_, Alias aliasModule aliasIdent) -> go (Qualified (Just aliasModule) aliasIdent)
157 _ -> case qual of
192 _ -> case qual of
158 Qualified Nothing _ -> var ident
193 Qualified Nothing _ -> var ident
159− Qualified (Just (ModuleName (ProperName mn))) (Op op) -> JSIndexer (JSStringLiteral op) (JSVar mn)
160− _ -> qualifiedToJS identToJs qual
194+ _ -> qualifiedToJS id qual
161 isExtern (Extern ForeignImport) = True
195 isExtern (Extern ForeignImport) = True
162 isExtern (Alias m' ident') = case M.lookup (m', ident') (names e) of
196 isExtern (Alias m' ident') = case M.lookup (m', ident') (names e) of
163 Just (_, ty') -> isExtern ty'
197 Just (_, ty') -> isExtern ty'
164 Nothing -> error "Undefined alias in varToJs"
198 Nothing -> error "Undefined alias in varToJs"
165 isExtern _ = False
199 isExtern _ = False
166
200
201+-- |
202+-- Generate code in the simplified Javascript intermediate representation for a reference to a
203+-- variable that may have a qualified name.
204+--
167−qualifiedToJS :: (a -> String) -> Qualified a -> JS
205+qualifiedToJS :: (a -> Ident) -> Qualified a -> JS
168−qualifiedToJS f (Qualified (Just (ModuleName (ProperName m))) a) = JSAccessor (f a) (JSVar m)
206+qualifiedToJS f (Qualified (Just (ModuleName (ProperName m))) a) = accessor (f a) (JSVar m)
169−qualifiedToJS f (Qualified Nothing a) = JSVar (f a)
207+qualifiedToJS f (Qualified Nothing a) = JSVar $ identToJs (f a)
170
208
209+-- |
210+-- Generate code in the simplified Javascript intermediate representation for pattern match binders
211+-- and guards.
212+--
171bindersToJs :: Options -> ModuleName -> Environment -> [([Binder], Maybe Guard, Value)] -> [JS] -> JS
213bindersToJs :: Options -> ModuleName -> Environment -> [([Binder], Maybe Guard, Value)] -> [JS] -> JS
172bindersToJs opts m e binders vals = runGen (map identToJs (unusedNames (binders, vals))) $ do
214bindersToJs opts m e binders vals = runGen (map identToJs (unusedNames (binders, vals))) $ do
173 valNames <- replicateM (length vals) fresh
215 valNames <- replicateM (length vals) fresh
@@ -183,6 +225,10 @@ bindersToJs opts m e binders vals = runGen (map identToJs (unusedNames (binders,
183 binderToJs m e v done'' b
225 binderToJs m e v done'' b
184 go _ _ _ _ = error "Invalid arguments to bindersToJs"
226 go _ _ _ _ = error "Invalid arguments to bindersToJs"
185
227
228+-- |
229+-- Generate code in the simplified Javascript intermediate representation for a pattern match
230+-- binder.
231+--
186binderToJs :: ModuleName -> Environment -> String -> [JS] -> Binder -> Gen [JS]
232binderToJs :: ModuleName -> Environment -> String -> [JS] -> Binder -> Gen [JS]
187binderToJs _ _ _ done NullBinder = return done
233binderToJs _ _ _ done NullBinder = return done
188binderToJs _ _ varName done (StringBinder str) =
234binderToJs _ _ varName done (StringBinder str) =
@@ -246,6 +292,10 @@ binderToJs m e varName done (NamedBinder ident binder) = do
246 js <- binderToJs m e varName done binder
292 js <- binderToJs m e varName done binder
247 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : js)
293 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : js)
248
294
295+-- |
296+-- Checks whether a data constructor is the only constructor for that type, used to simplify the
297+-- check when generating code for binders.
298+--
249isOnlyConstructor :: ModuleName -> Environment -> Qualified ProperName -> Bool
299isOnlyConstructor :: ModuleName -> Environment -> Qualified ProperName -> Bool
250isOnlyConstructor m e ctor =
300isOnlyConstructor m e ctor =
251 let (ty, _) = fromMaybe (error "Data constructor not found") $ qualify m ctor `M.lookup` dataConstructors e
301 let (ty, _) = fromMaybe (error "Data constructor not found") $ qualify m ctor `M.lookup` dataConstructors e
@@ -258,6 +308,10 @@ isOnlyConstructor m e ctor =
258 typeConstructor (TypeApp ty _) = typeConstructor ty
308 typeConstructor (TypeApp ty _) = typeConstructor ty
259 typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn
309 typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn
260
310
311+-- |
312+-- Generate code in the simplified Javascript intermediate representation for a statement in a
313+-- PureScript block.
314+--
261statementToJs :: Options -> ModuleName -> Environment -> Statement -> JS
315statementToJs :: Options -> ModuleName -> Environment -> Statement -> JS
262statementToJs opts m e (VariableIntroduction ident value) = JSVariableIntroduction (identToJs ident) (Just (valueToJs opts m e value))
316statementToJs opts m e (VariableIntroduction ident value) = JSVariableIntroduction (identToJs ident) (Just (valueToJs opts m e value))
263statementToJs opts m e (Assignment target value) = JSAssignment (JSVar (identToJs target)) (valueToJs opts m e value)
317statementToJs opts m e (Assignment target value) = JSAssignment (JSVar (identToJs target)) (valueToJs opts m e value)
src/Language/PureScript/Parser/Common.hs+1−69
@@ -52,69 +52,6 @@ reservedPsNames = [ "data"
52
52
53 ]
53 ]
54
54
55−-- |
56−-- A list of javascript reserved identifiers
57−--
58−reservedJsNames :: [String]
59−reservedJsNames = [ "abstract"
60− , "boolean"
61− , "break"
62− , "byte"
63− , "case"
64− , "catch"
65− , "char"
66− , "class"
67− , "const"
68− , "continue"
69− , "debugger"
70− , "default"
71− , "delete"
72− , "do"
73− , "double"
74− , "else"
75− , "enum"
76− , "export"
77− , "extends"
78− , "final"
79− , "finally"
80− , "float"
81− , "for"
82− , "function"
83− , "goto"
84− , "if"
85− , "implements"
86− , "import"
87− , "in"
88− , "instanceof"
89− , "int"
90− , "interface"
91− , "let"
92− , "long"
93− , "native"
94− , "new"
95− , "package"
96− , "private"
97− , "protected"
98− , "public"
99− , "return"
100− , "short"
101− , "static"
102− , "super"
103− , "switch"
104− , "synchronized"
105− , "this"
106− , "throw"
107− , "throws"
108− , "transient"
109− , "try"
110− , "typeof"
111− , "var"
112− , "void"
113− , "volatile"
114− , "while"
115− , "with"
116− , "yield" ]
117−
118-- |
55-- |
119-- A list of reserved identifiers for types
56-- A list of reserved identifiers for types
120--
57--
@@ -287,12 +224,7 @@ integerOrFloat = (Left <$> P.try (PT.natural tokenParser) <|>
287-- Parse an identifier or parenthesized operator
224-- Parse an identifier or parenthesized operator
288--
225--
289parseIdent :: P.Parsec String ParseState Ident
226parseIdent :: P.Parsec String ParseState Ident
290−parseIdent = parseIdent' <|> (Op <$> parens operator)
227+parseIdent = (Ident <$> identifier) <|> (Op <$> parens operator)
291− where
292− parseIdent' :: P.Parsec String ParseState Ident
293− parseIdent' = do
294− ident <- identifier
295− return $ if (ident `elem` reservedJsNames) then (Escaped $ "$" ++ ident) else (Ident ident)
296
228
297-- |
229-- |
298-- Parse a token inside square brackets
230-- Parse a token inside square brackets