diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2024-07-03 15:05:18 +0200 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2024-07-03 15:05:18 +0200 |
| commit | 40939b3ebe359b19cc4ee1d9a7b831fada71ce75 (patch) | |
| tree | 74c5ce2c6d22490bf35ed4dae778ae542f5fd228 /src/services/quick-answer-service.c | |
| parent | 16483d65744488146e96d149b41f5869a2597a4c (diff) | |
implement a parser for mathematical expressions
Diffstat (limited to 'src/services/quick-answer-service.c')
| -rw-r--r-- | src/services/quick-answer-service.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/services/quick-answer-service.c b/src/services/quick-answer-service.c index b564a16..70d54b6 100644 --- a/src/services/quick-answer-service.c +++ b/src/services/quick-answer-service.c @@ -1,4 +1,5 @@ #include "services/quick-answer-service.h" +#include "services/quick-answers/math.h" #include "launcher-item.h" #include <gdk/gdk.h> @@ -302,16 +303,23 @@ FoobarQuickAnswer* foobar_quick_answer_service_query( { (void)self; - if ( !g_strcmp0(query, "2+2") ) + gsize token_count; + g_autofree FoobarMathToken* tokens = foobar_math_lex( query, strlen( query ), &token_count ); + if ( tokens ) { - g_autoptr(GIcon) icon = g_themed_icon_new("fluent-calculator-symbolic"); - - FoobarQuickAnswer* answer = foobar_quick_answer_new(); - foobar_quick_answer_set_value(answer, "4"); - foobar_quick_answer_set_title(answer, "= 4"); - foobar_quick_answer_set_icon(answer, icon); - return answer; + FoobarMathExpression* expr = foobar_math_parse( tokens, token_count ); + if ( expr ) + { + g_print( "---\n" ); + foobar_math_expression_print( expr, 0 ); + foobar_math_expression_free( expr ); + } } + (void)foobar_quick_answer_new; + (void)foobar_quick_answer_set_value; + (void)foobar_quick_answer_set_icon; + (void)foobar_quick_answer_set_title; + return NULL; } |
