Mercurial > hg > index.cgi
diff lwlib/lw_expr.c @ 399:6153cb49403c
Initial commit of pragma newsource
pragma newsource enables a source code variant as follows:
1. no line numbers
2. no implied comments at the end of lines
3. all comments must be introduced by a comment character
4. spaces are allowed in operands
(4) is not quite complete. This commit handles "operandless" instructions
(anything where the parser calls skip_operand()) and expression parsing.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 13 Oct 2015 23:38:02 -0600 |
parents | 67373a053c49 |
children | 052c5f335a92 |
line wrap: on
line diff
--- a/lwlib/lw_expr.c Sun Oct 11 09:31:06 2015 -0600 +++ b/lwlib/lw_expr.c Tue Oct 13 23:38:02 2015 -0600 @@ -36,6 +36,7 @@ /* Q&D to break out of infinite recursion */ static int level = 0; static int bailing = 0; +static int parse_compact = 0; static void (*divzero)(void *priv) = NULL; @@ -1141,7 +1142,7 @@ following conditions: 1. a NUL character -2. a whitespace character +2. a whitespace character (if parse mode is "COMPACT") 3. a ) 4. a , 5. any character that is not recognized as a term @@ -1155,19 +1156,29 @@ lw_expr_t lw_expr_parse_expr(char **p, void *priv, int prec); +static void lw_expr_parse_next_tok(char **p) +{ + if (parse_compact) + return; + for (; **p && isspace(**p); (*p)++) + /* do nothing */ ; +} + lw_expr_t lw_expr_parse_term(char **p, void *priv) { lw_expr_t term, term2; eval_next: + lw_expr_parse_next_tok(p); + if (!**p || isspace(**p) || **p == ')' || **p == ']') return NULL; - // parentheses if (**p == '(') { (*p)++; term = lw_expr_parse_expr(p, priv, 0); + lw_expr_parse_next_tok(p); if (**p != ')') { lw_expr_destroy(term); @@ -1247,6 +1258,7 @@ int opern, i; lw_expr_t term1, term2, term3; + lw_expr_parse_next_tok(p); if (!**p || isspace(**p) || **p == ')' || **p == ',' || **p == ']' || **p == ';') return NULL; @@ -1255,6 +1267,7 @@ return NULL; eval_next: + lw_expr_parse_next_tok(p); if (!**p || isspace(**p) || **p == ')' || **p == ',' || **p == ']' || **p == ';') return term1; @@ -1312,9 +1325,17 @@ lw_expr_t lw_expr_parse(char **p, void *priv) { + parse_compact = 0; return lw_expr_parse_expr(p, priv, 0); } +lw_expr_t lw_expr_parse_compact(char **p, void *priv) +{ + parse_compact = 1; + return lw_expr_parse_expr(p, priv, 0); +} + + int lw_expr_testterms(lw_expr_t e, lw_expr_testfn_t *fn, void *priv) { struct lw_expr_opers *o;