Merge pull request #3060 from RaiKoHoff/Dev_Lexilla

Tinyexpr evaluation of math constants "e" and "pi"...
This commit is contained in:
Pairi Daiza 2021-01-24 15:55:03 +01:00 committed by GitHub
commit 40fa31c498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 9 deletions

View File

@ -720,14 +720,6 @@ inline bool IsAlphaNumericW(const WCHAR ch) {
((ch >= L'A') && (ch <= L'Z'));
}
// no encoding for safe chars
inline bool IsIdentifierA(const char ch) {
return ((ch >= '0') && (ch <= '9')) ||
((ch >= 'a') && (ch <= 'z')) ||
((ch >= 'A') && (ch <= 'Z')) ||
(ch >= '_');
}
// If the character is an hexadecimal digit, get its value.
inline int GetHexDigitA(const char ch)
{

View File

@ -2131,7 +2131,7 @@ static bool _EvalTinyExpr(bool qmark)
while (*pBegin && exprErr) {
dExprEval = te_interp(pBegin, &exprErr);
// proceed to next possible expression
while (exprErr && IsIdentifierA(*pBegin++)) {}
while (exprErr && !te_is_op(pBegin++)) {}
}
FreeMem(lineBuf);

View File

@ -454,6 +454,7 @@ void next_token(state *s) {
} else {
/* Look for an operator or special character. */
/* keep in sync with te_isop(const char ch) defined in header */
switch (s->next++[0]) {
case '+': s->type = TOK_INFIX; s->function = get_function_pointer_2d(add); break;
case '-': s->type = TOK_INFIX; s->function = get_function_pointer_2d(sub); break;

View File

@ -105,6 +105,50 @@ void te_print(const te_expr *n);
/* This is safe to call on NULL pointers. */
void te_free(te_expr *n);
/* check for operator or special character. */
inline int te_is_op(const char* const expr) {
if (!expr)
return !0;
switch (*expr) {
case 0:
case '+':
case '-':
case '*':
case -41:
case '/':
case ':':
case -9:
case '^':
case '%':
case '!':
case '<':
case '>':
case '(':
case ')':
case ',':
case ' ':
case '\t':
case '\n':
case '\r':
return !0;
case '=':
if (expr[1] == '=')
return !0;
break;
case '&':
if (expr[1] == '&')
return !0;
break;
case '|':
if (expr[1] == '|')
return !0;
break;
default:
break;
}
return 0;
}
#ifdef __cplusplus
}