packages feed

SableCC2Hs-0.0.0.1: src/SableCC/Test/Test.hs

----------------------------------------------------------------------------
-- |
-- Module      :  SableCC.Test.Test
-- Copyright   :  (c) Fontaine 2011
-- License     :  BSD3
--
-- Maintainer  :  fontaine@cs.uni-duesseldorf.de
-- Stability   :  experimental
-- Portability :  GHC-only
--
--
-----------------------------------------------------------------------------

module SableCC.Test.Test
where

import SableCC.ParserTypes (CST)
import SableCC.XML.ParserDefinitionRaw
import SableCC.XML.XML2Parser
import SableCC.LexerDefinition
import SableCC.ParserDefinition as ParserDefinition
import SableCC.Test.Parser

-- | Read a parser definition (XML-file) and a source file
-- and apply the parser to the source.
-- This test passes the parser tables directly to the parser
-- without generating Haskell-modules for the tables.
parseFile :: FilePath -> FilePath -> IO CST
parseFile sableParser bFile = do
  putStrLn "reading Parser"
  rawParser <- readParser sableParser
  putStrLn "reading Source"
  src <- readFile bFile
  putStrLn "running Lexer"
  lexerTokens <- runLexer (makeLexerDefinition rawParser) src
  let
    parserDefinition = makeParserDefinition rawParser
    parserTokens = trimTokens rawParser lexerTokens
  putStrLn "running Parser"
  cst <- runParser parserDefinition parserTokens
  return cst