language-javascript 0.5.6 → 0.5.7
raw patch · 5 files changed
+36/−5 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Language.JavaScript.Parser: parseFileUtf8 :: FilePath -> IO JSNode
+ Language.JavaScript.Parser.Parser: parseFileUtf8 :: FilePath -> IO JSNode
Files
- README +14/−0
- language-javascript.cabal +2/−3
- runtests.hs +7/−1
- src/Language/JavaScript/Parser.hs +1/−0
- src/Language/JavaScript/Parser/Parser.hs +12/−1
README view
@@ -32,8 +32,22 @@ Alex 3.0 now supports unicode natively, and has been included as a dependency in the cabal file. +Note: The generation of the lexical analyser has been separated out,+ to remove the install-time dependency on Alex. If any changes+ need to be made to the lexer, the Lexer.x source lies in+ src-dev, and the runalex.sh script will invoke Alex with the+ appropriate directories. + At the moment (0.5.6), the lexer can only be generated with Alex+ 3.0.1+ Changes++0.5.7 Remove the hs-source-dirs from test suite to prevent compilation+ issues (@nomeata) ++ Introduce parseFileUtf8 to explicitly use utf8 for parsing a+ file, and update tests to use it where needed. Closes #21 0.5.6 Remove constraint on Alex 3.0.1, it is only required to make changes to the lexer. Closes #19
language-javascript.cabal view
@@ -1,5 +1,5 @@ Name: language-javascript-Version: 0.5.6+Version: 0.5.7 Synopsis: Parser for JavaScript Description: Parses Javascript into an Abstract Syntax Tree (AST). Initially intended as frontend to hjsmin. .@@ -72,8 +72,7 @@ , blaze-builder >= 0.2 && < 1 -- need our own library for tests , language-javascript >= 0.5.5- hs-source-dirs: . src ./dist/build-+ source-repository head type: git
runtests.hs view
@@ -294,7 +294,7 @@ , testCase "unicode4" (testProg "x=\"àáâãäå\";y='\3012a\0068'" "Right (JSSourceElementsTop [JSExpression [JSIdentifier \"x\",JSOperator JSLiteral \"=\",JSStringLiteral '\"' \"\\224\\225\\226\\227\\228\\229\"],JSLiteral \";\",JSExpression [JSIdentifier \"y\",JSOperator JSLiteral \"=\",JSStringLiteral '\\'' \"\\3012aD\"],JSLiteral \"\"])") - , testCase "unicode5f" (testFile "./test/Unicode.js" "JSSourceElementsTop [JSExpression [JSIdentifier \"\\224\\225\\226\\227\\228\\229\",JSOperator JSLiteral \"=\",JSDecimal \"1\"],JSLiteral \";\",JSLiteral \"\"]")+ , testCase "unicode5f" (testFileUtf8 "./test/Unicode.js" "JSSourceElementsTop [JSExpression [JSIdentifier \"\\224\\225\\226\\227\\228\\229\",JSOperator JSLiteral \"=\",JSDecimal \"1\"],JSLiteral \";\",JSLiteral \"\"]") , testCase "bug2.a" (testProg "function() {\nz = function /*z*/(o) {\nreturn r;\n};}" "Right (JSSourceElementsTop [JSExpression [JSFunctionExpression [] [] (JSBlock ([JSExpression [JSIdentifier \"z\",JSOperator JSLiteral \"=\",JSFunctionExpression [] [JSIdentifier \"o\"] (JSBlock ([JSReturn [JSExpression [JSIdentifier \"r\"]] JSLiteral \";\"]))],JSLiteral \";\"]))],JSLiteral \"\"])") @@ -775,6 +775,12 @@ testFile :: FilePath -> String -> IO () testFile fileName expected = do res <- parseFile fileName+ -- expected @=? (liftM show $ parseFile fileName)+ (expected @=? (showStripped res))++testFileUtf8 :: FilePath -> String -> IO ()+testFileUtf8 fileName expected = do+ res <- parseFileUtf8 fileName -- expected @=? (liftM show $ parseFile fileName) (expected @=? (showStripped res))
src/Language/JavaScript/Parser.hs view
@@ -3,6 +3,7 @@ PA.parse , PA.readJs , PA.parseFile+ , PA.parseFileUtf8 , PA.showStripped , PA.showStrippedMaybe , JSNode(..)
src/Language/JavaScript/Parser/Parser.hs view
@@ -4,6 +4,7 @@ , readJs -- , readJsKeepComments , parseFile+ , parseFileUtf8 -- * Parsing expressions -- parseExpr , parseUsing@@ -15,7 +16,7 @@ import Language.JavaScript.Parser.Grammar5 import Language.JavaScript.Parser.Lexer import qualified Language.JavaScript.Parser.AST as AST-+import System.IO -- | Parse one compound statement, or a sequence of simple statements. -- Generally used for interactive input, such as from the command line of an interpreter.@@ -41,6 +42,16 @@ parseFile filename = do x <- readFile (filename)+ return $ readJs x++-- | Parse the given file, explicitly setting the encoding to UTF8+-- when reading it+parseFileUtf8 :: FilePath -> IO AST.JSNode+parseFileUtf8 filename =+ do+ h <- openFile filename ReadMode+ hSetEncoding h utf8+ x <- hGetContents h return $ readJs x showStripped :: AST.JSNode -> String