Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
fe090e4
[ WIP ] mockup of rules instead of actors, in the middle of the seman…
fredrikNordvallForsberg Oct 5, 2022
34582c9
snapshot of current work
JacquesCarette Oct 5, 2022
1303b4b
a good day's work on rules and citizens
JacquesCarette Oct 5, 2022
fd8590e
[ WIP ] more design for rules and judg(e)ments
maltenmuller Oct 7, 2022
de5ea6a
[ WIP ] towards representing concrete and abstract rules
fredrikNordvallForsberg Oct 10, 2022
84aae7f
[ WIP ] towards parsing rules
g-nakov Oct 10, 2022
39dc5e2
[ WIP ] judgement form parsing
g-nakov Oct 19, 2022
65ce92b
[ WIP ] elaborating judgement form declations
fredrikNordvallForsberg Oct 21, 2022
0b78635
[ wip ] elaboration cont.
g-nakov Oct 28, 2022
9e576a8
[ WIP ] protocol fix, onto syntaxDesc -> semanticsDesc
g-nakov Nov 2, 2022
218c859
[ fix ] impossible error in ssyntaxdesc
g-nakov Nov 2, 2022
321727a
[ fix ] back to building
gallais Nov 4, 2022
b4d21e6
[ minor ] contextual info for judgementform
gallais Nov 4, 2022
40bf58e
[ rule ] error reporting for citizen vs. subject mismatch
gallais Nov 4, 2022
43244fb
Update Src/Elaboration/Pretty.hs
gallais Nov 4, 2022
dc7da1d
[ fix ] better error messages
gallais Nov 5, 2022
b86d8ba
[ wip ] progress on elaborating judgement forms
fredrikNordvallForsberg Nov 9, 2022
c9f9a9e
better malformed op error
fredrikNordvallForsberg Nov 9, 2022
569b568
[ broken ] towards proper Semantics
fredrikNordvallForsberg Nov 9, 2022
aaf96a5
[ wip ] polymorphic headUpData
g-nakov Nov 23, 2022
b68d0c1
[ wip ] validating semantics via typechecking
g-nakov Nov 25, 2022
734d03c
[ wip ] further progress / regression
g-nakov Nov 30, 2022
da55c25
[ wip ] small fixes, still not compiling
g-nakov Dec 2, 2022
40d6997
[ wip ] towards scope checking operator declarations (courtesy of @Fred)
g-nakov Dec 2, 2022
2394448
[ wip ] fixing (and introducing) errors in elaboration
g-nakov Dec 7, 2022
d97d818
[ wip ] elaboration cont.
g-nakov Dec 9, 2022
2610c52
[ fix ] errors with pretty printing
g-nakov Jan 19, 2023
e4c7774
[ fix ] some undefined values to get past errors
g-nakov Jan 19, 2023
7de5d7f
[ more ] isList, sop, itm, (parts of) stm
gallais Jan 19, 2023
c7bb318
[ refactor ] making mangleActors generic over the meta type
g-nakov Jan 24, 2023
b02233d
[ new ] itm definition
g-nakov Jan 24, 2023
c0dd134
[ new ] beginning of a LexicalScope
g-nakov Jan 26, 2023
445ff41
[ more ] type fixing
gallais Jan 31, 2023
cfc19c5
[ done ] change meaning of thinned patterns in spat et al
fredrikNordvallForsberg Jan 31, 2023
9b34b08
[ fix ] it compiles!
fredrikNordvallForsberg Feb 2, 2023
2707475
[ broken ] DefnOp, and its telescopic nature, is hard
gallais Feb 2, 2023
cdabccb
[ done ] fixing sdeclOps
gallais Feb 7, 2023
42d6389
[ more ] sparam
fredrikNordvallForsberg Feb 7, 2023
2ece2fd
[ more ] towards elaborating operator definitions
fredrikNordvallForsberg Feb 9, 2023
7846695
[ done ] (hopefully) with defnop
gallais Feb 16, 2023
5768b0f
[ stm ] universe checking for atoms
gallais Feb 16, 2023
c7b6c03
[ todo ] WithRange Complaint
gallais Feb 16, 2023
959833d
[ debug ] added typecheck command
fredrikNordvallForsberg Feb 16, 2023
e3b6900
[ refactor ] get rid of HasGetRange Complaint
gallais Feb 16, 2023
ca39ad8
[ refactor ] get rid of HasGetRange Warning
gallais Feb 16, 2023
135695c
[ fix ] some scope issues
gallais Feb 21, 2023
5b4611d
[ unfix ] broke substitutions
g-nakov Feb 21, 2023
b73b90b
[ broken ] thun fails hard
gallais Feb 23, 2023
0291db8
[ debug ] found the issue!
gallais Feb 23, 2023
885695f
[ TODO ] Refactor this bug fix in a clean manner
gallais Feb 23, 2023
c8fb36e
[ refactor ] last week's dodgy-looking elabUnders
gallais Feb 28, 2023
0a2f4ad
[ fix ] scope of context stack decls & binder annotations
gallais Feb 28, 2023
225f9e6
[ fix ] got STLC working!
gallais Mar 7, 2023
1cdb00b
[ fix ] got stlc2 working!
gallais Mar 7, 2023
9446f92
[ cleanup ] got stlc3 working!
gallais Mar 7, 2023
5ec64bc
[ fix ] got stlctpp working!
gallais Mar 7, 2023
42bdc93
[ fix ] got stlctpp2 working!
gallais Mar 7, 2023
f98428f
[ fix ] got krivine2 working!
gallais Mar 7, 2023
38cb835
[ test ] updating some golden files
gallais Mar 7, 2023
d80e8bc
[ debugging ] HasCallStack for all uses of thun
fredrikNordvallForsberg Mar 8, 2023
34e5698
got elaboration.act working!
fredrikNordvallForsberg Mar 9, 2023
e0d1912
[ fix ] got mlttList working!
gallais Mar 14, 2023
da25243
[ fix ] scopecheck thinning elaboration
gallais Mar 14, 2023
72bfa75
[ fix ] missing range info in smeta
gallais Mar 14, 2023
dfe40a6
[ fix ] printing open terms in error messages
gallais Mar 14, 2023
8a7f8ea
[ fix ] more now working test cases
fredrikNordvallForsberg Mar 14, 2023
433302f
[ fix ] bring back clause tracing
gallais Mar 16, 2023
3934124
towards bringing back judgement declarations
fredrikNordvallForsberg Mar 16, 2023
12c57fe
[ bug ] alarm-causing test case
gallais Mar 21, 2023
40fe9c7
[ doc ] matchObjType
gallais Mar 21, 2023
4ab3a40
[ TODO ] type annotations for operator objects
gallais Mar 21, 2023
f5fea2d
[ breaking ] insist on binding the obj name in op decl
gallais Mar 21, 2023
570ec1e
[ cleanup ] unused imports
gallais Mar 21, 2023
64dab28
[ broken ] more uniform operator declaration
gallais Mar 21, 2023
7f84d11
[ fix ] checking judgement form telescopically
gallais Mar 21, 2023
cae7116
[ broken ] subject should become citizen after sub send
gallais Mar 21, 2023
a564d57
[ test ] update test cases
fredrikNordvallForsberg Mar 23, 2023
377a10a
[ todo ] add todo
fredrikNordvallForsberg Mar 23, 2023
b76a366
[ fix ] checking optional patterns in judgements
fredrikNordvallForsberg Mar 23, 2023
1534176
[ testing ] excluded directories, and fix README.md
fredrikNordvallForsberg Mar 23, 2023
3732063
Merge branch 'main' into rules
gallais Mar 23, 2023
a948991
[ cleanup ] remove filepath printing
gallais Mar 23, 2023
9683c37
[ fix ] disallow matching on the universe
gallais Mar 24, 2023
24ac4dc
radicals and types in operators
fredrikNordvallForsberg Mar 28, 2023
8d921bb
[ test ] add missing golden file
fredrikNordvallForsberg Mar 29, 2023
dd6f862
separate examples/stlcRules.act and test/stlcRules.act, which explore…
fredrikNordvallForsberg Mar 31, 2023
bb3998d
[ emacs ] add missing '=>' symbol
gallais Apr 6, 2023
5ff1f3e
Merge branch 'main' into actual-rules
gallais Apr 13, 2023
aac50de
[ syntax ] wondering about named telescopic things
fredrikNordvallForsberg Apr 13, 2023
287ea2a
[ doc ] design decisions on telescopes' syntax
gallais Apr 18, 2023
80aeb58
[ cleanup ] examples, tests
gallais Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 151 additions & 6 deletions Src/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import Control.Monad.Reader
import Control.Monad.State

