]> git.tdb.fi Git - libs/datafile.git/commitdiff
Support ignoring statements
authorMikko Rasa <tdb@tdb.fi>
Sat, 30 Sep 2006 19:56:06 +0000 (19:56 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 30 Sep 2006 19:56:06 +0000 (19:56 +0000)
Allow numbers to begin with a plus sign
Support exponents in floating point numbers

source/loader.h
source/parser.cpp

index 2fe0292bff01d5a6cdbab98e387daf0bbfab309e..6e9c4f8012e42c952a36bc21f392a7559ef22e47 100644 (file)
@@ -172,6 +172,9 @@ protected:
        void add(const std::string &k, T L::*p)
        { actions.insert(typename ActionMap::value_type(k, new LoadValue<L, T>(p))); }
 
+       void add(const std::string &k)
+       { actions.insert(ActionMap::value_type(k, 0)); }
+
        template<typename S>
        void load_sub(S &s)
        { load_sub<S, typename S::Loader>(s); }
@@ -196,7 +199,8 @@ private:
                ActionMap::iterator j=actions.find(st.keyword);
                if(j==actions.end())
                        throw Exception(st.get_location()+": Unknown keyword '"+st.keyword+"'");
-               j->second->execute(*this, st);
+               if(j->second)
+                       j->second->execute(*this, st);
                cur_st=0;
        }
 };
index 7b9af11d60ca292a860ae346cebcb813220e5469..f74be86396881917caf46fec861a923d954f5293 100644 (file)
@@ -143,7 +143,9 @@ Token Parser::parse_token()
        enum ParseState
        {
                INIT,
-               NEGATIVE,
+               SIGN,
+               FLOATEXPINIT,
+               FLOATEXPSIGN,
                STRING,
                ACCEPT,
                ZERO,
@@ -151,11 +153,14 @@ Token Parser::parse_token()
                HEXADECIMAL,
                OCTAL,
                FLOAT,
+               FLOATEXP,
                IDENTIFIER
        };
 
        static Token::Type token_type[]=
        {
+               Token::SPECIAL,
+               Token::SPECIAL,
                Token::SPECIAL,
                Token::SPECIAL,
                Token::STRING,
@@ -165,6 +170,7 @@ Token Parser::parse_token()
                Token::INTEGER,
                Token::INTEGER,
                Token::FLOAT,
+               Token::FLOAT,
                Token::IDENTIFIER
        };
 
@@ -185,8 +191,8 @@ Token Parser::parse_token()
                case INIT:
                        if(c=='0')
                                state=ZERO;
-                       else if(c=='-')
-                               state=NEGATIVE;
+                       else if(c=='-' || c=='+')
+                               state=SIGN;
                        else if(c=='.')
                                state=FLOAT;
                        else if(c=='"')
@@ -201,7 +207,7 @@ Token Parser::parse_token()
                                parse_error(c, state);
                        break;
                
-               case NEGATIVE:
+               case SIGN:
                        if(c=='0')
                                state=ZERO;
                        else if(isdigit(c))
@@ -241,6 +247,29 @@ Token Parser::parse_token()
                        break;
 
                case FLOAT:
+                       if(c=='e' || c=='E')
+                               state=FLOATEXPINIT;
+                       else if(!isdigit(c))
+                               parse_error(c, state);
+                       break;
+
+               case FLOATEXPINIT:
+                       if(c=='+' || c=='-')
+                               state=FLOATEXPSIGN;
+                       else if(isdigit(c))
+                               state=FLOATEXP;
+                       else
+                               parse_error(c, state);
+                       break;
+
+               case FLOATEXPSIGN:
+                       if(isdigit(c))
+                               state=FLOATEXP;
+                       else
+                               parse_error(c, state);
+                       break;
+
+               case FLOATEXP:
                        if(!isdigit(c))
                                parse_error(c, state);
                        break;