packages feed

nmis-parser 0.1.0.1 → 0.1.0.2

raw patch · 14 files changed

+146/−79 lines, 14 filesbinary-added

Files

+ .DS_Store view

binary file changed (absent → 6148 bytes)

+ ._.DS_Store view

binary file changed (absent → 120 bytes)

README.md view
@@ -1,4 +1,4 @@-# NMIS file parser +# NMIS file parser  - NMIS stands for Network Management Information System  This parser parses the NMIS format files to `Nmis` record type@@ -12,18 +12,13 @@   import Text.Megaparsec   import Text.Nmis -  main :: IO ()-  main = do-    args <- getArgs-    case args of-      [] -> putStrLn "error: you need to pass in file path"-      [path] -> do-              contents <- readFile path-              let result = parse parseNmis "" contents-              case result of-                  Left nodes -> print $ parseErrorPretty nodes-                  Right nodes -> do-                      print nodes-      _ -> putStrLn "error: you need to pass in only one file path"+main :: IO ()+main = getArgs >>= parseArgs+  where+    parseArgs [] = putStrLn "error: you need to pass in the file path"+    parseArgs (path:_) = do+      contents <- readFile path+      either (print . parseErrorPretty) print (parse parseNmis "" contents)+  ```
nmis-parser.cabal view
@@ -1,11 +1,11 @@ name:                nmis-parser-version:             0.1.0.1+version:             0.1.0.2 synopsis:            NMIS file parser homepage:            https://github.com/v0d1ch/nmis-parser#readme license:             BSD3 license-file:        LICENSE author:              Sasa Bogicevic-maintainer:          brutallesale@gmail.com+maintainer:          t4nt0r@pm.me copyright:           2017 Sasa Bogicevic category:            Text, Parsers build-type:          Simple
− nmis-parser.cabal~
@@ -1,40 +0,0 @@-name:                nmis-parser-version:             0.1.0.0-synopsis:            NMIS file parser-homepage:            https://github.com/v0d1ch/nmis-parser#readme-license:             BSD3-license-file:        LICENSE-author:              Sasa Bogicevic-maintainer:          brutallesale@gmail.com-copyright:           2017 Sasa Bogicevic-category:            Text, Parsers-build-type:          Simple-extra-source-files:  README.md-cabal-version:       >=1.10--description:-     Parser for __NMIS__ (Network Management Information System) files to record type. Main module to use is __Text.Nmis__ and __parseNmis__ function--library-  hs-source-dirs:      src-  exposed-modules:     Text.Nmis-                     , Text.Internal.Helper-                     , Text.Internal.NmisTypes-  build-depends:       base >= 4.7 && < 5-                     , containers-                     , megaparsec < 5.3.2-  default-language:    Haskell2010---test-suite nmis-test-  type:                exitcode-stdio-1.0-  hs-source-dirs:      test-  main-is:             Spec.hs-  build-depends:       base-                     , Nmis-  ghc-options:         -threaded -rtsopts -with-rtsopts=-N-  default-language:    Haskell2010--source-repository head-  type:     git-  location: https://github.com/v0d1ch/nmis-parser
+ src/.DS_Store view

binary file changed (absent → 6148 bytes)

+ src/._.DS_Store view

binary file changed (absent → 120 bytes)

− src/Text/Internal/.DS_Store

binary file changed (6148 → absent bytes)

− src/Text/Internal/._.DS_Store

binary file changed (120 → absent bytes)

