.TCore: SQL-style extensions to calculator parser (continued)

git-svn-id: svn://ultimatepp.org/upp/trunk@2550 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
rylek 2010-07-19 18:32:55 +00:00
parent 0a354ec94d
commit 2b14ddfa32
2 changed files with 25 additions and 7 deletions

View file

@ -1260,18 +1260,35 @@ Value CalcParser::GetNumberOrDate()
String CalcParser::GetString()
{
CParser parser(pos);
try
{
try {
String result = parser.ReadOneString();
pos = parser.GetPtr();
return result;
}
catch(CParser::Error e)
{
catch(CParser::Error e) {
throw Exc(e);
}
}
String CalcParser::GetSqlString()
{
ASSERT(*pos == '\'');
pos++;
StringBuffer out;
for(;;) {
if(*pos == '\'') {
if(*++pos != '\'')
break;
out.Cat(*pos++);
}
else if(*pos)
out.Cat(*pos++);
else
throw Exc(t_("Unterminated string constant"));
}
return out;
}
CalcNodePtr CalcParser::Scan(const char *t)
{
Clear(t);
@ -1537,9 +1554,9 @@ CalcNodePtr CalcParser::ScanPrefix()
}
}
if(*pos == '\"')
{
return ScanPostfix(new CalcConstNode(GetString()));
}
if(sql_style && *pos == '\'')
return ScanPostfix(new CalcConstNode(GetSqlString()));
if(IsDigit(*pos)) // numeric or date constant
return ScanPostfix(new CalcConstNode(GetNumberOrDate()));
if(IsIdent(*pos))
@ -1666,7 +1683,7 @@ int CalcParser::GetOperator()
if(sql_style && IsAlpha(*op_end)) {
const char *b = op_end;
while(IsAlNum(*++op_end) || *op_end == '_')
op_end++;
;
int len = (int)(op_end - b);
if(len == 3 && !MemICmp(b, "and", 3))
op_last = OP_LOG_AND;

View file

@ -440,6 +440,7 @@ protected:
String GetIdent();
Value GetNumberOrDate();
String GetString();
String GetSqlString();
enum OPERATOR
{