[gnome-calculator] Fixes 'malformed syntax' when using '@'
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Fixes 'malformed syntax' when using '@'
- Date: Thu, 20 May 2021 07:47:48 +0000 (UTC)
commit 98b3f5782f53bab2f1c0b14c4b6368a74b462308
Author: harryjrk <martinjirku gmail com>
Date: Sat May 15 17:20:02 2021 +0200
Fixes 'malformed syntax' when using '@'
When custom function is specified with '@' for description, Calculator returned malfored syntax.
This change will add support for description in function definition.
Implements #188
lib/equation-lexer.vala | 9 +++++++--
tests/test-equation.vala | 3 +++
2 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/lib/equation-lexer.vala b/lib/equation-lexer.vala
index 36e8d9bd..7adb5814 100644
--- a/lib/equation-lexer.vala
+++ b/lib/equation-lexer.vala
@@ -67,7 +67,8 @@ public enum LexerTokenType
POWER, /* ^ */
FACTORIAL, /* ! */
PERCENTAGE, /* % */
- ARGUMENT_SEPARATOR /* ; (Function argument separator) */
+ ARGUMENT_SEPARATOR, /* ; (Function argument separator) */
+ FUNC_DESC_SEPARATOR /* @ (Function description separator) */
}
// FIXME: Merge into lexer
@@ -244,6 +245,9 @@ public class PreLexer : Object
if (c == ' ' || c == '\r' || c == '\t' || c == '\n')
return LexerTokenType.PL_SKIP;
+ if (c == '@')
+ return LexerTokenType.FUNC_DESC_SEPARATOR;
+
return LexerTokenType.UNKNOWN;
}
}
@@ -395,7 +399,8 @@ public class Lexer : Object
|| type == LexerTokenType.L_R_BRACKET || type == LexerTokenType.R_R_BRACKET || type ==
LexerTokenType.L_S_BRACKET
|| type == LexerTokenType.R_S_BRACKET || type == LexerTokenType.L_C_BRACKET || type ==
LexerTokenType.R_C_BRACKET
|| type == LexerTokenType.ABS || type == LexerTokenType.POWER || type ==
LexerTokenType.FACTORIAL || type == LexerTokenType.PERCENTAGE
- || type == LexerTokenType.ARGUMENT_SEPARATOR || type == LexerTokenType.SHIFT_LEFT || type ==
LexerTokenType.SHIFT_RIGHT)
+ || type == LexerTokenType.ARGUMENT_SEPARATOR || type == LexerTokenType.SHIFT_LEFT || type ==
LexerTokenType.SHIFT_RIGHT
+ || type == LexerTokenType.FUNC_DESC_SEPARATOR)
return insert_token (type);
/* [LexerTokenType.PL_SUPER_MINUS][LexerTokenType.PL_SUPER_DIGIT]+ */
diff --git a/tests/test-equation.vala b/tests/test-equation.vala
index 356d8bf1..e9b415f9 100644
--- a/tests/test-equation.vala
+++ b/tests/test-equation.vala
@@ -805,12 +805,15 @@ private void test_custom_functions ()
test ("sum(sum(sum(1;1);sum(1;1));sum(sum(1;1);sum(1;1)))", "8", ErrorCode.UNKNOWN_FUNCTION);
test ("sum(x;y)=x+y+1", "0", 0);
test ("sum(sum(sum(1;1);sum(1;1));sum(sum(1;1);sum(1;1)))", "15", 0);
+ test ("funcWithDescription(x;y;z)=x+y+z @ Description", "0", 0);
+ test ("funcWithDescription(2;3;5)", "10", 0);
function_manager.delete ("func");
function_manager.delete ("test");
function_manager.delete ("sum");
function_manager.delete ("dummy");
function_manager.delete ("abcd");
+ function_manager.delete ("funcWithDescription");
}
public int main (string[] args)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]