src/Text/Internal/Helper.hs view
@@ -1,11 +1,11 @@ {-| Module      : Text.Internal.Helper-Description : Helper for parse actions +Description : Helper for parse actions Copyright   : (c) Sasa Bogicevic, 2017 License     : GPL-3-Maintainer  : brutallesale@gmail.com+Maintainer  : t4nt0r@pm.me Stability   : experimental-Uses megaparsec library +Uses megaparsec library -}  {-# LANGUAGE OverloadedStrings #-}
+ src/Text/Internal/Helper.hs~ view
@@ -0,0 +1,84 @@+{-# LANGUAGE OverloadedStrings #-}+-- | This helper module contains functions to parse nmis file.+-- It uses megapasec library+module Helper where++import Control.Applicative (empty)+import Control.Monad (void)+import Prelude hiding (until)+import Text.Megaparsec+import qualified Text.Megaparsec.Lexer as L+import Text.Megaparsec.String++-- | space consumer - consume space and comments+spaceConsumer :: Parser ()+spaceConsumer = L.space (void spaceChar) lineCmnt blockCmnt+  where+    lineCmnt = L.skipLineComment "#"+    blockCmnt = L.skipBlockComment "/*" "*/"+-- | hashbang line comment+lineComment :: Parser ()+lineComment = L.skipLineComment "#"++-- | space consumer no 2+scn :: Parser ()+scn = L.space (void spaceChar) lineComment empty++-- | lexeme+lexeme :: Parser a -> Parser a+lexeme = L.lexeme spaceConsumer++-- | symbol+symbol :: String -> Parser String+symbol = L.symbol scn++-- | arrow - parse haskell constraint like arrow sign+parrow :: Parser String+parrow = lexeme $ string " => "++-- | equals - parse equals sign+pequals :: Parser String+pequals = lexeme $ string " = "++-- | parse all between parens+parens :: Parser a -> Parser a+parens = between (string "(") (string ")")++-- | parse all between braces+braces :: Parser a -> Parser a+braces = between (string "{") (string "}")++-- | parse until string passed as function parameter+until :: String -> Parsec Dec String String+until s = anyChar `manyTill` string s++-- | parse until newline character+untilEol :: Parsec Dec String String+untilEol = anyChar `someTill` newline++-- | parse until newline character+phash :: Parser String+phash = lexeme $ string' "%hash" >> pequals++-- | parse quoted string with optional space in front of it+pQuotedStr :: Parser String+pQuotedStr = do+  _ <- optional space+  string' "'" >> until "'"++-- | parse 'undef' literal+pUndefined :: Parser String+pUndefined = do+  _ <- optional space+  string' "undef"++-- | combined parser for single record+pOpt :: Parser (String, String)+pOpt = do+  _ <- space+  key <- pQuotedStr+  _ <- space >> string "=>" >> space+  value <- try (pQuotedStr <|> pUndefined <|> many numberChar)+  _ <- optional $ string' ","+  _ <- newline+  return (key, value)
src/Text/Internal/NmisTypes.hs view
@@ -1,9 +1,9 @@ {-| Module      : Text.Internal.NmisTypes-Description : Contains single type that holds all parsed data  +Description : Contains single type that holds all parsed data Copyright   : (c) Sasa Bogicevic, 2017 License     : GPL-3-Maintainer  : brutallesale@gmail.com+Maintainer  : t4nt0r@pm.me Stability   : experimental -} module Text.Internal.NmisTypes where
+ src/Text/Internal/NmisTypes.hs~ view
@@ -0,0 +1,36 @@+module NmisTypes where++-- | Main type that containes all parsed data+data Nmis = Nmis+  { customer :: Maybe String+  , groups :: Maybe String+  , active :: Maybe String+  , advancedOptions :: Maybe String+  , authKey :: Maybe String+  , authPassword :: Maybe String+  , authProtocol :: Maybe String+  , businessService :: Maybe String+  , calls :: Maybe String+  , cbqos :: Maybe String+  , collect :: Maybe String+  , community :: Maybe String+  , depend :: Maybe String+  , display_name :: Maybe String+  , group :: Maybe String+  , host :: Maybe String+  , location :: Maybe String+  , model :: Maybe String+  , name :: Maybe String+  , netType :: Maybe String+  , ping :: Maybe String+  , port :: Maybe String+  , rancid :: Maybe String+  , roleType :: Maybe String+  , serviceStatus :: Maybe String+  , services :: Maybe String+  , threshold :: Maybe String+  , timezone :: Maybe Integer+  , uuid :: Maybe String+  , version :: Maybe String+  , webserver :: Maybe String+  } deriving (Show)
src/Text/Nmis.hs view
@@ -3,7 +3,7 @@ Description : Main module for nmis parsing Copyright   : (c) Sasa Bogicevic, 2017 License     : GPL-3-Maintainer  : brutallesale@gmail.com+Maintainer  : t4nt0r@pm.me Stability   : experimental  -}@@ -16,6 +16,9 @@ -- --  module Main where --+--+--  import Data.Either+-- --  import System.Environment (getArgs) -- --  import System.IO@@ -26,29 +29,18 @@ -- --  main :: IO () -----  main = do------    args <- getArgs------    case args of------      [] -> putStrLn "error: you need to pass in file path"------      [path] -> do------              contents <- readFile path+--  main = getArgs >>= parseArgs -----              let result = parse parseNmis "" contents+--    where -----              case result of+--      parseArgs [] = putStrLn "error: you need to pass in the file path" -----                  Left nodes -> print $ parseErrorPretty nodes+--      parseArgs (path:_) = do -----                  Right nodes -> do+--        contents <- readFile path -----                      print nodes+--        either (print . parseErrorPretty) print (parse parseNmis "" contents) -----      _ -> putStrLn "error: you need to pass in only one file path" --  {-# LANGUAGE OverloadedStrings #-}