{- |
Module      :  ./CASL/CompositionTable/ParseSparQ.hs
Description :  parsing SparQ CompositionTables
Copyright   :  (c) Christian Maeder and Uni Bremen 2002-2005
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  fmossa@informatik.uni-bremen.de
Stability   :  provisional
Portability :  portable

Parses CompositionTables in SparQ(Lisp)-Format using Parsec
 <http://www.cs.uu.nl/~daan/parsec.html>
-}

module CASL.CompositionTable.ParseSparQ where

import Text.ParserCombinators.Parsec
import CASL.CompositionTable.CompositionTable
import CASL.CompositionTable.Keywords
import Common.Parsec

import Data.Char

import qualified Control.Monad.Fail as Fail

parseSparQTableOld :: Parser Table
parseSparQTableOld :: Parser Table
parseSparQTableOld = Parser Table -> Parser Table
forall a. Parser a -> Parser a
inParens (Parser Table -> Parser Table) -> Parser Table -> Parser Table
forall a b. (a -> b) -> a -> b
$ do
  String
calculusName <- Parser String
parseCalculusName
  (i1 :: [Baserel]
i1, rs1 :: [Baserel]
rs1) <- Parser ([Baserel], [Baserel])
parseIdBaOths
  Conversetable
ct <- Parser Conversetable
parseConversetable
  (i2 :: [Baserel]
i2, rs2 :: [Baserel]
rs2) <- Parser ([Baserel], [Baserel])
parseIdBaOths
  Compositiontable
compt <- Parser Compositiontable
parseCompTable
  (i3 :: [Baserel]
i3, rs3 :: [Baserel]
rs3) <- Parser ([Baserel], [Baserel])
parseIdBaOths
  case [Baserel]
i1 [Baserel] -> [Baserel] -> [Baserel]
forall a. [a] -> [a] -> [a]
++ [Baserel]
i2 [Baserel] -> [Baserel] -> [Baserel]
forall a. [a] -> [a] -> [a]
++ [Baserel]
i3 of
    [i :: Baserel
i] -> Table -> Parser Table
forall (m :: * -> *) a. Monad m => a -> m a
return (Table -> Parser Table) -> Table -> Parser Table
forall a b. (a -> b) -> a -> b
$ Table_Attrs
-> Compositiontable
-> Conversetable
-> Reflectiontable
-> Models
-> Table
Table
      (String -> Baserel -> [Baserel] -> Table_Attrs
Table_Attrs String
calculusName Baserel
i ([Baserel] -> Table_Attrs) -> [Baserel] -> Table_Attrs
forall a b. (a -> b) -> a -> b
$ [Baserel]
rs1 [Baserel] -> [Baserel] -> [Baserel]
forall a. [a] -> [a] -> [a]
++ [Baserel]
rs2 [Baserel] -> [Baserel] -> [Baserel]
forall a. [a] -> [a] -> [a]
++ [Baserel]
rs3)
      Compositiontable
compt Conversetable
ct ([Reftabentry] -> Reflectiontable
Reflectiontable []) (Models -> Table) -> Models -> Table
forall a b. (a -> b) -> a -> b
$ [Model] -> Models
Models []
    [] -> String -> Parser Table
forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail "missing identity relation"
    is :: [Baserel]
is -> String -> Parser Table
forall (m :: * -> *) a. MonadFail m => String -> m a
Fail.fail (String -> Parser Table) -> String -> Parser Table
forall a b. (a -> b) -> a -> b
$ "non-unique identity relation " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Baserel] -> String
forall a. Show a => a -> String
show [Baserel]
is

