take into account the order in which CAPIT && ALL_CAPIT appears

This commit is contained in:
krangelov
2021-12-03 11:40:00 +01:00
parent df82e1e7ca
commit 0132a70b94
2 changed files with 21 additions and 17 deletions

View File

@@ -42,8 +42,7 @@ PgfLinearizer::PgfLinearizer(ref<PgfConcr> concr, PgfMarshaller *m) {
this->root = NULL; this->root = NULL;
this->first = NULL; this->first = NULL;
this->args = NULL; this->args = NULL;
this->capit = false; this->capit = CAPIT_NONE;
this->allcapit = false;
this->pre_stack = NULL; this->pre_stack = NULL;
}; };
@@ -195,7 +194,6 @@ void PgfLinearizer::flush_pre_stack(PgfLinearizationOutputIface *out, PgfText *t
out->symbol_bind(); out->symbol_bind();
capit = pre->capit; capit = pre->capit;
allcapit = pre->allcapit;
delete pre; delete pre;
} }
@@ -262,7 +260,11 @@ void PgfLinearizer::linearize(PgfLinearizationOutputIface *out, TreeNode *node,
flush_pre_stack(out, &sym_ks->token); flush_pre_stack(out, &sym_ks->token);
if (capit) { switch (capit) {
case CAPIT_NONE:
out->symbol_token(&sym_ks->token);
break;
case CAPIT_FIRST: {
PgfText *cap = (PgfText *) alloca(sizeof(PgfText)+sym_ks->token.size+6); PgfText *cap = (PgfText *) alloca(sizeof(PgfText)+sym_ks->token.size+6);
const uint8_t *p = (const uint8_t *) sym_ks->token.text; const uint8_t *p = (const uint8_t *) sym_ks->token.text;
@@ -280,8 +282,10 @@ void PgfLinearizer::linearize(PgfLinearizationOutputIface *out, TreeNode *node,
cap->size = q - (uint8_t *) cap->text; cap->size = q - (uint8_t *) cap->text;
out->symbol_token(cap); out->symbol_token(cap);
capit = false; capit = CAPIT_NONE;
} else if (allcapit) { break;
}
case CAPIT_ALL: {
PgfText *cap = (PgfText *) alloca(sizeof(PgfText)+sym_ks->token.size*6); PgfText *cap = (PgfText *) alloca(sizeof(PgfText)+sym_ks->token.size*6);
const uint8_t *p = (const uint8_t *) sym_ks->token.text; const uint8_t *p = (const uint8_t *) sym_ks->token.text;
@@ -300,9 +304,9 @@ void PgfLinearizer::linearize(PgfLinearizationOutputIface *out, TreeNode *node,
out->symbol_token(cap); out->symbol_token(cap);
allcapit = false; capit = CAPIT_NONE;
} else { break;
out->symbol_token(&sym_ks->token); }
} }
break; break;
} }
@@ -330,15 +334,15 @@ void PgfLinearizer::linearize(PgfLinearizationOutputIface *out, TreeNode *node,
break; break;
case PgfSymbolCAPIT::tag: case PgfSymbolCAPIT::tag:
if (pre_stack == NULL) if (pre_stack == NULL)
capit = true; capit = CAPIT_FIRST;
else else
pre_stack->capit = true; pre_stack->capit = CAPIT_FIRST;
break; break;
case PgfSymbolALLCAPIT::tag: case PgfSymbolALLCAPIT::tag:
if (pre_stack == NULL) if (pre_stack == NULL)
allcapit = true; capit = CAPIT_ALL;
else else
pre_stack->allcapit = true; pre_stack->capit = CAPIT_ALL;
break; break;
} }
} }

View File

@@ -46,16 +46,16 @@ class PGF_INTERNAL_DECL PgfLinearizer : public PgfUnmarshaller {
TreeNode *first; TreeNode *first;
TreeNode *args; TreeNode *args;
bool capit; enum CapitState { CAPIT_NONE, CAPIT_FIRST, CAPIT_ALL };
bool allcapit;
CapitState capit;
struct PreStack { struct PreStack {
PreStack *next; PreStack *next;
TreeNode *node; TreeNode *node;
ref<PgfSymbolKP> sym_kp; ref<PgfSymbolKP> sym_kp;
bool bind; bool bind;
bool capit; CapitState capit;
bool allcapit;
}; };
PreStack *pre_stack; PreStack *pre_stack;