From 40939b3ebe359b19cc4ee1d9a7b831fada71ce75 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Wed, 3 Jul 2024 15:05:18 +0200 Subject: implement a parser for mathematical expressions --- src/services/quick-answer-service.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/services/quick-answer-service.c') 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 @@ -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; } -- cgit v1.3.1