parseIdBaOths :: Parser ([Baserel], [Baserel])
parseIdBaOths :: Parser ([Baserel], [Baserel])
parseIdBaOths = ([([Baserel], [Baserel])] -> ([Baserel], [Baserel]))
-> ParsecT String () Identity [([Baserel], [Baserel])]
-> Parser ([Baserel], [Baserel])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ l :: [([Baserel], [Baserel])]
l ->
   ((([Baserel], [Baserel]) -> [Baserel])
-> [([Baserel], [Baserel])] -> [Baserel]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([Baserel], [Baserel]) -> [Baserel]
forall a b. (a, b) -> a
fst [([Baserel], [Baserel])]
l, (([Baserel], [Baserel]) -> [Baserel])
-> [([Baserel], [Baserel])] -> [Baserel]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([Baserel], [Baserel]) -> [Baserel]
forall a b. (a, b) -> b
snd [([Baserel], [Baserel])]
l))
   (ParsecT String () Identity [([Baserel], [Baserel])]
 -> Parser ([Baserel], [Baserel]))
-> ParsecT String () Identity [([Baserel], [Baserel])]
-> Parser ([Baserel], [Baserel])
forall a b. (a -> b) -> a -> b
$ Parser ([Baserel], [Baserel])
-> ParsecT String () Identity [([Baserel], [Baserel])]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many Parser ([Baserel], [Baserel])
parseIdBaOth

parseIdBaOth :: Parser ([Baserel], [Baserel])
parseIdBaOth :: Parser ([Baserel], [Baserel])
parseIdBaOth = Parser ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall tok st a. GenParser tok st a -> GenParser tok st a
try (Parser ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel]))
-> Parser ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall a b. (a -> b) -> a -> b
$ do
  String
s <- Parser String
cWord
  case () of
    _ | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
identityRelationS
        -> do
            Baserel
i <- Parser Baserel
parseRelationId
            ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Baserel
i], [])
    _ | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
baseRelationsS
        -> do
            [Baserel]
rs <- Parser [Baserel] -> Parser [Baserel]
forall a. Parser a -> Parser a
inParens (Parser Baserel -> Parser [Baserel]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 Parser Baserel
parseRelationId)
            ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [Baserel]
rs)
    _ | String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
s [String
converseOperationS
            , String
compositionOperationS, String
homingOperationS, String
inverseOperationS
            , String
shortcutOperationS]
        -> Parser ([Baserel], [Baserel])
forall tok st a. GenParser tok st a
pzero
    _ | String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
parametricS
        -> Parser String -> ParsecT String () Identity ()
forall (m :: * -> *) a. Monad m => m a -> m ()
forget Parser String
word ParsecT String () Identity ()
-> Parser ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])
    _ -> (ParsecT String () Identity () -> ParsecT String () Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT String () Identity ()
parseQualifierBrace ParsecT String () Identity ()
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser String -> ParsecT String () Identity ()
forall (m :: * -> *) a. Monad m => m a -> m ()
forget Parser String
cWord)
         ParsecT String () Identity ()
-> Parser ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ([Baserel], [Baserel]) -> Parser ([Baserel], [Baserel])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])

parseQualifierBrace :: Parser ()
parseQualifierBrace :: ParsecT String () Identity ()
parseQualifierBrace = do
  String -> Parser String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "(" Parser String -> Parser String -> Parser String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> Parser String
forall st. String -> CharParser st String
tryString "#'("
  ParsecT String () Identity ()
skip
  ParsecT String () Identity () -> ParsecT String () Identity [()]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (ParsecT String () Identity () -> ParsecT String () Identity [()])
-> ParsecT String () Identity () -> ParsecT String () Identity [()]
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity ()
parseQualifierBrace ParsecT String () Identity ()
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ((Parser String
forall st. CharParser st String
stringLit Parser String -> Parser String -> Parser String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Char -> Parser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (String -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf ";()")) Parser String
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ()
skip)
  ParsecT String () Identity ()
cParenT

cKey :: String -> Parser ()
cKey :: String -> ParsecT String () Identity ()
cKey s :: String
s = String -> Parser String
forall st. String -> CharParser st String
tryString (':' Char -> String -> String
forall a. a -> [a] -> [a]
: String
s) Parser String
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ()
skip

cWord :: Parser String
cWord :: Parser String
cWord = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ':' ParsecT String () Identity Char -> Parser String -> Parser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser String
word

