Ticket #251: comments.patch

File comments.patch, 1.6 KB (added by Quentin Pradet, 15 years ago)

Patch that remove comments from the config parsing. Tests included.

  • source/ps/tests/test_Parser.h

     
    109109        TS_ASSERT(! Line.ParseString(Parser, "a a x"));
    110110        TS_ASSERT(Line.ParseString(Parser, "a x a b x a x b x b x b x b x a x a x a b x a b x b x a x"));
    111111    }
     112
     113    void test5()
     114    {
     115        CParser Parser;
     116        Parser.InputTaskType("assignment", "_$ident_=_$value[[;]$rest]");
     117        std::string str;
     118
     119        CParserLine Line;
     120
     121        TS_ASSERT(Line.ParseString(Parser, "12 = 34 ; comment"));
     122        TS_ASSERT_EQUALS((int)Line.GetArgCount(), 2);
     123        TS_ASSERT(Line.GetArgString(0, str) && str == "12");
     124        TS_ASSERT(Line.GetArgString(1, str) && str == "34");
     125    }
    112126};
  • source/ps/Parser.cpp

     
    710710                                ++Progress;
    711711                                break;
    712712                            case typeRest:
    713                                 // Extract the whole of the std::string
    714                                
    715                                 // Reset, probably is but still
    716                                 value.m_String = std::string();
    717 
    718                                 for (i=Progress; i<Segments.size(); ++i)
    719                                 {
    720                                     value.m_String += Segments[i];
    721 
    722                                     // If argument starts with => " <=, add one to the end of it too
    723                                     if (Segments[i][0] == '"')
    724                                         value.m_String += "\"";
    725                                 }
    726 
    727                                 m_Arguments.push_back(value);
    728 
     713                                // This is a comment, don't store it.
    729714                                // Now BREAK EVERYTHING !
    730715                                //  We're done, we found our match and let's get out
    731716                                LookNoFurther = true;