bcalc

cli bitcoin unit calculator
git clone git://jb55.com/bcalc
Log | Files | Refs | README | LICENSE

commit 71118ef4bf3a39c6179e7bb25472cd25aac1b7a5
parent edc877ef3145edb5983ad74130c795ca9afe6a7d
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 17 Apr 2019 12:25:54 -0700

lexer: support [,_ ] between digits

So you can do stuff like 'bcalc  1 000 000 sats to bits'

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mlexer.l | 17+++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lexer.l b/lexer.l @@ -8,6 +8,19 @@ #include "parser.tab.h" +static char * copy_num(char *in, int len) { + static char buf[2048] = {0}; + int i, j = 0; + + for (int i = 0; i < len; i++) { + char c = in[i]; + if (c != ',' && c != '_' && c != ' ') + buf[j++] = c; + } + buf[j] = 0; +} + + %} %% @@ -56,8 +69,8 @@ fiat|FIAT|alt|ALT|usd|USD|cur|CUR|other|OTHER { return T_FLOAT; } -[0-9]+ { - yylval.intval = strtoll(yytext, NULL, 10); +[0-9_, ]+ { + yylval.intval = strtoll(copy_num(yytext, yyleng), NULL, 10); return T_INT; }