summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInari Listenmaa <inari.listenmaa@gmail.com>2020-07-31 15:05:46 +0200
committerInari Listenmaa <inari.listenmaa@gmail.com>2020-07-31 15:05:46 +0200
commitaeabc955c8b107e5467cb6b384b40320fb453176 (patch)
tree11d66ed23fc079924a4c9b8b3b940c78814d4c0e
parent030c3bfee91b6f6a633c73231f06a53b9c9be67d (diff)
Remove characters that aren't allowed in Haskell data types.
GF allows more characters in its types, as long as they are inside single quotes. E.g. 'VP/Object' is a valid name for a GF category, but not for a Haskell data type.
-rw-r--r--src/compiler/GF/Compile/PGFtoHaskell.hs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/compiler/GF/Compile/PGFtoHaskell.hs b/src/compiler/GF/Compile/PGFtoHaskell.hs
index e1fbc49aa..41f928d31 100644
--- a/src/compiler/GF/Compile/PGFtoHaskell.hs
+++ b/src/compiler/GF/Compile/PGFtoHaskell.hs
@@ -40,8 +40,10 @@ grammar2haskell opts name gr = foldr (++++) [] $
gadt = haskellOption opts HaskellGADT
dataExt = haskellOption opts HaskellData
lexical cat = haskellOption opts HaskellLexical && isLexicalCat opts cat
- gId | haskellOption opts HaskellNoPrefix = id
- | otherwise = ("G"++)
+ gId | haskellOption opts HaskellNoPrefix = rmForbiddenChars
+ | otherwise = ("G"++) . rmForbiddenChars
+ -- GF grammars allow weird identifier names inside '', e.g. 'VP/Object'
+ rmForbiddenChars = filter (`notElem` "'!#$%&*+./<=>?@\\^|-~")
pragmas | gadt = ["{-# OPTIONS_GHC -fglasgow-exts #-}","{-# LANGUAGE GADTs #-}"]
| dataExt = ["{-# LANGUAGE DeriveDataTypeable #-}"]
| otherwise = []