/* Decides which attributes are admissible */
VflOrientation orientation;
VflView *leading_super;
VflView *trailing_super;
VflView *current_view;
VflView *views;
};
/* NOTE: These two symbols are defined in gtkconstraintlayout.h, but we *cannotincludethatheaderhere
*/ #define GTK_CONSTRAINT_VFL_PARSER_ERROR (gtk_constraint_vfl_parser_error_quark ())
GQuark gtk_constraint_vfl_parser_error_quark (void);
if (*cur == '=')
{
*relation = GTK_CONSTRAINT_RELATION_EQ;
*endptr = (char *) cur + 1; returnTRUE;
}
goto out;
} elseif (*cur == '>')
{
cur += 1;
if (*cur == '=')
{
*relation = GTK_CONSTRAINT_RELATION_GE;
*endptr = (char *) cur + 1; returnTRUE;
}
goto out;
} elseif (*cur == '<')
{
cur += 1;
if (*cur == '=')
{
*relation = GTK_CONSTRAINT_RELATION_LE;
*endptr = (char *) cur + 1; returnTRUE;
}
goto out;
}
out:
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_RELATION, "Unknown relation; must be one of '==', '>=', or '<='"); returnFALSE;
}
while (g_ascii_isalnum (*end) || *end == '_')
end += 1;
char *name = g_strndup (name_start, end - name_start);
/* We only accept view names if the subject of the predicate *isaview,i.e.wedonotallowviewnamesinsideaspacing *predicate
*/ if (predicate->subject == NULL)
{ if (parser->metrics_set == NULL || !has_metric (parser, name))
{
parser->error_offset = name_start - parser->cursor;
parser->error_range = end - name_start;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_METRIC, "Unable to find metric with name '%s'", name);
g_free (name); returnFALSE;
}
parser->error_offset = end - parser->cursor;
parser->error_range = 0;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Expected a positive number as a multiplier"); returnFALSE;
}
if (predicate->object != NULL)
{ if (*operator == '*')
predicate->multiplier = multiplier; else
predicate->multiplier = 1.0 / multiplier;
} else
{ /* If the subject is a constant then apply multiplier directly */ if (*operator == '*')
predicate->constant *= multiplier; else
predicate->constant *= 1.0 / multiplier;
}
}
/* Parse constant operator */ while (g_ascii_isspace (*end))
end += 1;
parser->error_offset = end - parser->cursor;
parser->error_range = 0;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Expected positive number as a constant"); returnFALSE;
}
if (range_end != NULL)
parser->error_range = range_end - end - 1; else
parser->error_range = 0;
parser->error_offset = end - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_PRIORITY, "Priority must be a positive number or one of " "'weak', 'medium', 'strong', and 'required'"); returnFALSE;
}
if (!(g_ascii_isalpha (*end) || *end == '_'))
{
parser->error_offset = end - parser->cursor;
parser->error_range = 0;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_VIEW, "View identifiers must be valid C identifiers"); returnFALSE;
}
while (g_ascii_isalnum (*end) || *end == '_')
end += 1;
if (*end == '\0')
{
parser->error_offset = end - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "A view must end with ']'"); returnFALSE;
}
char *name = g_strndup (cursor + 1, end - cursor - 1); if (!has_view (parser, name))
{
parser->error_offset = (cursor + 1) - parser->cursor;
parser->error_range = end - cursor - 1;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_VIEW, "Unable to find view with name '%s'", name);
g_free (name); returnFALSE;
}
if (*end == ']')
{ if (endptr != NULL)
*endptr = (char *) end + 1;
returnTRUE;
}
/* <predicateListWithParens> = '(' <predicate> (',' <predicate>)* ')' */ if (*end != '(')
{
parser->error_offset = end - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "A predicate must follow a view name"); returnFALSE;
}
end += 1;
while (*end != '\0')
{
VflPredicate cur_predicate; char *tmp;
if (*end == ']' || *end == '\0')
{
parser->error_offset = end - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "A predicate on a view must end with ')'"); returnFALSE;
}
/* If the predicate is a list, iterate again */ if (*end == ',')
{
end += 1; continue;
}
/* We reached the end of the predicate */ if (*end == ')')
{
end += 1; break;
}
parser->error_offset = end - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Expected ')' at the end of a predicate, not '%c'", *end); returnFALSE;
}
if (*end != ']')
{
parser->error_offset = end - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Expected ']' at the end of a view, not '%c'", *end); returnFALSE;
}
if (endptr != NULL)
*endptr = (char *) end + 1;
returnTRUE;
}
staticvoid
vfl_view_free (VflView *view)
{ if (view == NULL) return;
g_free (view->name);
if (view->predicates != NULL)
{ for (int i = 0; i < view->predicates->len; i++)
{
VflPredicate *p = &g_array_index (view->predicates, VflPredicate, i);
/* If we reached the second '|' then we completed a line *oflayout,andwecanstop
*/ break;
} else
{
parser->error_offset = cur - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Super views can only appear at the beginning " "and end of the layout, and not multiple times"); returnFALSE;
}
cur += 1;
continue;
}
/* Spacing */ if (*cur == '-')
{ if (*(cur + 1) == '\0')
{
parser->error_offset = cur - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Unterminated spacing"); returnFALSE;
}
if (parser->current_view == NULL)
{
parser->error_offset = cur - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Spacing cannot be set without a view"); returnFALSE;
}
/* Spacing predicates have no subject */
predicate = &(spacing->predicate);
predicate->subject = NULL;
cur += 1; if (!parse_predicate (parser, cur, predicate, &tmp, error)) returnFALSE;
if (*tmp != ')')
{
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Expected ')' at the end of a predicate, not '%c'", *tmp); returnFALSE;
}
cur = tmp + 1; if (*cur != '-')
{
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Explicit spacing must be followed by '-'"); returnFALSE;
}
if (tmp == cur)
{
parser->error_offset = cur - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Spacing must be a number"); returnFALSE;
}
if (*tmp != '-')
{
parser->error_offset = cur - parser->cursor;
parser->error_range = tmp - cur;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Explicit spacing must be followed by '-'"); returnFALSE;
}
cur = tmp + 1;
continue;
} else
{
parser->error_offset = cur - parser->cursor;
g_set_error (error, GTK_CONSTRAINT_VFL_PARSER_ERROR,
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_SYMBOL, "Spacing can either be '-' or a number"); returnFALSE;
}
}
if ((iter->spacing.flags & SPACING_SET) != 0)
{
c.view1 = iter->name;
/* If this is the first view, we need to anchor the leading edge */ if (iter == parser->leading_super)
c.attr1 = iter->orientation == VFL_HORIZONTAL ? "start" : "top"; else
c.attr1 = iter->orientation == VFL_HORIZONTAL ? "end" : "bottom";
/* If this is the first view, we need to anchor the leading edge */ if (iter == parser->leading_super)
c.attr1 = iter->orientation == VFL_HORIZONTAL ? "start" : "top"; else
c.attr1 = iter->orientation == VFL_HORIZONTAL ? "end" : "bottom";
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.