From 14ebde52893263930cdcde1406cc91cc5c42556f Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Tue, 5 Jan 2016 00:40:40 +0100 Subject: First hit at providing support for floats in the language. --- src/libexpr/lexer.l | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/libexpr/lexer.l') diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 1f2957ec71ad..8f9d686a1c89 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -85,6 +85,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s) ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* INT [0-9]+ +FLOAT {INT}[0-9]+\.[0-9]+[eE]-?{INT} PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+ HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+ SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\> @@ -123,6 +124,12 @@ or { return OR_KW; } throw ParseError(format("invalid integer ‘%1%’") % yytext); return INT; } +{FLOAT} { errno = 0; + yylval->n = strtod(yytext, 0); + if (errno != 0) + throw ParseError(format("invalid float ‘%1%’") % yytext); + return FLOAT; + } \$\{ { PUSH_STATE(INITIAL); return DOLLAR_CURLY; } \{ { PUSH_STATE(INITIAL); return '{'; } -- cgit 1.4.1 From 494fc5acbb104371a80ca17bd9f1e35c3859ed27 Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Tue, 5 Jan 2016 00:53:22 +0100 Subject: Try a simplified version of float lexing that didn't work. The last one I tried was botchered anyway ... --- src/libexpr/lexer.l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libexpr/lexer.l') diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 8f9d686a1c89..158ca915266f 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -85,7 +85,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s) ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* INT [0-9]+ -FLOAT {INT}[0-9]+\.[0-9]+[eE]-?{INT} +FLOAT {INT}\.{INT} PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+ HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+ SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\> -- cgit 1.4.1 From f872262e0818ae1000826cfca3ad17619f50b60c Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Tue, 5 Jan 2016 09:46:37 +0100 Subject: Fix up float parsing. --- src/libexpr/eval.cc | 1 + src/libexpr/lexer.l | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libexpr/lexer.l') diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index e5a108a4385e..b951daacaf0c 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -130,6 +130,7 @@ static void printValue(std::ostream & str, std::set & active, con break; case tFloat: str << v.fpoint; + break; default: throw Error("invalid value"); } diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 158ca915266f..5fdcb25dd483 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -85,7 +85,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s) ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* INT [0-9]+ -FLOAT {INT}\.{INT} +FLOAT (([1-9][0-9]*\.?[0-9]*)|(\.[0-9]+))([Ee][+-]?[0-9]+)? PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+ HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+ SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\> @@ -125,7 +125,7 @@ or { return OR_KW; } return INT; } {FLOAT} { errno = 0; - yylval->n = strtod(yytext, 0); + yylval->nf = strtod(yytext, 0); if (errno != 0) throw ParseError(format("invalid float ‘%1%’") % yytext); return FLOAT; -- cgit 1.4.1 From a12a43046b0d1b967f0ca31d0db7bff218250274 Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Tue, 5 Jan 2016 09:54:49 +0100 Subject: Edge condition: parser did not pick up floats starting exactly with 0. --- src/libexpr/lexer.l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libexpr/lexer.l') diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 5fdcb25dd483..7a6e48215b34 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -85,7 +85,7 @@ static Expr * unescapeStr(SymbolTable & symbols, const char * s) ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* INT [0-9]+ -FLOAT (([1-9][0-9]*\.?[0-9]*)|(\.[0-9]+))([Ee][+-]?[0-9]+)? +FLOAT (([1-9][0-9]*\.[0-9]*)|(0?\.[0-9]+))([Ee][+-]?[0-9]+)? PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+ HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+ SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\> -- cgit 1.4.1