import Data.Bifunctor (bimap, first)
import Data.Char (isSpace)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe, catMaybes)
import Data.Traversable (for)
import Data.Foldable (asum)
import qualified Data.Set as Set
import Data.These (These(..), mergeThese)

import Actor
import Actor.Display ()
Expand All @@ -32,19 +36,23 @@ import Machine.Trace (Shots)
import Options
import Parse
import Pretty
import Rules
import Syntax
import Term.Base
import Unelaboration.Monad (Unelab(..), Naming, subunelab, withEnv)
import Unelaboration (initDAEnv, declareChannel)
import Location

import Data.Char (isSpace)
import Operator
import Thin
import Operator.Eval (HeadUpData' (..))
import Hide (Hide(..))
import Scope (Scope(..))

import Utils
import Data.Either (partitionEithers)
import Data.List (sort, sortBy)
import Data.Function (on)

type family DEFNPROTOCOL (ph :: Phase) :: *
type instance DEFNPROTOCOL Concrete = ()
type instance DEFNPROTOCOL Abstract = AProtocol
Expand Down Expand Up @@ -76,6 +84,8 @@ data COMMAND (ph :: Phase)
| Trace [MachineStep]
| OpBlock [OPENTRY ph]
| Typecheck (TERM ph) (SEMANTICSDESC ph)
| DeclJudgementForm (JUDGEMENTFORM ph)
| DeclRule (RULE ph)

deriving instance
( Show (JUDGEMENTNAME ph)
Expand All @@ -99,6 +109,8 @@ deriving instance
, Show (DEFNPROTOCOL ph)
, Show (LOOKEDUP ph)
, Show (DEFNOP ph)
, Show (JUDGEMENTFORM ph)
, Show (RULE ph)
, Show (GUARD ph)) =>
Show (COMMAND ph)

Expand Down Expand Up @@ -127,6 +139,13 @@ instance Display AProtocol where
instance Pretty CStatement where
pretty (Statement jd vars) = hsep $ pretty jd : (pretty <$> vars)

instance Pretty (PLACE Concrete) where
pretty (v, CitizenPlace) = pretty v
pretty (v, SubjectPlace (WithRange _ syntaxcat) (semanticsdesc, _)) =
parens $ hsep $ [ pretty v, ":", pretty syntaxcat ]
++ (("=>" <+> pretty semanticsdesc)
<$ guard (At unknown syntaxcat /= semanticsdesc))

instance Pretty CCommand where
pretty = let prettyCds cds = collapse (BracesList $ pretty <$> cds) in \case
DeclJudge em jd p -> hsep [pretty em <> pretty jd, colon, pretty p]
Expand All @@ -140,6 +159,9 @@ instance Pretty CCommand where
, prettyCds posts]
Go a -> keyword "exec" <+> pretty a
Trace ts -> keyword "trace" <+> collapse (BracesList $ map pretty ts)
DeclJudgementForm j -> keyword "judgementform" <+> collapse (BracesList $ pretty <$> jpreconds j)
<+> hsep (pretty (jname j) : map pretty (jplaces j))
<+> collapse (BracesList $ either pretty pretty <$> jpostconds j)
Typecheck t ty -> keyword "typecheck" <+> pretty t <+> ":" <+> pretty ty

