module WASHParser ( xmlfile, washfile ) where { import Char ; import Parsec hiding (letter) ; import WASHData; import WASHUtil; notImplemented = char '\xff' >> return undefined "something that isn't implemented yet"; f <$> p = do { x <- p; return $ f x; }; testParser p s = case parse (do { x <- p; eof; return x; }) "bla" s of { Left x -> print x; Right y -> print y; }; washfile :: Parser [CodeFrag] ; washfile = do code <- hBody eof return $ code ; setMode :: Bool -> Mode ; setMode toplevel = if toplevel then S else F ; -- The numbers given for each parser identify the section and -- grammar production within the XML 1.0 definition (W3C -- REC-xml-19980210). -- 2.1 / 1 xmlfile :: Parser File; xmlfile = do { prolog; code <- option [] (do { hs <- haskell; s0; return hs }); elem <- element True; many misc; eof; return $ File { fcode = code, topElem = elem }; }; -- 2.2 / 2 char' = (char '\t' <|> char '\n' <|> char '\r' <|> satisfy (>= ' ')) "character"; -- 2.3 / 3 s = (try $ many1 (char ' ' <|> char '\t' <|> char '\r' <|> char '\n')) "whitespace"; s0 = option "" s; {- s0 = (try $ many (char ' ' <|> char '\t' <|> char '\r' <|> char '\n')) "optional whitespace"; -} -- 2.3 / 4 nameChar = letter <|> digit <|> char '.' <|> char '-' <|> char '_' <|> char ':' <|> combiningChar <|> extender; -- 2.3 / 5 name :: Parser String; name = do { c <- letter <|> char '_' <|> char ':'; cs <- many nameChar; return $ c:cs; } "name"; -- 2.3 / 6 names :: Parser [String]; names = sepBy1 name s; -- 2.3 / 7 nmtoken :: Parser String; nmtoken = many1 nameChar "nmtoken"; -- 2.3 / 8 nmtokens :: Parser [String]; nmtokens = sepBy1 name s; -- 2.3 / 10 attValue :: Parser AttrValue; attValue = (((AText . concat) <$> ( between (char '\"') (char '\"') (many (p '\"')) <|> between (char '\'') (char '\'') (many (p '\'')) )) <|> ACode <$> haskellAttr) "attvalue" where { p end = (\x -> [x]) <$> satisfy (f end) <|> reference; f end = \c -> c /= '<' && c /= '&' && c /= end; }; -- 2.3 / 11 systemLiteral = do{ char '\''; sl <- many (satisfy (\c -> c /= '\'')); char '\''; return sl; } <|> do{ char '\"'; sl <- many (satisfy (\c -> c /= '\"')); char '\"'; return sl; }; -- 2.3 / 12 pubidLiteral = do { char '\''; sl <- many (pubidChar False); char '\''; return sl; } <|> do{ char '\"'; sl <- many (pubidChar True); char '\"'; return sl; }; -- 2.3 / 13 pubidChar w = satisfy (\c -> c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c `elem` " \n\r-()+,./:=?;!*#@$_%" || w && c == '\''); -- 2.4 / 14 charData :: Bool -> Parser Text; charData toplevel = do { s <- many1 charData'; return $ Text (setMode toplevel) $ concat s; } "#PCDATA"; charData' :: Parser String; charData' = do { c <- satisfy f; return [c]; } <|> do { string "]]"; c <- satisfy (\c -> f c && c /= '>'); return $ ']':']':[c]; } where { f c = c /= '<' && c /= '&' && c /= ']'; }; -- 2.5 / 15 comment :: Parser String; comment = do { try $ string "