git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove Javascript parser
20505a8Phil Freeman
purescript.cabal−1
@@ -49,7 +49,6 @@ library
49 Language.PureScript.Parser.State
49 Language.PureScript.Parser.State
50 Language.PureScript.Parser.Types
50 Language.PureScript.Parser.Types
51 Language.PureScript.Parser.Values
51 Language.PureScript.Parser.Values
52− Language.PureScript.Parser.JS
53 Language.PureScript.Pretty
52 Language.PureScript.Pretty
54 Language.PureScript.Pretty.Common
53 Language.PureScript.Pretty.Common
55 Language.PureScript.Pretty.JS
54 Language.PureScript.Pretty.JS
src/Language/PureScript/Parser/Declarations.hs+1−4
@@ -31,7 +31,6 @@ import Language.PureScript.Declarations
31import Language.PureScript.Parser.Values
31import Language.PureScript.Parser.Values
32import Language.PureScript.Parser.Types
32import Language.PureScript.Parser.Types
33import Language.PureScript.Parser.Kinds
33import Language.PureScript.Parser.Kinds
34−import Language.PureScript.Parser.JS
35import Language.PureScript.CodeGen.JS.AST
34import Language.PureScript.CodeGen.JS.AST
36import Language.PureScript.Values
35import Language.PureScript.Values
37
36
@@ -67,11 +66,9 @@ parseExternDeclaration = P.try (reserved "foreign") *> indented *> (reserved "im
67 (ExternDataDeclaration <$> (P.try (reserved "data") *> indented *> properName)
66 (ExternDataDeclaration <$> (P.try (reserved "data") *> indented *> properName)
68 <*> (lexeme (indented *> P.string "::") *> parseKind)
67 <*> (lexeme (indented *> P.string "::") *> parseKind)
69 <|> do ident <- parseIdent
68 <|> do ident <- parseIdent
70− js <- P.optionMaybe (parseJSLiteral <$> stringLiteral)
69+ js <- P.optionMaybe (JSRaw <$> stringLiteral)
71 ty <- (lexeme (indented *> P.string "::") *> parsePolyType)
70 ty <- (lexeme (indented *> P.string "::") *> parsePolyType)
72 return $ ExternDeclaration (if isJust js then InlineJavascript else ForeignImport) ident js ty)
71 return $ ExternDeclaration (if isJust js then InlineJavascript else ForeignImport) ident js ty)
73−parseJSLiteral :: String -> JS
74−parseJSLiteral s = either (const $ JSRaw s) id $ P.runParser parseJS () "Javascript" s
75
72
76parseAssociativity :: P.Parsec String ParseState Associativity
73parseAssociativity :: P.Parsec String ParseState Associativity
77parseAssociativity =
74parseAssociativity =
src/Language/PureScript/Parser/JS.hsdeleted−174
@@ -1,174 +0,0 @@
1−-----------------------------------------------------------------------------
2−--
3−-- Module : Language.PureScript.Parser.JS
4−-- Copyright : (c) Phil Freeman 2013
5−-- License : MIT
6−--
7−-- Maintainer : Phil Freeman <paf31@cantab.net>
8−-- Stability : experimental
9−-- Portability :
10−--
11−-- |
12−-- A parser for a small fragment of Javascript
13−--
14−-----------------------------------------------------------------------------
15−
16−module Language.PureScript.Parser.JS (
17− parseJS
18−) where
19−
20−import Language.PureScript.Values
21−import Language.PureScript.Names
22−import Language.PureScript.CodeGen.JS.AST
23−import qualified Language.PureScript.Parser.Common as C
24−import Control.Applicative
25−import Control.Monad
26−import Data.Functor.Identity
27−import qualified Text.Parsec as P
28−import qualified Text.Parsec.Token as P
29−import qualified Text.Parsec.Expr as P
30−
31−booleanLiteral :: P.Parsec String u Bool
32−booleanLiteral = (C.reserved "true" >> return True) P.<|> (C.reserved "false" >> return False)
33−
34−parseNumericLiteral :: P.Parsec String u JS
35−parseNumericLiteral = JSNumericLiteral <$> C.integerOrFloat
36−
37−parseStringLiteral :: P.Parsec String u JS
38−parseStringLiteral = JSStringLiteral <$> C.stringLiteral
39−
40−parseBooleanLiteral :: P.Parsec String u JS
41−parseBooleanLiteral = JSBooleanLiteral <$> booleanLiteral
42−
43−parseArrayLiteral :: P.Parsec String u JS
44−parseArrayLiteral = JSArrayLiteral <$> P.squares C.tokenParser (P.commaSep C.tokenParser parseJS)
45−
46−parseObjectLiteral :: P.Parsec String u JS
47−parseObjectLiteral = JSObjectLiteral <$> P.braces C.tokenParser (P.commaSep C.tokenParser parseIdentifierAndValue)
48−
49−parseIdentifierAndValue :: P.Parsec String u (String, JS)
50−parseIdentifierAndValue = (,) <$> (identifier <* C.colon)
51− <*> parseJS
52−
53−identifier :: P.Parsec String u String
54−identifier = do
55− ident <- C.identifier
56− when (ident `elem` C.reservedJsNames) $ P.unexpected $ ("reserved identifier " ++ show ident)
57− return ident
58−
59−parseFunction :: P.Parsec String u JS
60−parseFunction = do
61− C.reserved "function"
62− name <- P.optionMaybe C.identifier
63− args <- P.parens C.tokenParser $ P.commaSep C.tokenParser identifier
64− body <- parseJS
65− return $ JSFunction name args body
66−
67−parseBlock :: P.Parsec String u JS
68−parseBlock = JSBlock <$> P.braces C.tokenParser (P.many parseJS)
69−
70−parseVar :: P.Parsec String u JS
71−parseVar = JSVar <$> identifier
72−
73−parseJSAtom :: P.Parsec String u JS
74−parseJSAtom = P.choice
75− [ P.try parseNumericLiteral
76− , P.try parseStringLiteral
77− , P.try parseBooleanLiteral
78− , parseArrayLiteral
79− , P.try parseObjectLiteral
80− , parseFunction
81− , parseBlock
82− , P.try parseVar
83− , parseVariableIntroduction
84− , parseWhile
85− , parseIf
86− , parseReturn
87− , P.parens C.tokenParser parseJS ]
88−
89−parseAccessor :: JS -> P.Parsec String u JS
90−parseAccessor js = P.try $ flip JSAccessor js <$> (C.dot *> P.notFollowedBy C.opLetter *> identifier)
91−
92−parseIndexer :: JS -> P.Parsec String u JS
93−parseIndexer js = P.try $ flip JSIndexer js <$> (P.squares C.tokenParser parseJS)
94−
95−parseConditional :: JS -> P.Parsec String u JS
96−parseConditional js = P.try $ do
97− _ <- C.lexeme $ P.char '?'
98− tr <- parseJS
99− _ <- C.lexeme $ P.char ':'
100− fa <- parseJS
101− return $ JSConditional js tr fa
102−
103−binary :: BinaryOperator -> String -> P.Assoc -> P.Operator String u Identity JS
104−binary op s f = P.Infix (P.try $ C.reservedOp s >> return (JSBinary op)) f
105−
106−unary :: UnaryOperator -> String -> P.Operator String u Identity JS
107−unary op s = P.Prefix (P.try $ C.reservedOp s >> return (JSUnary op))
108−
109−-- |
110−-- Parse a simplified Javascript expression
111−--
112−parseJS :: P.Parsec String u JS
113−parseJS =
114− (P.buildExpressionParser operators
115− . C.buildPostfixParser postfixTable2
116− $ indexersAndAccessors) P.<?> "javascript"
117− where
118− indexersAndAccessors = C.buildPostfixParser postfixTable1 parseJSAtom
119− postfixTable1 = [ parseAccessor, parseIndexer, parseConditional, parseAssignment ]
120− postfixTable2 = [ \v -> P.try $ JSApp v <$> (P.parens C.tokenParser (P.commaSep C.tokenParser parseJS)) ]
121− operators = [ [ binary LessThan "<" P.AssocLeft]
122− , [ binary LessThanOrEqualTo "<=" P.AssocLeft]
123− , [ binary GreaterThan ">" P.AssocLeft]
124− , [ binary GreaterThanOrEqualTo ">=" P.AssocLeft]
125− , [ unary Not "!" ]
126− , [ unary BitwiseNot "~" ]
127− , [ unary Negate "-" ]
128− , [ unary Positive "+" ]
129− , [ binary Multiply "*" P.AssocLeft]
130− , [ binary Divide "/" P.AssocLeft]
131− , [ binary Modulus "%" P.AssocLeft]
132− , [ binary Add "+" P.AssocLeft]
133− , [ binary Subtract "-" P.AssocLeft]
134− , [ binary ShiftLeft "<<" P.AssocLeft]
135− , [ binary ShiftRight ">>" P.AssocLeft]
136− , [ binary ZeroFillShiftRight ">>>" P.AssocLeft]
137− , [ binary EqualTo "===" P.AssocLeft]
138− , [ binary NotEqualTo "!==" P.AssocLeft]
139− , [ binary BitwiseAnd "&" P.AssocLeft]
140− , [ binary BitwiseXor "^" P.AssocLeft]
141− , [ binary BitwiseOr "|" P.AssocLeft]
142− , [ binary And "&&" P.AssocRight]
143− , [ binary Or "||" P.AssocRight]
144− ]
145−
146−parseVariableIntroduction :: P.Parsec String u JS
147−parseVariableIntroduction = do
148− C.reserved "var"
149− name <- P.identifier C.tokenParser
150− value <- P.optionMaybe $ do
151− _ <- C.lexeme $ P.char '='
152− value <- parseJS
153− _ <- C.semi
154− return value
155− return $ JSVariableIntroduction name value
156−
157−parseAssignment :: JS -> P.Parsec String u JS
158−parseAssignment tgt = do
159− _ <- C.lexeme $ P.char '='
160− value <- parseJS
161− _ <- C.semi
162− return $ JSAssignment tgt value
163−
164−parseWhile :: P.Parsec String u JS
165−parseWhile = JSWhile <$> (C.reserved "while" *> P.parens C.tokenParser parseJS)
166− <*> parseJS
167−
168−parseIf :: P.Parsec String u JS
169−parseIf = JSIfElse <$> (C.reserved "if" *> P.parens C.tokenParser parseJS)
170− <*> parseJS
171− <*> P.optionMaybe (C.reserved "else" >> parseJS)
172−
173−parseReturn :: P.Parsec String u JS
174−parseReturn = JSReturn <$> (C.reserved "return" *> parseJS <* C.semi)