instance Unelab ACommand where
Expand Down Expand Up @@ -196,6 +218,8 @@ pcommand
<* pspc <*> pconditions
<|> Go <$ plit "exec" <* pspc <*> pACT
<|> Trace <$ plit "trace" <*> pcurlies (psep (ppunc ",") pmachinestep)
<|> DeclJudgementForm <$> pjudgementform
<|> DeclRule <$> prule
<|> OpBlock <$ plit "operator"
<*> pcurlies (psep (ppunc ";") (DeclOp <$> panoperator <|> DefnOp <$> pdefnop))
<|> Typecheck <$ plit "typecheck" <* pspc <*> pTM <* ppunc ":" <*> pTM
Expand Down Expand Up @@ -278,6 +302,7 @@ sdeclOp (AnOperator (objBinder, objDescPat) (WithRange r opname) paramDescs retD
(paramDescs, ds) <- sparamdescs paramDescs
retDesc <- local (setDecls ds) $ sty retDesc
pure $ AnOperator (objName, descPat) opname paramDescs retDesc
-- Process the rest of the declarations, in the original context
local (addOperator op) $ (op,) <$> asks globals

scommand :: CCommand -> Elab (ACommand, Globals)
Expand Down Expand Up @@ -321,16 +346,136 @@ scommand = \case
(ContractStack pres (stk, lhs, rhs) posts,) <$> asks globals
Go a -> during ExecElaboration $ (,) . Go <$> local (setElabMode Execution) (sact a) <*> asks globals
Trace ts -> (Trace ts,) <$> asks globals
DeclJudgementForm j -> do
(j , gs) <- sjudgementform j
pure (DeclJudgementForm j, gs)
Typecheck t ty -> do
ty <- sty ty
t <- stm DontLog ty t
g <- asks globals
pure (Typecheck t ty, g)

-- Sig S \x.T - 'fst ~> S
-- (p : Sig S \x.T) - 'snd ~> {x=[ p - 'fst ]}T
OpBlock ops -> first OpBlock <$> sopBlock ops

