From f5bbddb5bef1eece48f3899a3242756cdba77868 Mon Sep 17 00:00:00 2001 From: Spyros Trigazis Date: Wed, 31 Jul 2013 18:47:17 +0300 Subject: [PATCH] Add generic Parsers file Extract the utility functions of Diskstats's collector Parser so other collector Parsers can be able to use them. Signed-off-by: Spyros Trigazis Signed-off-by: Michele Tartara Reviewed-by: Michele Tartara --- Makefile.am | 1 + src/Ganeti/Parsers.hs | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/Ganeti/Parsers.hs diff --git a/Makefile.am b/Makefile.am index 30d846b8d..0e8cf3d8f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -608,6 +608,7 @@ HS_LIB_SRCS = \ src/Ganeti/OpCodes.hs \ src/Ganeti/OpParams.hs \ src/Ganeti/Path.hs \ + src/Ganeti/Parsers.hs \ src/Ganeti/Query/Cluster.hs \ src/Ganeti/Query/Common.hs \ src/Ganeti/Query/Export.hs \ diff --git a/src/Ganeti/Parsers.hs b/src/Ganeti/Parsers.hs new file mode 100644 index 000000000..5d14189b1 --- /dev/null +++ b/src/Ganeti/Parsers.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE OverloadedStrings #-} +{-| Utility functions for several parsers + +This module holds the definition for some utility functions for two +parsers. The parser for the @/proc/stat@ file and the parser for the +@/proc/diskstats@ file. + +-} +{- + +Copyright (C) 2013 Google Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301, USA. + +-} +module Ganeti.Parsers where + +import Control.Applicative ((*>)) +import qualified Data.Attoparsec.Text as A +import Data.Attoparsec.Text (Parser) +import Data.Text (unpack) + +-- * Utility functions + +-- | Our own space-skipping function, because A.skipSpace also skips +-- newline characters. It skips ZERO or more spaces, so it does not +-- fail if there are no spaces. +skipSpaces :: Parser () +skipSpaces = A.skipWhile A.isHorizontalSpace + +-- | A parser recognizing a number preceeded by spaces. +numberP :: Parser Int +numberP = skipSpaces *> A.decimal + +-- | A parser recognizing a word preceded by spaces, and closed by a space. +stringP :: Parser String +stringP = skipSpaces *> fmap unpack (A.takeWhile $ not . A.isHorizontalSpace) -- GitLab