skip :: Parser ()
skip :: ParsecT String () Identity ()
skip = Parser String -> ParsecT String () Identity ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (Parser String -> ParsecT String () Identity ())
-> Parser String -> ParsecT String () Identity ()
forall a b. (a -> b) -> a -> b
$ ParsecT String () Identity Char -> Parser String
forall (m :: * -> *) a. Monad m => m a -> m [a]
single ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
space Parser String -> Parser String -> Parser String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> String -> Parser String
forall st. String -> String -> CharParser st String
nestedComment ";;#|" ";;|#"
  Parser String -> Parser String -> Parser String
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ';' ParsecT String () Identity Char -> Parser String -> Parser String
forall (m :: * -> *) a. Monad m => m a -> m [a] -> m [a]
<:> ParsecT String () Identity Char -> Parser String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (String -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
noneOf "\n")

parseCalculusName :: Parser String
parseCalculusName :: Parser String
parseCalculusName =
  String -> Parser String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
string "def-calculus" Parser String
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ()
skip ParsecT String () Identity () -> Parser String -> Parser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (String -> String) -> Parser String -> Parser String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (String -> String
forall a. [a] -> [a]
init (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. [a] -> [a]
tail) Parser String
forall st. CharParser st String
stringLit Parser String -> ParsecT String () Identity () -> Parser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m a
<< ParsecT String () Identity ()
skip

word :: Parser String
word :: Parser String
word = ParsecT String () Identity Char -> Parser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> String -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m Char
oneOf "_.-?" ParsecT String () Identity Char
-> ParsecT String () Identity Char
-> ParsecT String () Identity Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
digit) Parser String -> ParsecT String () Identity () -> Parser String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m a
<< ParsecT String () Identity ()
skip

oParenT :: Parser ()
oParenT :: ParsecT String () Identity ()
oParenT = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '(' ParsecT String () Identity Char
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ()
skip

cParenT :: Parser ()
cParenT :: ParsecT String () Identity ()
cParenT = Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char ')' ParsecT String () Identity Char
-> ParsecT String () Identity () -> ParsecT String () Identity ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity ()
skip

inParens :: Parser a -> Parser a
inParens :: Parser a -> Parser a
inParens p :: Parser a
p = ParsecT String () Identity ()
oParenT ParsecT String () Identity () -> Parser a -> Parser a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser a
p Parser a -> ParsecT String () Identity () -> Parser a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m a
<< ParsecT String () Identity ()
cParenT

parseCompTable :: Parser Compositiontable
parseCompTable :: Parser Compositiontable
parseCompTable = String -> ParsecT String () Identity ()
cKey String
compositionOperationS
  ParsecT String () Identity ()
-> Parser Compositiontable -> Parser Compositiontable
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser Compositiontable -> Parser Compositiontable
forall a. Parser a -> Parser a
inParens (([Cmptabentry] -> Compositiontable)
-> ParsecT String () Identity [Cmptabentry]
-> Parser Compositiontable
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Cmptabentry] -> Compositiontable
Compositiontable ParsecT String () Identity [Cmptabentry]
parseComptabentryList)

parseComptabentryList :: Parser [Cmptabentry]
parseComptabentryList :: ParsecT String () Identity [Cmptabentry]
parseComptabentryList = ParsecT String () Identity Cmptabentry
-> ParsecT String () Identity [Cmptabentry]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String () Identity Cmptabentry
parseComptabentry

parseComptabentry :: Parser Cmptabentry
parseComptabentry :: ParsecT String () Identity Cmptabentry
parseComptabentry = ParsecT String () Identity Cmptabentry
-> ParsecT String () Identity Cmptabentry
forall a. Parser a -> Parser a
inParens (ParsecT String () Identity Cmptabentry
 -> ParsecT String () Identity Cmptabentry)
-> ParsecT String () Identity Cmptabentry
-> ParsecT String () Identity Cmptabentry
forall a b. (a -> b) -> a -> b
$ do
  Baserel
rel1 <- Parser Baserel
parseRelationId
  Baserel
rel2 <- Parser Baserel
parseRelationId
  [Baserel]
results <- Parser [Baserel]
parseComptabentryResults
  Cmptabentry -> ParsecT String () Identity Cmptabentry
