language-pig 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+13/−9 lines, 5 files
Files
- README.md +3/−5
- language-pig.cabal +1/−1
- src/Language/Pig/Parser/AST.hs +2/−0
- src/Language/Pig/Parser/Parser.hs +2/−2
- src/Language/Pig/Pretty.hs +5/−1
README.md view
@@ -26,15 +26,13 @@ parseString :: [Char] -> Root ``` -Returns an AST (type is the root node).+Returns an AST (type Root is the root node). Parse a file:- ```-parseFile :: FilePath -> IO Root+parseFile :: FilePath -> IO PigFile ```--Returns an AST (type = Root, which is the root node).+PigFile contains the Root (of AST) and the file name. Pretty print the produced tree: ```
language-pig.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: language-pig-version: 0.1.0.0+version: 0.2.0.0 synopsis: Pig parser in haskell. description: Parser and pretty printer for the Apache Pig scripting language (http://pig.apache.org/). The current version is implemented using Parsec parser combinators. -- description:
src/Language/Pig/Parser/AST.hs view
@@ -10,6 +10,8 @@ -- http://wiki.apache.org/pig/PigLexer -- http://wiki.apache.org/pig/PigParser +data PigFile = PigFile String Root+ data Root = Seq [Statement] DERIVE
src/Language/Pig/Parser/Parser.hs view
@@ -68,8 +68,8 @@ Left msg -> error (show msg) Right p -> p -parseFile :: FilePath -> IO Root-parseFile filename = parseString <$> readFile (filename)+parseFile :: FilePath -> IO PigFile+parseFile filename = ((PigFile filename) . parseString) <$> readFile (filename) parsePig :: String -> Either ParseError Root parsePig input = parse pigParser "pigParser error" input
src/Language/Pig/Pretty.hs view
@@ -10,6 +10,8 @@ import Data.Tree import Data.Tree.Pretty +import Control.Applicative ((<$>), (<*>))+ -- patterns: -- node name + list nodes -- node name + literal to display = terminalnode@@ -113,4 +115,6 @@ toTree c = Node (show c) [] prettyPrint :: Root -> String-prettyPrint ast = drawVerticalTree $ toTree ast+prettyPrint (Seq []) = "no statements\n"+prettyPrint (Seq statements) = "sequence of statements:\n" +++ (intercalate "\n" (map drawVerticalTree $ map toTree statements))