checkCompatiblePlaces :: [PLACE Concrete] ->
[(Variable, ASemanticsDesc)] ->
[(Variable, ASemanticsDesc)] ->
Elab ()
checkCompatiblePlaces places inputs outputs = do
-- Make sure subject protocol can be found unambiguously
let names = map fst places
let citizenNames = [x | (x, CitizenPlace) <- places]
let inputNames = map fst inputs
let outputNames = map fst outputs
whenLeft (allUnique names) $ \ a -> throwComplaint a $ DuplicatedPlace a
inputNamesSet <- case allUnique inputNames of
Left a -> throwComplaint a $ DuplicatedInput a
Right as -> pure as
outputNamesSet <- case allUnique outputNames of
Left a -> throwComplaint a $ DuplicatedOutput a
Right as -> pure as
whenCons (Set.toList (Set.intersection inputNamesSet outputNamesSet)) $ \ a _ ->
throwComplaint a $ BothInputOutput a
whenCons (mismatch citizenNames inputNames outputNames) $ \ (v, m) _ ->
throwComplaint v (ProtocolCitizenSubjectMismatch v m)
where
mismatch :: [Variable]
-> [Variable]
-> [Variable]
-> [(Variable, Mode ())]
mismatch cs is os =
catMaybes $ alignWith check (sort cs)
$ sortBy (compare `on` fst)
$ map (, Input) is ++ map (, Output) os

check :: These Variable (Variable, Mode ()) -> Maybe (Variable, Mode ())
check (These a b) = (a, Subject ()) <$ guard (a /= fst b)
check t = Just (mergeThese const (first (, Subject ()) t))


{-
Do not use operators to compute citizens from subjects.
Rather, transmit glued subject-citizen pairs,
when matching a subject, glue metavars to pattern vars
then use s => c clauses ub rules to constrain the citizen
the parent sent with the subject syntax.
-}

sjudgementform :: JUDGEMENTFORM Concrete
-> Elab (JUDGEMENTFORM Abstract, Globals)
sjudgementform JudgementForm{..} = during (JudgementFormElaboration jname) $ do
inputs <- concat <$> traverse subjects jpreconds -- TODO: should really be the closure of this info
let (outputs, operators) = partitionEithers jpostconds
outputs <- concat <$> traverse subjects outputs
checkCompatiblePlaces jplaces inputs outputs
(ps, subjectKinds, _) <- citizenJudgements Map.empty inputs outputs jplaces
let protocol = Protocol ps
jname <- isFresh jname
local (declare (Used jname) (AJudgement jextractmode protocol)) $ do
(operators, gs) <- sopBlock . map DeclOp =<< traverse (kindify subjectKinds) operators
pure ((jextractmode, jname, protocol), gs)


where
subjects :: JUDGEMENT Concrete -> Elab [(Variable, ASemanticsDesc)]
subjects (Judgement r name fms) = do
IsJudgement{..} <- isJudgement name
xs <- case halfZip (getProtocol judgementProtocol) fms of
Just xs -> pure xs
Nothing -> throwComplaint r $ JudgementWrongArity judgementName judgementProtocol fms
let ys = [ (fm, sem) | ((Subject _, sem), fm) <- xs ]
forM ys $ \case
-- TODO: should use something like `isSendableSubject`
(CFormula (These _ (Var r x)), sem) -> pure (x, sem)
(x, _) -> throwComplaint r $ UnexpectedNonSubject x

