marco 1.29.1
Window manager
Loading...
Searching...
No Matches
The theme expression parser

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.
 

Detailed Description

Themes can use a simple expression language to represent the values of things.

This is the parser used for that language.

Typedef Documentation

◆ MetaDrawSpec

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?

Enumeration Type Documentation

◆ PosExprType

The type of a PosExpr: either integer, double, or an operation.

Enumerator
POS_EXPR_INT 
POS_EXPR_DOUBLE 
POS_EXPR_OPERATOR 

Function Documentation

◆ pos_eval()

static gboolean pos_eval ( MetaDrawSpec *  spec,
const MetaPositionExprEnv *  env,
int *  val_p,
GError **  err 
)
static

Evaluates an expression.

Parameters
specThe expression to evaluate.
envThe environment context to evaluate the expression in.
[out]val_pThe 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]errThe error, if anything went wrong.
Returns
True if we evaluated the expression successfully; false otherwise.
Bug:
Shouldn't spec be const?

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().

Here is the call graph for this function:

◆ pos_eval_get_variable()

static gboolean pos_eval_get_variable ( PosToken *  t,
int *  result,
const MetaPositionExprEnv *  env,
GError **  err 
)
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.

Parameters
tThe token representing a variable
[out]resultThe value of that variable; not set if the token did not represent a known variable
envThe environment within which t should be evaluated
[out]errset to the problem if there was a problem
Returns
true if we found the variable asked for, false if we didn't
Bug:

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().

◆ pos_eval_helper()

static gboolean pos_eval_helper ( PosToken *  tokens,
int  n_tokens,
const MetaPositionExprEnv *  env,
PosExpr *  result,
GError **  err 
)
static

Evaluates a sequence of tokens within a particular environment context, and returns the current value.

May recur if parantheses are found.

Parameters
tokensA list of tokens to evaluate.
n_tokensHow many tokens are in the list.
envThe environment context in which to evaluate the expression.
[out]resultThe current value of the expression
Bug:
Yes, we really do reparse the expression every time it's evaluated. We should keep the parse tree around all the time and just run the new values through it.

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().

Here is the call graph for this function: