]> git.tdb.fi Git - libs/gl.git/commitdiff
Recognize the 'f' suffix for float literals in GLSL
authorMikko Rasa <tdb@tdb.fi>
Tue, 20 Apr 2021 16:21:06 +0000 (19:21 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 20 Apr 2021 16:26:10 +0000 (19:26 +0300)
source/glsl/parser.cpp
source/glsl/tokenizer.cpp

index 6a055c0cd3ebb718830e65175efa15aa3bf10ca1..72f8ebfa6279982e675b98b9c5364044e90f3150 100644 (file)
@@ -536,10 +536,12 @@ RefPtr<Literal> 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<int>(literal->token);
-               else
+               if(literal->token.back()=='f')
+                       literal->value = lexical_cast<float>(literal->token.substr(0, literal->token.size()-1));
+               else if(literal->token.find('.')!=string::npos)
                        literal->value = lexical_cast<float>(literal->token);
+               else
+                       literal->value = lexical_cast<int>(literal->token);
        }
        else if(literal->token=="true" || literal->token=="false")
                literal->value = (literal->token=="true");
index 0b18245f0e323e66c9c2eef6fb40ff19ba8307dc..2fa1b64ae960be301874c872c60c67c70f23cd13 100644 (file)
@@ -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;