mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
Merge pull request #3060 from RaiKoHoff/Dev_Lexilla
Tinyexpr evaluation of math constants "e" and "pi"...
This commit is contained in:
commit
40fa31c498
@ -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)
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user