Skip to content

Commit

Permalink
jQuery passes pretty-parse test
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun Guha committed Dec 23, 2008
1 parent 36d5b78 commit 6663fcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/WebBits/JavaScript/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,12 @@ parseRegexpLit = do
return $ \f -> f ('g' `elem` flags) ('i' `elem` flags)
let parseEscape = char '\\' >> anyChar
let parseChar = noneOf "/"
let parseRe = (char '/' >> return "") <|> (char '\\' >> liftM2 (:) anyChar parseRe) <|> (liftM2 (:) anyChar parseRe)
let parseRe = (char '/' >> return "") <|>
(do char '\\'
ch <- anyChar -- TOOD: too lenient
rest <- parseRe
return ('\\':ch:rest)) <|>
(liftM2 (:) anyChar parseRe)
pos <- getPosition
char '/'
pat <- parseRe --many1 parseChar
Expand Down
6 changes: 4 additions & 2 deletions tests/ParsePretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Data.Data
import System.Directory (getDirectoryContents)
import System.FilePath (takeExtension, FilePath, (</>))
import qualified Data.List as L
import System.IO.Unsafe (unsafePerformIO)

import WebBits.Common (pp)
import Text.ParserCombinators.Parsec (ParseError, sourceName, errorPos)
Expand All @@ -24,11 +25,12 @@ isPrettyPrintError pe =

parse :: FilePath -> String -> [ParsedStatement]
parse src str = case parseScriptFromString src str of
Left err | isPrettyPrintError err -> error $ (show err) ++ "\n" ++ str
Left err | isPrettyPrintError err ->
(unsafePerformIO $ putStrLn str) `seq` error (show err)
| otherwise -> error (show err)
Right (Script _ stmts) -> stmts

eraseSourcePos x = fmap (\_ -> ()) x
eraseSourcePos x = fmap (const ()) x

assertEqualWithoutSourcePos lhs rhs =
case eraseSourcePos lhs == eraseSourcePos rhs of
Expand Down

0 comments on commit 6663fcb

Please sign in to comment.