009263d75ef584d8571becd4199a56bc52ec9dc4 — Simon Ser a month ago 000f80e
parser/arithm: parse variables

References: https://github.com/emersion/mrsh/issues/85
1 files changed, 18 insertions(+), 0 deletions(-)

M parser/arithm.c
M parser/arithm.c => parser/arithm.c +18 -0
@@ 92,6 92,19 @@ return mrsh_arithm_literal_create(value);
  }
  
+ static struct mrsh_arithm_variable *variable(struct mrsh_parser *state) {
+ 	size_t name_len = peek_name(state, false);
+ 	if (name_len == 0) {
+ 		return NULL;
+ 	}
+ 
+ 	char *name = malloc(name_len + 1);
+ 	parser_read(state, name, name_len);
+ 	name[name_len] = '\0';
+ 
+ 	return mrsh_arithm_variable_create(name);
+ }
+ 
  static struct mrsh_arithm_expr *arithm_expr(struct mrsh_parser *state);
  
  static struct mrsh_arithm_unop *unop(struct mrsh_parser *state) {


@@ 158,6 171,11 @@ return &al->expr;
  	}
  
+ 	struct mrsh_arithm_variable *av = variable(state);
+ 	if (av != NULL) {
+ 		return &av->expr;
+ 	}
+ 
  	return NULL;
  }