From: Mikko Rasa Date: Tue, 20 Apr 2021 16:21:06 +0000 (+0300) Subject: Recognize the 'f' suffix for float literals in GLSL X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2016444ee144ce41f88c48e89c825137ad7e4ec2;p=libs%2Fgl.git Recognize the 'f' suffix for float literals in GLSL --- diff --git a/source/glsl/parser.cpp b/source/glsl/parser.cpp index 6a055c0c..72f8ebfa 100644 --- a/source/glsl/parser.cpp +++ b/source/glsl/parser.cpp @@ -536,10 +536,12 @@ RefPtr Parser::parse_literal() if(isdigit(literal->token[0])) { // TODO have the tokenizer return the type of the token - if(isnumrc(literal->token)) - literal->value = lexical_cast(literal->token); - else + if(literal->token.back()=='f') + literal->value = lexical_cast(literal->token.substr(0, literal->token.size()-1)); + else if(literal->token.find('.')!=string::npos) literal->value = lexical_cast(literal->token); + else + literal->value = lexical_cast(literal->token); } else if(literal->token=="true" || literal->token=="false") literal->value = (literal->token=="true"); diff --git a/source/glsl/tokenizer.cpp b/source/glsl/tokenizer.cpp index 0b18245f..2fa1b64a 100644 --- a/source/glsl/tokenizer.cpp +++ b/source/glsl/tokenizer.cpp @@ -136,7 +136,9 @@ string Tokenizer::parse_number() } bool require_digit = false; - if(iter!=source_end && (*iter=='e' || *iter=='E')) + if(iter==source_end) + ; + else if(*iter=='e' || *iter=='E') { number += *iter++; if(iter!=source_end && (*iter=='-' || *iter=='+')) @@ -152,11 +154,15 @@ string Tokenizer::parse_number() else break; } + if(!require_digit && iter!=source_end && *iter=='f') + number += *iter++; } + else if(*iter=='f') + number += *iter++; if(require_digit) throw syntax_error(location, number, "Incomplete numeric literal"); - else if(isalnum(*iter) || *iter=='_') + else if(iter!=source_end && (isalnum(*iter) || *iter=='_')) throw syntax_error(location, number, "Garbage at end of numeric literal"); return number;