|
marco 1.29.1
Window manager
|
Themes can use a simple expression language to represent the values of things. More...
Data Structures | |
| struct | PosExpr |
| Type and value of an expression in a parsed sequence. More... | |
| struct | _MetaDrawSpec |
| A computed expression in our simple vector drawing language. More... | |
Typedefs | |
| typedef struct _MetaDrawSpec | MetaDrawSpec |
| A computed expression in our simple vector drawing language. | |
Enumerations | |
| enum | PosExprType { POS_EXPR_INT , POS_EXPR_DOUBLE , POS_EXPR_OPERATOR } |
| The type of a PosExpr: either integer, double, or an operation. More... | |
Functions | |
| static gboolean | pos_eval_get_variable (PosToken *t, int *result, const MetaPositionExprEnv *env, GError **err) |
| There is a predefined set of variables which can appear in an expression. | |
| static gboolean | pos_eval_helper (PosToken *tokens, int n_tokens, const MetaPositionExprEnv *env, PosExpr *result, GError **err) |
| Evaluates a sequence of tokens within a particular environment context, and returns the current value. | |
| static gboolean | pos_eval (MetaDrawSpec *spec, const MetaPositionExprEnv *env, int *val_p, GError **err) |
| Evaluates an expression. | |
Themes can use a simple expression language to represent the values of things.
This is the parser used for that language.
| typedef struct _MetaDrawSpec MetaDrawSpec |
A computed expression in our simple vector drawing language.
While it appears to take the form of a tree, this is actually merely a list; concerns such as precedence of operators are currently recomputed on every recalculation.
Created by meta_draw_spec_new(), destroyed by meta_draw_spec_free(). pos_eval() fills this with ...FIXME. Are tokens a tree or a list?
| enum PosExprType |
The type of a PosExpr: either integer, double, or an operation.
| Enumerator | |
|---|---|
| POS_EXPR_INT | |
| POS_EXPR_DOUBLE | |
| POS_EXPR_OPERATOR | |
|
static |
Evaluates an expression.
| spec | The expression to evaluate. | |
| env | The environment context to evaluate the expression in. | |
| [out] | val_p | The integer value of the expression; if the expression is of type float, this will be rounded. If we return FALSE because the expression is invalid, this will be zero. |
| [out] | err | The error, if anything went wrong. |
References PosExpr::d, PosExpr::double_val, FALSE, PosExpr::int_val, _MetaDrawSpec::n_tokens, pos_eval_helper(), POS_EXPR_DOUBLE, POS_EXPR_INT, POS_EXPR_OPERATOR, _MetaDrawSpec::tokens, TRUE, and PosExpr::type.
Referenced by meta_draw_spec_new(), meta_parse_position_expression(), and meta_parse_size_expression().
|
static |
There is a predefined set of variables which can appear in an expression.
Here we take a token representing a variable, and return the current value of that variable in a particular environment. (The value is always an integer.)
There are supposedly some circumstances in which this function can be called from outside Marco, in which case env->theme will be NULL, and therefore we can't use it to find out quark values, so we do the comparison using strcmp, which is slower.
| t | The token representing a variable | |
| [out] | result | The value of that variable; not set if the token did not represent a known variable |
| env | The environment within which t should be evaluated | |
| [out] | err | set to the problem if there was a problem |
shouldn't t be const?
we should perhaps consider some sort of lookup arrangement into an array; also, the duplication of code is unlovely; perhaps using glib string hashes instead of quarks would fix both problems?
References _, _MetaPositionExprEnv::bottom_height, PosToken::d, FALSE, _MetaPositionExprEnv::frame_x_center, _MetaPositionExprEnv::frame_y_center, _MetaRectangle::height, _MetaPositionExprEnv::icon_height, _MetaPositionExprEnv::icon_width, _MetaPositionExprEnv::left_width, META_THEME_ERROR, META_THEME_ERROR_UNKNOWN_VARIABLE, _MetaPositionExprEnv::mini_icon_height, _MetaPositionExprEnv::mini_icon_width, PosToken::name, PosToken::name_quark, _MetaPositionExprEnv::object_height, _MetaPositionExprEnv::object_width, _MetaTheme::quark_bottom_height, _MetaTheme::quark_frame_x_center, _MetaTheme::quark_frame_y_center, _MetaTheme::quark_height, _MetaTheme::quark_icon_height, _MetaTheme::quark_icon_width, _MetaTheme::quark_left_width, _MetaTheme::quark_mini_icon_height, _MetaTheme::quark_mini_icon_width, _MetaTheme::quark_object_height, _MetaTheme::quark_object_width, _MetaTheme::quark_right_width, _MetaTheme::quark_title_height, _MetaTheme::quark_title_width, _MetaTheme::quark_top_height, _MetaTheme::quark_width, _MetaPositionExprEnv::rect, _MetaPositionExprEnv::right_width, _MetaPositionExprEnv::theme, _MetaPositionExprEnv::title_height, _MetaPositionExprEnv::title_width, _MetaPositionExprEnv::top_height, TRUE, PosToken::v, and _MetaRectangle::width.
Referenced by pos_eval_helper().
|
static |
Evaluates a sequence of tokens within a particular environment context, and returns the current value.
May recur if parantheses are found.
| tokens | A list of tokens to evaluate. | |
| n_tokens | How many tokens are in the list. | |
| env | The environment context in which to evaluate the expression. | |
| [out] | result | The current value of the expression |
References _, PosExpr::d, PosToken::d, do_operations(), PosExpr::double_val, FALSE, PosToken::i, PosExpr::int_val, MAX_EXPRS, META_THEME_ERROR, META_THEME_ERROR_BAD_PARENS, META_THEME_ERROR_FAILED, PosToken::o, PosToken::op, PosExpr::operator, pos_eval_get_variable(), pos_eval_helper(), POS_EXPR_DOUBLE, POS_EXPR_INT, POS_EXPR_OPERATOR, POS_TOKEN_CLOSE_PAREN, POS_TOKEN_DOUBLE, POS_TOKEN_INT, POS_TOKEN_OPEN_PAREN, POS_TOKEN_OPERATOR, POS_TOKEN_VARIABLE, TRUE, PosExpr::type, PosToken::type, and PosToken::val.
Referenced by pos_eval(), and pos_eval_helper().