citizenJudgements :: Map Variable RawP
-> [(Variable, ASemanticsDesc)]
-> [(Variable, ASemanticsDesc)]
-> [CPlace]
-> Elab ( [AProtocolEntry]
, Map Variable RawP
, Decls )
citizenJudgements mp inputs outputs [] = ([], mp,) <$> asks declarations
citizenJudgements mp inputs outputs ((name, place) : plcs) = case place of
CitizenPlace -> do
bd <- Used <$> isFresh name
th <- asks (ones . scopeSize . objVars)
case (lookup name inputs, lookup name outputs) of
(Just isem, Nothing) -> do
(_, asot) <- thickenedASOT (getRange name) th isem
(ps, mp, ds) <- local (declare bd (ActVar IsNotSubject asot)) $
citizenJudgements mp inputs outputs plcs
pure ((Input, isem) : ps, mp, ds)
(Nothing, Just osem) -> do
(_, asot) <- thickenedASOT (getRange name) th osem
(ps, mp, ds) <- local (declare bd (ActVar IsNotSubject asot)) $
citizenJudgements mp inputs outputs plcs
pure ((Output, osem) : ps, mp, ds)
_ -> error "Impossible in citizenJudgement"

SubjectPlace (WithRange r rsyn) (sem, msempat) -> do
syndecls <- gets (Map.keys . syntaxCats)
unless (rsyn `elem` syndecls) $
throwComplaint r $ InvalidSubjectSyntaxCat rsyn syndecls
syn <- satom rsyn
-- TODO: we use underScore here if the type is not a valid pattern, eg a stuck neutral. It would be good to do better.
mp <- pure (Map.insert name (fromMaybe (UnderscoreP unknown) msempat) mp)
(ps, mp, ds) <- citizenJudgements mp inputs outputs plcs
sem <- local (setDecls ds) $ sty sem
pure ((Subject syn, sem) : ps, mp, ds)

kindify :: Map Variable RawP -> CAnOperator -> Elab CAnOperator
kindify m op
| (Used x, pat) <- objDesc op
, Just sempat <- Map.lookup x m
= do
case pat of
UnderscoreP _ -> pure ()
_ -> when (pat /= sempat) $ throwComplaint pat $ MismatchedObjectPattern (theValue (opName op)) pat sempat
pure (op { objDesc = (Used x, sempat) })
| otherwise = throwComplaint (fst $ objDesc op)
$ MalformedPostOperator (theValue (opName op)) (Map.keys m)

sopBlock :: [OPENTRY Concrete] -> Elab ([OPENTRY Abstract], Globals)
sopBlock [] = ([],) <$> asks globals
sopBlock (DefnOp (rp, opelims@((rpty,_,_):_), rhs) : rest) = do
Expand Down
4 changes: 3 additions & 1 deletion Src/Concrete/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,15 @@ data ExtractMode
deriving (Show, Eq)

data Keyword
= KwSyntax | KwExec | KwTrace
= KwSyntax | KwRule | KwJudgementForm | KwExec | KwTrace
| KwLet | KwCase | KwLookup | KwCompare
| KwBREAK | KwPRINT | KwPRINTF
deriving (Enum, Bounded)

instance Show Keyword where
show KwSyntax = "syntax"
show KwRule = "rule"
show KwJudgementForm = "judgementform"
show KwExec = "exec"
show KwTrace = "trace"
show KwLet = "let"
Expand Down
5 changes: 3 additions & 2 deletions Src/Elaboration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import Control.Applicative ((<|>))
import Operator
import Operator.Eval
import Semantics
-- import Debug.Trace (traceShow, traceShowId, trace)
import Data.Bifunctor (bimap)
import GHC.Stack.Types (HasCallStack)

-- import Debug.Trace (traceShow, traceShowId, trace)

type CPattern = PATTERN Concrete
type APattern = PATTERN Abstract

