forked from GitHub/gf-core
Convert tokens to lower case when printing GSL.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
-- |
|
-- |
|
||||||
-- Module : (Module)
|
-- Module : PrGSL
|
||||||
-- Maintainer : (Maintainer)
|
-- Maintainer : Bjorn Bringert (bringert@cs.chalmers.se)
|
||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
@@ -9,26 +9,10 @@
|
|||||||
-- > CVS $Author $
|
-- > CVS $Author $
|
||||||
-- > CVS $Revision $
|
-- > 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
|
-- FIXME: remove / warn / fail if there are int / string literal
|
||||||
-- categories in the grammar
|
-- categories in the grammar
|
||||||
|
|
||||||
@@ -42,7 +26,7 @@ import GrammarTypes
|
|||||||
import PrintParser
|
import PrintParser
|
||||||
import Option
|
import Option
|
||||||
|
|
||||||
import Data.Char (toUpper)
|
import Data.Char (toUpper,toLower)
|
||||||
|
|
||||||
gslPrinter :: Ident -- ^ Grammar name
|
gslPrinter :: Ident -- ^ Grammar name
|
||||||
-> Options -> CFGrammar -> String
|
-> Options -> CFGrammar -> String
|
||||||
@@ -64,7 +48,7 @@ prGSL (SRG{grammarName=name,startCat=start,origStartCat=origStart,rules=rs})
|
|||||||
prAlt rhs = wrap "(" (unwordsS (map prSymbol rhs')) ")"
|
prAlt rhs = wrap "(" (unwordsS (map prSymbol rhs')) ")"
|
||||||
where rhs' = rmPunct rhs
|
where rhs' = rmPunct rhs
|
||||||
prSymbol (Cat c) = prCat c
|
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
|
-- GSL requires an upper case letter in category names
|
||||||
prCat c = showString (firstToUpper c)
|
prCat c = showString (firstToUpper c)
|
||||||
|
|
||||||
@@ -77,6 +61,10 @@ rmPunct [] = []
|
|||||||
rmPunct (Tok t:ss) | all isPunct (prt t) = rmPunct ss
|
rmPunct (Tok t:ss) | all isPunct (prt t) = rmPunct ss
|
||||||
rmPunct (s:ss) = s : 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 :: Char -> Bool
|
||||||
isPunct c = c `elem` "-_.;.,?!()[]{}"
|
isPunct c = c `elem` "-_.;.,?!()[]{}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user