Merge branch 'majestic' of github.com:GrammaticalFramework/gf-core into majestic

This commit is contained in:
Krasimir Angelov committed 2026-09-09 15:10:11 +02:00
commit adace7e5e8
24 files changed
+455 -221

No files matched your search

+5
View File
@@ -78,6 +78,7 @@ data Value
| VMarkup Ident [(Ident,Value)] [L Value]
| VReset Ident (Maybe Value) Value (Maybe QIdent)
| VSymCat Int LIndex [(LIndex, (Value, Type))]
| VSymVar Int Int
| VError Doc
| VInts Integer Bool
@@ -311,6 +312,7 @@ eval g env c (Markup tag as ts) [] =
in (VMarkup tag vas vs)
eval g env c (Reset ctl mb_ct t qid) [] = VReset ctl (fmap (\t -> eval g env c t []) mb_ct) (eval g env c t []) qid
eval g env c (TSymCat d r rs) []= VSymCat d r [(i,(fromJust (lookup pv env),ty)) | (i,(pv,ty)) <- rs]
eval g env c (TSymVar d j) []= VSymVar d j
eval g env c t@(Opts n cs) vs = if null cs
then VError ("No options in expression:" $$ ppTerm Unqualified 0 t)
else let (c1,c2,c3) = split3 c
@@ -439,6 +441,7 @@ bubble v = snd (bubble v)
bubble (VSymCat d i0 vs) =
let (union,vs') = mapAccumL descendC Map.empty vs
in (union, addVariants (VSymCat d i0 vs') union)
bubble v@(VSymVar _ _) = lift0 v
bubble v@(VError _) = lift0 v
bubble v@(VInts _ _) = lift0 v
@@ -577,6 +580,7 @@ patternMatch g s v0 ((env0,ps,args0,t):eqs) = match env0 ps eqs args0
(p, VP _ _ _) -> v0
(p, VS _ _ _) -> v0
(p, VSymCat _ _ _) -> v0
(p, VSymVar _ _) -> v0
(PP q qs, VApp r vs)
| q == r -> match env (qs++ps) eqs (vs++args)
(PR pas, VR as) -> matchRec env (reverse pas) as ps eqs args
@@ -1158,6 +1162,7 @@ ppValue q d (VReset ctl ct t _) = pp "[" <> pp ctl <>
pp "|" <> ppValue q 0 t <>
pp "]"
ppValue q d (VSymCat i r rs) = pp '<' <> pp i <> pp ',' <> pp r <> pp '>'
ppValue q d (VSymVar i j) = pp '<' <> pp i <> pp ',' <> pp '$' <> pp j <> pp '>'
ppValue q d (VError msg) = prec d 4 (pp "error" <+> ppTerm q 5 (K (show msg)))
ppValue q d (VInts n ext)
| ext = prec d 4 (pp "Ints" <+> brackets (pp n <> ".."))
@@ -258,6 +258,7 @@ force (VSymCat d r rs) = do
force_ (factor, (v, ty)) = do
v <- force v
return (factor, (v, ty))
force (VSymVar d j) = return (VSymVar d j)
force (VApp q vs) = do
vs <- mapM force vs
return (VApp q vs)
@@ -306,6 +307,8 @@ flatten subst (VStr s) = return (subst,[SymKS s])
flatten subst (VSymCat d r rs) = do
(subst,lin_index) <- params2int' subst r rs
return (subst,[SymCat d lin_index])
flatten subst (VSymVar d j) = do
return (subst,[SymVar d j])
flatten subst (VApp (m,id) [])
| m == cPredef && id == cBIND = return (subst,[SymBIND])
| m == cPredef && id == cSOFT_BIND = return (subst,[SymSOFT_BIND])
+1 -1
View File
@@ -50,7 +50,7 @@ grammar2haskell opts name gr = foldr (++++) [] $
derivingClause
| dataExt = "deriving (Show,Data)"
| otherwise = "deriving Show"
extraImports | gadt = ["import Control.Monad.Identity", "import Data.Monoid"]
extraImports | gadt = ["import Control.Monad.Identity", "import Control.Monad", "import Data.Monoid"]
| dataExt = ["import Data.Data"]
| otherwise = []
pgfImports = ["import PGF2", ""]
+2 -2
View File
@@ -77,8 +77,8 @@ class PGF_INTERNAL_DECL interval_map {
Node *upd_node(Node *node, Node *left, Node *right)
{
node->sz = 1+size(left)+size(right);
node->max = std::max((left == NULL) ? node->end : left->max,
(right == NULL) ? node->end : right->max);
node->max = std::max<size_t>((left == NULL) ? node->end : left->max,
(right == NULL) ? node->end : right->max);
node->left = left;
node->right = right;
return node;
+5 -1
View File
@@ -14,6 +14,8 @@ PgfAbstractParser::PgfAbstractParser(ref<PgfConcr> concr)
this->last_fid = concr->last_fid;
}
PgfAbstractParser::ItemProbComparator PgfAbstractParser::item_prob_comp;
void PgfAbstractParser::get_info(CCat *ccat, ref<PgfConcrRule> *prule, size_t **pvalues)
{
if (ccat->fid <= concr->last_fid) {
@@ -514,7 +516,7 @@ void PgfAbstractParser::combine(State *state, Item *item, CCat *ccat)
state->push_item(item);
}
bool PgfAbstractParser::ItemComparator::operator()(Item *item1, Item *item2)
bool PgfAbstractParser::ItemComparator::operator()(Item *item1, Item *item2) const
{
if (item1->rule.as_object() < item2->rule.as_object())
return true;
@@ -860,6 +862,8 @@ PgfParser::PgfParser(ref<PgfConcr> concr, PgfText *sentence, bool case_sensitive
this->allocated_size = sizeof(PgfText)+sentence->size+1;
}
PgfParser::ExprStateComparator PgfParser::estate_comp;
PgfParser::~PgfParser()
{
free(sentence);
+1 -1
View File
@@ -132,7 +132,7 @@ protected:
} item_prob_comp;
struct ItemComparator : std::less<Item*> {
bool operator()(Item *item1, Item *item2);
bool operator()(Item *item1, Item *item2) const;
};
struct Cont {
+1 -1
View File
@@ -1870,7 +1870,7 @@ public:
this->sym_index = (size_t) -1;
this->alt_index = (size_t) -1;
this->n_lindefs = n_rules;
this->n_linrefs = n_linrefs;
this->n_linrefs = 0;
this->n_args = 1;
this->rule_index = 0;
this->syms = 0;
+3 -1
View File
@@ -154,7 +154,9 @@ PgfProbspace probspace_delete_by_cat(PgfProbspace space, PgfText *cat,
return Node<PgfProbspaceEntry>::link(space,space->left,right);
} else {
itor->fn(itor, &space->value.fun->name, space->value.fun.as_object(), err);
PgfText *name = textdup(&space->value.fun->name);
itor->fn(itor, name, space->value.fun.as_object(), err);
free(name);
if (err->type != PGF_EXN_NONE)
return 0;
+1 -1
View File
@@ -82,7 +82,7 @@ PgfType PgfTypechecker::marshall_type(Type *ty, PgfUnmarshaller *u)
for (;;) {
Pi *pi = ty->is_pi();
if (pi) {
hypos = (PgfTypeHypo *) realloc(hypos, n_hypos*sizeof(PgfTypeHypo));
hypos = (PgfTypeHypo *) realloc(hypos, (n_hypos+1)*sizeof(PgfTypeHypo));
PgfTypeHypo *hypo = &hypos[n_hypos++];
hypo->bind_type = pi->bind_type;
hypo->cid = &pi->var;
Binary file not shown.
+21 -29
View File
@@ -19,48 +19,40 @@ concrete basic_cnc {
lincat Float = [
"s"
]
lindef Float(0) -> Float[String(0)] = [S0]
linref String(0) -> Float[Float(0)] = [S0]
lindef Float(0) -> Float[String(0)]; 0 : <0,0>
linref String(0) -> Float[Float(0)]; 0 : <0,0>
lincat Int = [
"s"
]
lindef Int(0) -> Int[String(0)] = [S0]
linref String(0) -> Int[Int(0)] = [S0]
lindef Int(0) -> Int[String(0)]; 0 : <0,0>
linref String(0) -> Int[Int(0)]; 0 : <0,0>
lincat N = [
"s"
]
lindef N(0) -> N[String(0)] = [S0]
linref {i<2} . String(0) -> N[N(i)] = [S0]
lindef N(0) -> N[String(0)]; 0 : <0,0>
linref {i<2} String(0) -> N[N(i)]; 0 : <0,0>
lincat P = [
"s"
]
lindef P(0) -> P[String(0)] = [S0]
linref String(0) -> P[P(0)] = [S0]
lindef P(0) -> P[String(0)]; 0 : <0,0>
linref String(0) -> P[P(0)]; 0 : <0,0>
lincat S = [
""
]
lindef S(0) -> S[String(0)] = [S0]
linref String(0) -> S[S(0)] = [S0]
lindef S(0) -> S[String(0)]; 0 : <0,0>
linref String(0) -> S[S(0)]; 0 : <0,0>
lincat String = [
"s"
]
lindef String(0) -> String[String(0)] = [S0]
linref String(0) -> String[String(0)] = [S0]
lin {i<2} . S(0) -> c[N(i)] = [S0]
lin S(0) -> floatLit[Float(0)] = [S0]
lin {i<2} . P(0) -> ind[P(0),P(0),N(i)] = [S1]
lin S(0) -> intLit[Int(0)] = [S0]
lin {i<2} . P(0) -> nat[N(i)] = [S5]
lin N(0) -> s[N(0)] = [S2]
lin N(0) -> s[N(1)] = [S4]
lin S(0) -> stringLit[String(0)] = [S0]
lin N(1) -> z[] = [S3]
sequences {
S0 = <0,0>
S1 = <0,0> "&" "λ" SOFT_BIND <1,$0> SOFT_BIND "," SOFT_BIND <1,$1> "." <1,0>
S2 = <0,0> "+" "1"
S3 = "0"
S4 = "1"
S5 = "nat" SOFT_BIND "(" SOFT_BIND <0,0> SOFT_BIND ")"
}
lindef String(0) -> String[String(0)]; 0 : <0,0>
linref String(0) -> String[String(0)]; 0 : <0,0>
lin {i<2} S(0) -> c[N(i)]; 0 : <0,0>
lin S(0) -> floatLit[Float(0)]; 0 : <0,0>
lin {i<2} P(0) -> ind[P(0),P(0),N(i)]; 0 : <0,0> "&" "λ" SOFT_BIND <1,$0> SOFT_BIND "," SOFT_BIND <1,$1> "." <1,0>
lin S(0) -> intLit[Int(0)]; 0 : <0,0>
lin {i<2} P(0) -> nat[N(i)]; 0 : "nat" SOFT_BIND "(" SOFT_BIND <0,0> SOFT_BIND ")"
lin N(0) -> s[N(1)]; 0 : "1"
lin N(0) -> s[N(0)]; 0 : <0,0> "+" "1"
lin S(0) -> stringLit[String(0)]; 0 : <0,0>
lin N(1) -> z[]; 0 : "0"
}
+1 -1
View File
@@ -24,7 +24,7 @@ main = do
,TestCase (assertInference "infer literal 3" gr (Right "String") "\"abc\"")
,TestCase (assertInference "infer meta 1" gr (Left "Cannot infer the type of a meta variable") "?")
,TestCase (assertInference "infer meta 2" gr (Right "N->N") "<? : N->N>")
,TestCase (assertInference "infer lambda" gr (Left "Cannot infer the type of a lambda abstraction") "\\x->x")
,TestCase (assertInference "infer lambda" gr (Left "Cannot infer the type of a lambda variable") "\\x->x")
,TestCase (assertChecking "check fun 1" gr (Right "s") "s" "N->N")
,TestCase (assertChecking "check fun 2" gr (Right "s z") "s z" "N")
,TestCase (assertChecking "check fun 3" gr (Left "Types doesn't match") "s z" "N->N")
+1 -1
View File
@@ -15,7 +15,7 @@ if on_windows:
cpath = '../c/pgf/'
extra_sources = [cpath+f for f in os.listdir(cpath) if f.endswith('.cxx')]
includes+=["../c"]
flags = ['/DCOMPILING_STATIC_PGF=1']
flags = ['/DCOMPILING_STATIC_PGF=1', "/std:c++20"]
else:
extra_sources = []
flags = ['-std=c99', '-Werror', '-Wno-error=unused-variable', '-Wno-comment']