forall (m :: * -> *) a. Monad m => a -> m a
return (Cmptabentry_Attrs -> [Baserel] -> Cmptabentry
Cmptabentry (Baserel -> Baserel -> Cmptabentry_Attrs
Cmptabentry_Attrs Baserel
rel1 Baserel
rel2) [Baserel]
results)

parseComptabentryResults :: Parser [Baserel]
parseComptabentryResults :: Parser [Baserel]
parseComptabentryResults = Parser [Baserel] -> Parser [Baserel]
forall a. Parser a -> Parser a
inParens (Parser Baserel -> Parser [Baserel]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many Parser Baserel
parseRelationId)
  Parser [Baserel] -> Parser [Baserel] -> Parser [Baserel]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do
    result :: Baserel
result@(Baserel str :: String
str) <- Parser Baserel
parseRelationId
    [Baserel] -> Parser [Baserel]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Baserel] -> Parser [Baserel]) -> [Baserel] -> Parser [Baserel]
forall a b. (a -> b) -> a -> b
$ if (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper String
str String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "NIL" then [] else [Baserel
result]

parseConversetable :: Parser Conversetable
parseConversetable :: Parser Conversetable
parseConversetable = do
    [Contabentry_Ternary]
entry1 <- Parser [Contabentry_Ternary]
parseInverse
    [Contabentry_Ternary]
entry3 <- Parser [Contabentry_Ternary]
parseShortcut
    [Contabentry_Ternary]
entry2 <- Parser [Contabentry_Ternary]
parseHoming
    Conversetable -> Parser Conversetable
forall (m :: * -> *) a. Monad m => a -> m a
return (Conversetable -> Parser Conversetable)
-> Conversetable -> Parser Conversetable
forall a b. (a -> b) -> a -> b
$ [Contabentry_Ternary]
-> [Contabentry_Ternary] -> [Contabentry_Ternary] -> Conversetable
Conversetable_Ternary [Contabentry_Ternary]
entry1 [Contabentry_Ternary]
entry3 [Contabentry_Ternary]
entry2
  Parser Conversetable
-> Parser Conversetable -> Parser Conversetable
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ([Contabentry] -> Conversetable)
-> ParsecT String () Identity [Contabentry] -> Parser Conversetable
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Contabentry] -> Conversetable
Conversetable ParsecT String () Identity [Contabentry]
parseConverse

parseConverse :: Parser [Contabentry]
parseConverse :: ParsecT String () Identity [Contabentry]
parseConverse = String -> ParsecT String () Identity ()
cKey String
converseOperationS
  ParsecT String () Identity ()
-> ParsecT String () Identity [Contabentry]
-> ParsecT String () Identity [Contabentry]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity [Contabentry]
-> ParsecT String () Identity [Contabentry]
forall a. Parser a -> Parser a
inParens (ParsecT String () Identity Contabentry
-> ParsecT String () Identity [Contabentry]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String () Identity Contabentry
parseContabentry)

parseContabentry :: Parser Contabentry
parseContabentry :: ParsecT String () Identity Contabentry
parseContabentry = ParsecT String () Identity Contabentry
-> ParsecT String () Identity Contabentry
forall a. Parser a -> Parser a
inParens (ParsecT String () Identity Contabentry
 -> ParsecT String () Identity Contabentry)
-> ParsecT String () Identity Contabentry
-> ParsecT String () Identity Contabentry
forall a b. (a -> b) -> a -> b
$ do
  Baserel
id1 <- Parser Baserel
parseRelationId
  ([Baserel] -> Contabentry)
-> Parser [Baserel] -> ParsecT String () Identity Contabentry
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Baserel -> [Baserel] -> Contabentry
Contabentry Baserel
id1) (Parser [Baserel] -> ParsecT String () Identity Contabentry)
-> Parser [Baserel] -> ParsecT String () Identity Contabentry
forall a b. (a -> b) -> a -> b
$
    Parser Baserel -> Parser [Baserel]
forall (m :: * -> *) a. Monad m => m a -> m [a]
single Parser Baserel
parseRelationId Parser [Baserel] -> Parser [Baserel] -> Parser [Baserel]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser [Baserel]
parseBracedRelationIds

