[PATCH] Support shifts with keyboard



Signed-off-by: Stefan Tauner <stefan tauner student tuwien ac at>
---
This was nagging me for a long time... such a wonderful programming mode
and then there is no way to shift with "<<" and ">>"... :)
I have only tested this rudimentarily because the gui is completely
broken on my dev machine (ubuntu 12.04 beta).
Also, this could be documented (although i think the tooltips are enough).

PS: please CC me because i am not subscribed, thanks,

 src/math-buttons.c       |    4 ++--
 src/mp-equation-lexer.l  |    4 ++++
 src/mp-equation-parser.y |    3 +++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/math-buttons.c b/src/math-buttons.c
index cd28ee7..f698af8 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -237,10 +237,10 @@ static ButtonData button_data[] = {
       N_("Undo [Ctrl+Z]")},
     {"shift_left", NULL, ACTION,
       /* Tooltip for the shift left button */
-      N_("Shift Left")},  
+      N_("Shift Left [<<]")},
     {"shift_right", NULL, ACTION,
       /* Tooltip for the shift right button */
-      N_("Shift Right")},  
+      N_("Shift Right [>>]")},
     {"finc_compounding_term", NULL, FUNCTION,
       /* Tooltip for the compounding term button */
       N_("Compounding Term")},
diff --git a/src/mp-equation-lexer.l b/src/mp-equation-lexer.l
index 1a8919e..c5d1dd2 100644
--- a/src/mp-equation-lexer.l
+++ b/src/mp-equation-lexer.l
@@ -66,6 +66,8 @@ MOD  [mM][oO][dD]
 AND  "∧"|[aA][nN][dD]
 OR   "∨"|[oO][rR]
 XOR  "⊻"|"⊕"|[xX][oO][rR]
+LSHIFT  "<<"
+RSHIFT  ">>"
 NOT  "¬"|"~"|[nN][oO][tT]
 RE   "⃰ℜ"
 IM   "ℑ"
@@ -85,6 +87,8 @@ IN   [iI][nN]
 "√"         {return tROOT;}
 "∛"         {return tROOT3;}
 "∜"         {return tROOT4;}
+{LSHIFT}    {return tLSHIFT;}
+{RSHIFT}    {return tRSHIFT;}
 {NOT}       {return tNOT;}
 {AND}       {return tAND;}
 {OR}        {return tOR;}
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index cb9e49e..0678bd8 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -174,6 +174,7 @@ static void do_conversion(yyscan_t yyscanner, const MPNumber *x, const char *x_u
 %left UNARY_PLUS
 %left tADD tSUBTRACT
 %left tAND tOR tXOR tXNOR
+%left tLSHIFT tRSHIFT
 %left tMULTIPLY MULTIPLICATION
 %left tDIVIDE tMOD
 %left tNOT
@@ -237,6 +238,8 @@ exp:
 | exp tOR exp %prec BOOLEAN_OPERATOR {mp_or(&$1, &$3, &$$);}
 | exp tXOR exp %prec BOOLEAN_OPERATOR {mp_xor(&$1, &$3, &$$);}
 | tNUMBER {mp_set_from_mp(&$1, &$$);}
+| exp tLSHIFT exp {mp_shift(&$1, mp_cast_to_int(&$3), &$$);}
+| exp tRSHIFT exp {mp_shift(&$1, -mp_cast_to_int(&$3), &$$);}
 ;
 
 
-- 
1.7.9.1




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]