mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
gf -server: /parse command now supports input with character codes > 255
This enables the use of arbitrary Unicode character in text mode in GFSE.
This commit is contained in:
@@ -5,10 +5,15 @@ import Control.Monad(unless,foldM,ap,mplus)
|
|||||||
import Data.List(sortBy)
|
import Data.List(sortBy)
|
||||||
import Data.Function(on)
|
import Data.Function(on)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.ByteString.Char8 as BS(pack)
|
|
||||||
import Text.JSON(encode,makeObj)
|
import Text.JSON(encode,makeObj)
|
||||||
import Text.PrettyPrint(render)
|
import Text.PrettyPrint(render)
|
||||||
|
|
||||||
|
-- 4 extra imports just to deal with the ByteString mess...
|
||||||
|
import qualified Data.ByteString.Char8 as BS(pack)
|
||||||
|
import Codec.Binary.UTF8.String(encodeString)
|
||||||
|
import GF.Compile.Coding(decodeStringsInModule)
|
||||||
|
import System.IO(utf8)
|
||||||
|
|
||||||
--import GF.Compile.GetGrammar (getSourceModule)
|
--import GF.Compile.GetGrammar (getSourceModule)
|
||||||
import GF.Infra.Option(optionsGFO)
|
import GF.Infra.Option(optionsGFO)
|
||||||
import GF.Infra.Ident(showIdent)
|
import GF.Infra.Ident(showIdent)
|
||||||
@@ -25,10 +30,10 @@ import SimpleEditor.JSON
|
|||||||
|
|
||||||
parseModule (path,source) =
|
parseModule (path,source) =
|
||||||
(path.=) $
|
(path.=) $
|
||||||
case runP pModDef (BS.pack source) of
|
case runP pModDef (BS.pack (encodeString source)) of
|
||||||
Left (Pn l c,msg) ->
|
Left (Pn l c,msg) ->
|
||||||
makeObj ["error".=msg, "location".= show l++":"++show c]
|
makeObj ["error".=msg, "location".= show l++":"++show c]
|
||||||
Right mod -> case convModule mod of
|
Right mod -> case convModule (decodeStringsInModule utf8 mod) of
|
||||||
Ok g -> makeObj ["converted".=g]
|
Ok g -> makeObj ["converted".=g]
|
||||||
Bad msg -> makeObj ["parsed".=msg]
|
Bad msg -> makeObj ["parsed".=msg]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user