parseContabentryList :: String -> Parser [Contabentry_Ternary]
parseContabentryList :: String -> Parser [Contabentry_Ternary]
parseContabentryList s :: String
s = String -> ParsecT String () Identity ()
cKey String
s
  ParsecT String () Identity ()
-> Parser [Contabentry_Ternary] -> Parser [Contabentry_Ternary]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Parser [Contabentry_Ternary] -> Parser [Contabentry_Ternary]
forall a. Parser a -> Parser a
inParens (ParsecT String () Identity Contabentry_Ternary
-> Parser [Contabentry_Ternary]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT String () Identity Contabentry_Ternary
parseContabentryTernary)

parseContabentryTernary :: Parser Contabentry_Ternary
parseContabentryTernary :: ParsecT String () Identity Contabentry_Ternary
parseContabentryTernary = ParsecT String () Identity Contabentry_Ternary
-> ParsecT String () Identity Contabentry_Ternary
forall a. Parser a -> Parser a
inParens (ParsecT String () Identity Contabentry_Ternary
 -> ParsecT String () Identity Contabentry_Ternary)
-> ParsecT String () Identity Contabentry_Ternary
-> ParsecT String () Identity Contabentry_Ternary
forall a b. (a -> b) -> a -> b
$ do
  Baserel
id1 <- Parser Baserel
parseRelationId
  [Baserel]
ids <- Parser Baserel -> Parser [Baserel]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 Parser Baserel
parseRelationId Parser [Baserel] -> Parser [Baserel] -> Parser [Baserel]
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Parser [Baserel]
parseBracedRelationIds
  Contabentry_Ternary
-> ParsecT String () Identity Contabentry_Ternary
forall (m :: * -> *) a. Monad m => a -> m a
return (Baserel -> [Baserel] -> Contabentry_Ternary
Contabentry_Ternary Baserel
id1 [Baserel]
ids)

parseBracedRelationIds :: Parser [Baserel]
parseBracedRelationIds :: Parser [Baserel]
parseBracedRelationIds = Parser [Baserel] -> Parser [Baserel]
forall a. Parser a -> Parser a
inParens (Parser [Baserel] -> Parser [Baserel])
-> Parser [Baserel] -> Parser [Baserel]
forall a b. (a -> b) -> a -> b
$ Parser Baserel -> Parser [Baserel]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 Parser Baserel
parseRelationId

parseInverse :: Parser [Contabentry_Ternary]
parseInverse :: Parser [Contabentry_Ternary]
parseInverse = String -> Parser [Contabentry_Ternary]
parseContabentryList String
inverseOperationS

parseHoming :: Parser [Contabentry_Ternary]
parseHoming :: Parser [Contabentry_Ternary]
parseHoming = String -> Parser [Contabentry_Ternary]
parseContabentryList String
homingOperationS

parseShortcut :: Parser [Contabentry_Ternary]
parseShortcut :: Parser [Contabentry_Ternary]
parseShortcut = String -> Parser [Contabentry_Ternary]
parseContabentryList String
shortcutOperationS

parseRelationId :: Parser Baserel
parseRelationId :: Parser Baserel
parseRelationId =
  (String -> Baserel) -> Parser String -> Parser Baserel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Baserel
Baserel (ParsecT String () Identity Char -> Parser String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (ParsecT String () Identity Char -> Parser String)
-> ParsecT String () Identity Char -> Parser String
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy ((Char -> Bool) -> ParsecT String () Identity Char)
-> (Char -> Bool) -> ParsecT String () Identity Char
forall a b. (a -> b) -> a -> b
$ \ c :: Char
c ->
            Bool -> Bool
not (Char -> Bool
isSpace Char
c) Bool -> Bool -> Bool
&& Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
notElem Char
c "():;#'\"") Parser Baserel -> ParsecT String () Identity () -> Parser Baserel
forall (m :: * -> *) a b. Monad m => m a -> m b -> m a
<< ParsecT String () Identity ()
skip