Expand Down Expand Up @@ -518,7 +519,7 @@ itms :: Range -> String -> Usage
--
-> Elab (ASemanticsDesc -- Instantiated return type
, [ACTm]) -- Elaborated parameters
itms r op usage [] [] rdesc = (, []) <$> instantiateDesc r rdesc
itms r op usage [] [] rdesc = (, []) <$> (instantiateDesc r rdesc)
itms r op usage ((binder, sot):bs) (rp:rps) rdesc = do
(ovs :=> desc) <- instantiateSOT (getRange rp) sot
(p, dat) <- sparam usage binder B0 (discharge ovs desc) rp
Expand Down
23 changes: 22 additions & 1 deletion Src/Elaboration/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Thin
import Term.Base
import Utils
import Operator
import Rules
import Info
import Pattern
import Hide
Expand Down Expand Up @@ -309,10 +310,19 @@ declareObjVar :: ( {- x :: -} String
-> Context {- gamma, x :: S -}
declareObjVar (x, sem) ctx =
-- We store semantics descs ready to be deployed at use sites
let scp = getObjVars (objVars ctx) :< ObjVar x sem in
let scp = getObjVars (objVars ctx) :< ObjVar x sem
dat = headUpData ctx
in
ctx { objVars = ObjVars (fmap weak <$> scp)
, binderHints = fmap weak <$> binderHints ctx
, headUpData = dat { huEnv = weakenEnvWith x (huEnv dat) }
}
where
-- we extend the global scope so that mangleActors will bring the
-- operator types into local scope during instantiation
weakenEnvWith :: String -> Env' m -> Env' m
weakenEnvWith x env = env { globalScope = globalScope env :< x}


-- Careful! The new ovs better be a valid scope
-- i.e. all the objvars mentioned in the SemanticsDesc of
Expand Down Expand Up @@ -505,6 +515,17 @@ data Complaint
| ProtocolsNotDual AProtocol AProtocol
| IncompatibleModes AProtocolEntry AProtocolEntry
| WrongDirection AProtocolEntry Ordering AProtocolEntry
-- judgementforms
| JudgementWrongArity JudgementName AProtocol [CFormula]
| UnexpectedNonSubject CFormula
| DuplicatedPlace Variable
| DuplicatedInput Variable
| DuplicatedOutput Variable
| BothInputOutput Variable
| ProtocolCitizenSubjectMismatch Variable (Mode ())
| MalformedPostOperator String [Variable]
| MismatchedObjectPattern String RawP RawP
| InvalidSubjectSyntaxCat SyntaxCat [SyntaxCat]
-- syntaxes
| AlreadyDeclaredSyntaxCat SyntaxCat
-- syntaxdesc validation
Expand Down
31 changes: 29 additions & 2 deletions Src/Elaboration/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Data.Foldable

import ANSI hiding (withANSI)
import Actor (ActorMeta'(..), ActorMeta, Channel(..), Stack(..), AProtocol)
import Concrete.Base (Binder (..), PROTOCOL(Protocol))
import Concrete.Base (Binder (..), PROTOCOL(Protocol), Mode (..))
import Concrete.Pretty()
import Elaboration.Monad
import Location
Expand Down Expand Up @@ -156,6 +156,32 @@ instance Pretty (WithRange Complaint) where
WrongDirection m1 dir m2 -> hsep ["Wrong direction", pretty (show dir)
, "between", pretty (WithVarNames B0 <$> m1)
, "and", pretty (WithVarNames B0 <$> m2)]
-- judgementforms
JudgementWrongArity name (Protocol protocol) fms ->
let applied = (if length protocol > length fms then "under" else "over") <> "-applied" in
hsep ["Judgement", pretty name, applied]
UnexpectedNonSubject fm -> hsep ["Unexpected non-subject", pretty fm]
DuplicatedPlace v -> hsep [pretty v, "is a duplicated place" ]
DuplicatedInput v -> hsep [pretty v, "is a duplicated input"]
DuplicatedOutput v -> hsep [pretty v, "is a duplicated output"]
BothInputOutput v -> hsep [pretty v, "is both an input and an output"]
ProtocolCitizenSubjectMismatch v m ->
let (seen, unseen) = case m of
Input -> ("an input", "not as a subject")
Subject{} -> ("a subject", "neither as an input nor an output")
Output -> ("an output", "not as a subject")
in hsep ["Found", pretty v, "as", seen, "but", unseen ]
MalformedPostOperator op cands ->
let message = case cands of [x] -> "the subject"
_ -> "a subject among" in
hsep $ ["Malformed operator", pretty op <> "; expected it to act on", message] ++ punctuate ", " (map pretty cands)
MismatchedObjectPattern op got expected ->
vcat [ hsep ["Mismatched object type pattern in operator declaration of ", pretty op <> "."]
, hsep ["Expected", pretty expected, "but got", pretty got]
]
InvalidSubjectSyntaxCat got known -> vcat [hsep ["Invalid subject syntax category", pretty got]
, hsep ("Expected one among" : punctuate ", " (map pretty known))
]
-- syntaxes
AlreadyDeclaredSyntaxCat x -> hsep ["The syntactic category", pretty x, "is already defined"]

Expand All @@ -166,7 +192,8 @@ instance Pretty (WithRange Complaint) where
hsep [ "Incompatible semantics descriptions, expected"
, prettyPrec 1 desc
, "but got"
, prettyPrec 1 desc']
, prettyPrec 1 desc'
]
IncompatibleSyntaxInfos info1 info2 ->
hsep ["Syntax infos" , pretty (WithVarNames B0 <$> info1)
, "and", pretty (WithVarNames B0 <$> info2)
Expand Down
Loading