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

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

Data Structures

struct  PosToken
 A token, as output by the tokeniser. More...
 

Functions

static gboolean parse_number (const char *p, const char **end_return, PosToken *next, GError **err)
 Tokenises a number in an expression.
 
static gboolean pos_tokenize (const char *expr, PosToken **tokens_p, int *n_tokens_p, GError **err)
 Tokenises an expression.
 

Detailed Description

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

This is the tokeniser used for that language.

Bug:
We could remove almost all this code by using GScanner instead, but we would also have to find every expression in every existing theme we could and make sure the parse trees were the same.

Function Documentation

◆ parse_number()

static gboolean parse_number ( const char *  p,
const char **  end_return,
PosToken *  next,
GError **  err 
)
static

Tokenises a number in an expression.

Parameters
pa pointer into a string representing an operation; part of an expression somewhere, so not null-terminated
end_returnset to a pointer to the end of the number found; but not updated if no number was found at all
nextset to either an integer or a float token
[out]errset to the problem if there was a problem
Returns
TRUE if a valid number was found, FALSE otherwise (and "err" will have been set)
Bug:

The "while (*start)..." part: what's wrong with strchr-ish things?

The name is wrong: it doesn't parse anything.

References _, PosToken::d, FALSE, PosToken::i, META_THEME_ERROR, META_THEME_ERROR_BAD_CHARACTER, META_THEME_ERROR_FAILED, POS_TOKEN_DOUBLE, POS_TOKEN_INT, TRUE, PosToken::type, and PosToken::val.

Referenced by pos_tokenize().

◆ pos_tokenize()

static gboolean pos_tokenize ( const char *  expr,
PosToken **  tokens_p,
int *  n_tokens_p,
GError **  err 
)
static

Tokenises an expression.

Parameters
exprThe expression
[out]tokens_pThe resulting tokens
[out]n_tokens_pThe number of resulting tokens
[out]errset to the problem if there was a problem
Returns
True if the expression was successfully tokenised; false otherwise.

References _, PosToken::d, FALSE, free_tokens(), IS_VARIABLE_CHAR, META_THEME_ERROR, META_THEME_ERROR_FAILED, PosToken::name, NULL, PosToken::o, PosToken::op, op_from_string(), parse_number(), POS_OP_NONE, POS_TOKEN_CLOSE_PAREN, POS_TOKEN_OPEN_PAREN, POS_TOKEN_OPERATOR, POS_TOKEN_VARIABLE, TRUE, PosToken::type, and PosToken::v.

Referenced by meta_draw_spec_new().

Here is the call graph for this function: