18 #include "precompiled.h"
23 #pragma warning(disable:4786)
31 #define REGULAR_MAX_LENGTH 10
32 #define START_DYNAMIC '<'
33 #define END_DYNAMIC '>'
34 #define START_OPTIONAL '['
35 #define END_OPTIONAL ']'
36 #define REGULAR_EXPRESSION '$'
39 #define FUNC_IMPL_CAST_GETDOUBLE(func_name,type) \
40 bool CParserValue::func_name(type &ret) \
44 return ret = (type)d, true; \
52 #define FUNC_IMPL_GETARG(func_name, get_name, type) \
53 bool CParserLine::func_name(size_t arg, type &ret) \
55 if (GetArgCount() <= arg) \
57 return m_Arguments[arg].get_name(ret); \
74 return ((c >=
'a' && c <=
'z') ||
75 (c >=
'A' && c <=
'Z') ||
76 (c >=
'0' && c <=
'9'));
82 return ((c >=
'a' && c <=
'z') ||
83 (c >=
'A' && c <=
'Z') ||
84 (c >=
'0' && c <=
'9') ||
136 double TempRet = 0.0;
139 bool AtLeastOne =
false;
142 bool Negative =
false;
152 if (DecimalPos == std::string::npos)
157 for (i=(Negative?1:0); i < DecimalPos; ++i)
165 double exp = (DecimalPos-i-1);
166 TempRet += (
m_String[i]-
'0')*pow(10.0, exp);
177 for (i=DecimalPos+1; i < Size; ++i)
185 double exp = (int)(DecimalPos-i);
186 TempRet += (
m_String[i]-
'0')*pow(10.0,exp);
189 else if (!(i==Size-1 &&
m_String[i] ==
'f'))
196 if (!AtLeastOne)
return false;
199 ret = (Negative?-TempRet:TempRet);
328 if (strLine == std::string())
338 char Letter[] = {
'\0',
'\0'};
339 std::vector<std::string> Segments;
358 for (i=0; i<strLine.size(); ++i)
368 memset((
void*)Buffer,
'\0',
sizeof(
char)*256);
372 if (strLine[i] ==
'\"')
375 size_t pos = strLine.find(
"\"", i+1);
379 if (pos == std::string::npos)
389 strSub =
"\"" + strLine.substr(i+1, pos-i-1);
392 Segments.push_back(strSub);
402 Letter[0] = strLine[i];
403 Segments.push_back(Letter);
411 if (i-ExtractPos >= 256)
421 Buffer[i-ExtractPos] = strLine[i];
435 if (i == strLine.size()-1)
440 if (Extract ==
false)
442 Segments.push_back( std::string(Buffer) );
457 std::vector<size_t> LastValidProgress;
459 std::vector<size_t> LastValidArgCount;
462 std::vector<bool> LastValidMatch;
463 bool BlockAltNode =
false;
467 bool LookNoFurther =
false;
478 std::vector<CParserTaskType>::const_iterator cit_tt;
479 for (cit_tt = Parser.m_TaskTypes.begin();
480 cit_tt != Parser.m_TaskTypes.end();
487 CurNode = cit_tt->m_BaseNode;
488 LookNoFurther =
false;
489 BlockAltNode =
false;
493 while (!LookNoFurther)
498 (CurNode->
m_AltNode == NULL || BlockAltNode))
506 (CurNode->
m_AltNode == NULL || BlockAltNode) &&
509 if (Progress != Segments.size())
557 if (LastValidProgress.size() < Lane+1)
559 LastValidProgress.resize(Lane+1);
560 LastValidMatch.resize(Lane+1);
561 LastValidArgCount.resize(Lane+1);
565 LastValidProgress[Lane] = Progress;
566 LastValidMatch[Lane] = Match;
567 LastValidArgCount[Lane] = (int)m_Arguments.size();
574 else BlockAltNode =
false;
595 if (Progress < Segments.size())
598 while (Segments[Progress].size()==1 &&
599 (Segments[Progress][0]==
' ' ||
600 Segments[Progress][0]==
'\t'))
605 if (Progress >= Segments.size())
615 if (Progress < Segments.size())
618 if (Segments[Progress].size() != 1)
622 if (CurNode->
m_Letter != Segments[Progress][0])
648 m_Arguments.push_back(value);
657 if (Progress >= Segments.size())
679 if (Segments[Progress][0] ==
'\"')
682 value.
m_String = Segments[Progress];
685 m_Arguments.push_back(value);
692 Segments[Progress][0] !=
'\"')
701 if (Segments[Progress][0] ==
'\"')
702 value.
m_String = Segments[Progress].substr(1, Segments[Progress].size()-1);
704 value.
m_String = Segments[Progress];
707 m_Arguments.push_back(value);
715 LookNoFurther =
true;
727 if (!Match && Lane > 0)
750 Progress = LastValidProgress[Lane];
751 Match = LastValidMatch[Lane];
752 m_Arguments.resize(LastValidArgCount[Lane]);
765 m_TaskTypeName = cit_tt->m_Name;
777 for (i=1; i<GetArgCount(); ++i)
779 if (m_Arguments[i-1].m_String ==
"_minus")
782 m_Arguments[i].
m_String =
"-" + m_Arguments[i].m_String;
783 m_Arguments.erase(m_Arguments.begin() + (i-1));
802 std::vector<CParserTaskType>::iterator itTT;
821 size_t ExtractPos = 0;
822 bool Extract =
false;
834 for (i=0; i<strSyntax.size(); ++i)
958 Buffer[i-ExtractPos] = strSyntax[i];
972 if (i == strSyntax.size()-1)
977 if (Extract ==
false)
989 std::string str = std::string(Buffer);
998 if (str ==
"rbracket") CurNode->
m_Letter =
'>';
1000 if (str ==
"lbracket") CurNode->
m_Letter =
'<';
1002 if (str ==
"rbrace") CurNode->
m_Letter =
']';
1004 if (str ==
"lbrace") CurNode->
m_Letter =
'[';
1006 if (str ==
"dollar") CurNode->
m_Letter =
'$';
1016 if (ExtractPos+4 >= strSyntax.size())
1024 if (strSyntax[ExtractPos+3] !=
'(')
1031 size_t Pos = strSyntax.find(
")", ExtractPos+5);
1034 if (Pos == std::string::npos)
1041 CurNode->
m_String = strSyntax.substr(ExtractPos+4, Pos-(ExtractPos+4));
1059 TaskType.
m_Name = strName;
std::deque< CParserValue > m_Arguments
#define FUNC_IMPL_GETARG(func_name, get_name, type)
bool GetString(std::string &ret)
#define FUNC_IMPL_CAST_GETDOUBLE(func_name, type)
#define REGULAR_MAX_LENGTH
static CacheType m_Cached
#define REGULAR_EXPRESSION
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
bool GetDouble(double &ret)
static CStrInternInternals * GetString(const char *str, size_t len)
std::map< T, P >::iterator iterator
CParserTaskTypeNode * m_AltNode
CParserTaskTypeNode * m_NextNode
std::vector< CParserTaskType > m_TaskTypes
static CParser & Get(const char *str)
bool InputTaskType(const std::string &strName, const std::string &strSyntax)
CParserTaskTypeNode * m_BaseNode
static bool _IsValueChar(const char &c)
CParserTaskTypeNode * m_ParentNode
static bool _IsStrictNameChar(const char &c)