1
0
forked from GitHub/gf-core

Convert tokens to lower case when printing GSL.

This commit is contained in:
bringert
2005-02-07 08:39:00 +00:00
parent 156c9b0bf3
commit ea169ef824

View File

@@ -1,7 +1,7 @@
----------------------------------------------------------------------
-- |
-- Module : (Module)
-- Maintainer : (Maintainer)
-- Module : PrGSL
-- Maintainer : Bjorn Bringert (bringert@cs.chalmers.se)
-- Stability : (stable)
-- Portability : (portable)
--
@@ -9,26 +9,10 @@
-- > CVS $Author $
-- > CVS $Revision $
--
-- (Description of the module)
-- This module prints a CFG as a Nuance GSL 2.0 grammar.
--
-----------------------------------------------------------------------------
{-
**************************************************************
GF Module
Description : This module prints a CFG as a Nuance GSL 2.0
grammar.
Author : Björn Bringert (bringert@cs.chalmers.se)
License : GPL (GNU General Public License)
Created : September 13, 2004
Modified : October 1, 2004
**************************************************************
-}
-- FIXME: remove / warn / fail if there are int / string literal
-- categories in the grammar
@@ -42,7 +26,7 @@ import GrammarTypes
import PrintParser
import Option
import Data.Char (toUpper)
import Data.Char (toUpper,toLower)
gslPrinter :: Ident -- ^ Grammar name
-> Options -> CFGrammar -> String
@@ -64,7 +48,7 @@ prGSL (SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs})
prAlt rhs = wrap "(" (unwordsS (map prSymbol rhs')) ")"
where rhs' = rmPunct rhs
prSymbol (Cat c) = prCat c
prSymbol (Tok t) = wrap "\"" (prtS t) "\""
prSymbol (Tok t) = wrap "\"" (showString (showToken t)) "\""
-- GSL requires an upper case letter in category names
prCat c = showString (firstToUpper c)
@@ -77,6 +61,10 @@ rmPunct [] = []
rmPunct (Tok t:ss) | all isPunct (prt t) = rmPunct ss
rmPunct (s:ss) = s : rmPunct ss
-- Nuance does not like upper case characters in tokens
showToken :: Token -> String
showToken t = map toLower (prt t)
isPunct :: Char -> Bool
isPunct c = c `elem` "-_.;.,?!()[]{}"