Skip to content

Instantly share code, notes, and snippets.

@dmitry-vsl
Created February 1, 2015 21:09
Show Gist options
  • Save dmitry-vsl/4e1ac80f755f3499ab68 to your computer and use it in GitHub Desktop.
Save dmitry-vsl/4e1ac80f755f3499ab68 to your computer and use it in GitHub Desktop.
{-# LANGUAGE NoMonomorphismRestriction #-}
import Text.ParserCombinators.Parsec
empty = many (oneOf "\t\n\r ")
inBraces = between (char '(') (char ')')
commaList p = sepBy (between empty empty p) (char ',')
array p = between (char '[') (char ']') (commaList p)
identifier = many1 alphaNum
quoted quote = do
begin <- (char quote)
result <- (many (noneOf [quote]))
end <- (char quote)
return result
jsString = choice [(quoted '\''), (quoted '"')]
amdModuleHeader = do
string "define(" >> empty
modules <- array jsString
char ',' >> empty >> string "function("
names <- commaList identifier
string "){"
return (modules, names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment