From f4cdd7098c0de7e200325be5c97e02ed33aff327 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Wed, 12 Aug 2009 15:17:35 +0000 Subject: [PATCH] Fix #251 (Config parser doesn't ignore comments), based on patch from Cygal This was SVN commit r7109. --- source/ps/Parser.cpp | 18 +----------------- source/ps/tests/test_Parser.h | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/source/ps/Parser.cpp b/source/ps/Parser.cpp index 7faaee2e82..173039516f 100644 --- a/source/ps/Parser.cpp +++ b/source/ps/Parser.cpp @@ -662,7 +662,6 @@ bool CParserLine::ParseString(const CParser& Parser, const std::string &strLine) { // Store argument in CParserValue! CParserValue value; - size_t i; switch(CurNode->m_Type) { @@ -710,22 +709,7 @@ bool CParserLine::ParseString(const CParser& Parser, const std::string &strLine) ++Progress; break; case typeRest: - // Extract the whole of the std::string - - // Reset, probably is but still - value.m_String = std::string(); - - for (i=Progress; i " <=, add one to the end of it too - if (Segments[i][0] == '"') - value.m_String += "\""; - } - - m_Arguments.push_back(value); - + // This is a comment, don't store it. // Now BREAK EVERYTHING ! // We're done, we found our match and let's get out LookNoFurther = true; diff --git a/source/ps/tests/test_Parser.h b/source/ps/tests/test_Parser.h index cb8850aa79..b691df162c 100644 --- a/source/ps/tests/test_Parser.h +++ b/source/ps/tests/test_Parser.h @@ -22,7 +22,7 @@ class TestParser : public CxxTest::TestSuite { public: - void test1() + void test_basic() { CParser Parser; Parser.InputTaskType("test", "_$ident_=_$value_"); @@ -39,7 +39,7 @@ public: } - void test2() + void test_optional() { CParser Parser; Parser.InputTaskType("test", "_$value_[$value]_"); @@ -61,7 +61,7 @@ public: } - void test3() + void test_multi_optional() { CParser Parser; Parser.InputTaskType("test", "_[$value]_[$value]_[$value]_"); @@ -90,7 +90,7 @@ public: } - void test4() + void test_optional_repeat() { CParser Parser; Parser.InputTaskType("test", "<[_a_][_b_]_x_>"); @@ -109,4 +109,18 @@ public: TS_ASSERT(! Line.ParseString(Parser, "a a x")); 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")); } + + void test_rest() + { + CParser Parser; + Parser.InputTaskType("assignment", "_$ident_=_$value[[;]$rest]"); + std::string str; + + CParserLine Line; + + TS_ASSERT(Line.ParseString(Parser, "12 = 34 ; comment")); + TS_ASSERT_EQUALS((int)Line.GetArgCount(), 2); + TS_ASSERT(Line.GetArgString(0, str) && str == "12"); + TS_ASSERT(Line.GetArgString(1, str) && str == "34"); + } };