forked from GitHub/gf-core
introduce the type synonym Token=String in the PGF API
This commit is contained in:
@@ -27,7 +27,6 @@ import qualified Data.Set as Set
|
|||||||
--
|
--
|
||||||
|
|
||||||
type Cat = String
|
type Cat = String
|
||||||
type Token = String
|
|
||||||
|
|
||||||
data Symbol c t = NonTerminal c | Terminal t
|
data Symbol c t = NonTerminal c | Terminal t
|
||||||
deriving (Eq, Ord, Show)
|
deriving (Eq, Ord, Show)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import GF.Speech.CFG
|
|||||||
import GF.Speech.RegExp
|
import GF.Speech.RegExp
|
||||||
import GF.Speech.SISR as SISR
|
import GF.Speech.SISR as SISR
|
||||||
import GF.Speech.SRG
|
import GF.Speech.SRG
|
||||||
import PGF (PGF, CId)
|
import PGF (PGF, CId, Token)
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Char (toUpper,toLower)
|
import Data.Char (toUpper,toLower)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ module PGF(
|
|||||||
groupResults, -- lins of trees by language, removing duplicates
|
groupResults, -- lins of trees by language, removing duplicates
|
||||||
showPrintName,
|
showPrintName,
|
||||||
|
|
||||||
BracketedString(..), FId, LIndex,
|
BracketedString(..), FId, LIndex, Token,
|
||||||
Forest.showBracketedString,
|
Forest.showBracketedString,
|
||||||
|
|
||||||
-- ** Parsing
|
-- ** Parsing
|
||||||
|
|||||||
@@ -44,19 +44,20 @@ data Concr = Concr {
|
|||||||
totalCats :: {-# UNPACK #-} !FId
|
totalCats :: {-# UNPACK #-} !FId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Token = String
|
||||||
type FId = Int
|
type FId = Int
|
||||||
type LIndex = Int
|
type LIndex = Int
|
||||||
type DotPos = Int
|
type DotPos = Int
|
||||||
data Symbol
|
data Symbol
|
||||||
= SymCat {-# UNPACK #-} !Int {-# UNPACK #-} !LIndex
|
= SymCat {-# UNPACK #-} !Int {-# UNPACK #-} !LIndex
|
||||||
| SymLit {-# UNPACK #-} !Int {-# UNPACK #-} !LIndex
|
| SymLit {-# UNPACK #-} !Int {-# UNPACK #-} !LIndex
|
||||||
| SymKS [String]
|
| SymKS [Token]
|
||||||
| SymKP [String] [Alternative]
|
| SymKP [Token] [Alternative]
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
data Production
|
data Production
|
||||||
= PApply {-# UNPACK #-} !FunId [FId]
|
= PApply {-# UNPACK #-} !FunId [FId]
|
||||||
| PCoerce {-# UNPACK #-} !FId
|
| PCoerce {-# UNPACK #-} !FId
|
||||||
| PConst CId Expr [String]
|
| PConst CId Expr [Token]
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
data CncCat = CncCat {-# UNPACK #-} !FId {-# UNPACK #-} !FId {-# UNPACK #-} !(Array LIndex String)
|
data CncCat = CncCat {-# UNPACK #-} !FId {-# UNPACK #-} !FId {-# UNPACK #-} !(Array LIndex String)
|
||||||
data CncFun = CncFun CId {-# UNPACK #-} !(UArray LIndex SeqId) deriving (Eq,Ord,Show)
|
data CncFun = CncFun CId {-# UNPACK #-} !(UArray LIndex SeqId) deriving (Eq,Ord,Show)
|
||||||
@@ -65,7 +66,7 @@ type FunId = Int
|
|||||||
type SeqId = Int
|
type SeqId = Int
|
||||||
|
|
||||||
data Alternative =
|
data Alternative =
|
||||||
Alt [String] [String]
|
Alt [Token] [String]
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ _V = mkCId "__gfV"
|
|||||||
-- as usual but we also want to retain the ''brackets'' that
|
-- as usual but we also want to retain the ''brackets'' that
|
||||||
-- mark the beginning and the end of each constituent.
|
-- mark the beginning and the end of each constituent.
|
||||||
data BracketedString
|
data BracketedString
|
||||||
= Leaf String -- ^ this is the leaf i.e. a single token
|
= Leaf Token -- ^ this is the leaf i.e. a single token
|
||||||
| Bracket CId {-# UNPACK #-} !FId {-# UNPACK #-} !LIndex [Expr] [BracketedString]
|
| Bracket CId {-# UNPACK #-} !FId {-# UNPACK #-} !LIndex [Expr] [BracketedString]
|
||||||
-- ^ this is a bracket. The 'CId' is the category of
|
-- ^ this is a bracket. The 'CId' is the category of
|
||||||
-- the phrase. The 'FId' is an unique identifier for
|
-- the phrase. The 'FId' is an unique identifier for
|
||||||
@@ -160,8 +160,8 @@ data BracketedString
|
|||||||
-- that represents the same constituent.
|
-- that represents the same constituent.
|
||||||
|
|
||||||
data BracketedTokn
|
data BracketedTokn
|
||||||
= LeafKS [String]
|
= LeafKS [Token]
|
||||||
| LeafKP [String] [Alternative]
|
| LeafKP [Token] [Alternative]
|
||||||
| Bracket_ CId {-# UNPACK #-} !FId {-# UNPACK #-} !LIndex [Expr] [BracketedTokn] -- Invariant: the list is not empty
|
| Bracket_ CId {-# UNPACK #-} !FId {-# UNPACK #-} !LIndex [Expr] [BracketedTokn] -- Invariant: the list is not empty
|
||||||
deriving Eq
|
deriving Eq
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ initState pgf lang (DTyp _ start _) =
|
|||||||
-- is consumed and the current position is shifted by one.
|
-- is consumed and the current position is shifted by one.
|
||||||
-- If the new token cannot be accepted then an error state
|
-- If the new token cannot be accepted then an error state
|
||||||
-- is returned.
|
-- is returned.
|
||||||
nextState :: ParseState -> String -> Either ErrorState ParseState
|
nextState :: ParseState -> Token -> Either ErrorState ParseState
|
||||||
nextState (PState pgf cnc chart items) t =
|
nextState (PState pgf cnc chart items) t =
|
||||||
let (mb_agenda,map_items) = TMap.decompose items
|
let (mb_agenda,map_items) = TMap.decompose items
|
||||||
agenda = maybe [] Set.toList mb_agenda
|
agenda = maybe [] Set.toList mb_agenda
|
||||||
@@ -147,7 +147,7 @@ feedLiteral (PState pgf cnc chart items) (ELit lit) =
|
|||||||
-- then the 'getCompletions' function can be used to calculate the possible
|
-- then the 'getCompletions' function can be used to calculate the possible
|
||||||
-- next words and the consequent states. This is used for word completions in
|
-- next words and the consequent states. This is used for word completions in
|
||||||
-- the GF interpreter.
|
-- the GF interpreter.
|
||||||
getCompletions :: ParseState -> String -> Map.Map String ParseState
|
getCompletions :: ParseState -> String -> Map.Map Token ParseState
|
||||||
getCompletions (PState pgf cnc chart items) w =
|
getCompletions (PState pgf cnc chart items) w =
|
||||||
let (mb_agenda,map_items) = TMap.decompose items
|
let (mb_agenda,map_items) = TMap.decompose items
|
||||||
agenda = maybe [] Set.toList mb_agenda
|
agenda = maybe [] Set.toList mb_agenda
|
||||||
@@ -164,7 +164,7 @@ getCompletions (PState pgf cnc chart items) w =
|
|||||||
| isPrefixOf w tok = Map.insertWith (TMap.unionWith Set.union) tok (TMap.singleton toks (Set.singleton item)) acc
|
| isPrefixOf w tok = Map.insertWith (TMap.unionWith Set.union) tok (TMap.singleton toks (Set.singleton item)) acc
|
||||||
add _ item acc = acc
|
add _ item acc = acc
|
||||||
|
|
||||||
recoveryStates :: [Type] -> ErrorState -> (ParseState, Map.Map String ParseState)
|
recoveryStates :: [Type] -> ErrorState -> (ParseState, Map.Map Token ParseState)
|
||||||
recoveryStates open_types (EState pgf cnc chart) =
|
recoveryStates open_types (EState pgf cnc chart) =
|
||||||
let open_fcats = concatMap type2fcats open_types
|
let open_fcats = concatMap type2fcats open_types
|
||||||
agenda = foldl (complete open_fcats) [] (actives chart)
|
agenda = foldl (complete open_fcats) [] (actives chart)
|
||||||
|
|||||||
Reference in New Issue
Block a user