Пример #1
0
bool EntTokenizer::NextKV()
{
    while(currentPtr != strEnd)
    {
		switch(*currentPtr)
		{
			case '\"':
				*currentPtr = 0;
				currentPtr++;
				return true;
			case '{':
				if(bInBlock)
				{
					throw ParseException("Unexpected start of block.", GetCharNum());
				}
				bInBlock = true;
				break;
			case '}':
				if(!bInBlock)
				{
					throw ParseException("Unexpected end of block.", GetCharNum());
				}
				bInBlock = false;
				blocksRead++;
				break;
			default:
				break;
		}

		currentPtr++;
    }

    currentPtr = NULL;
    return false;
}
Пример #2
0
int GetNum()
{
	register unsigned int v = 0;

	if (Token("'"))			// found «
	{		
		if (Token("\\"))		// Test "\"
		{
			v = GetEscCode();
			NeedToken("\'");
			return v;
		}

		v = GetCharNum();
		NeedToken("\'");
		return v;
	}

	if (*FilePtr == '0' && (*(FilePtr+1) =='x' || *(FilePtr+1) == 'X'))
	{
		FilePtr+=2;
		
		return GetHexNum(16);
	}

	return GetDecNum(16);
}
Пример #3
0
const EntTokenizer::KeyValuePair* EntTokenizer::NextPair()
{
	// Have we finished parsing?
	if(!currentPtr)
	{
		return NULL;
	}

	// Skip end of line
	if(!NextKV())
	{
		// If we've run out key-values, make sure we are in an accept state
		if(bInBlock)
		{
			throw ParseException("Reached end of entity data while inside a block.", GetCharNum());
		}

		return NULL;
	}

	// Read key
	pair.first = currentPtr;

	if(!Next())
	{
		throw ParseException("Failed to parse key of key-value pair.", GetCharNum());
	}
	// currentPtr points to char after NUL
	keyLength = (currentPtr ? currentPtr - 1 : strEnd) - pair.first;

	// Ignore space between key/value
	ParseKVSeparator();

	pair.second = currentPtr;

	if(!Next())
	{
		throw ParseException("Failed to parse value of key-value pair.", GetCharNum());
	}
	// currentPtr points to char after NUL
	valueLength = (currentPtr ? currentPtr - 1 : strEnd) - pair.second;

	return &pair;
}
Пример #4
0
void EntTokenizer::ParseKVSeparator()
{
	while(currentPtr != strEnd)
	{
		if(*currentPtr == '\"')
		{
			*currentPtr = 0;
			currentPtr++;
			return;
		}
		else if(*currentPtr != ' ')
		{
			throw ParseException("Found non-whitespace between key and value.", GetCharNum());
		}

		currentPtr++;
	}

	throw ParseException("Failed to parse key-value pair", GetCharNum());
}
Пример #5
0
void compileError(const char *fmt, ... )
{
	va_list argptr;
	char msg[MAXERROR];	
	Int16 linenum,charnum;
	
	compile_error=TRUE;
		
	va_start(argptr,fmt);
  	xvsnprintf(msg,(Int32)MAXERROR,fmt,argptr);
	va_end(argptr);
	
	linenum = GetLineNum()+1;
	charnum = GetCharNum();		
	xprintf("compile error: %s\n",msg);
	xprintf("near line: %d\n",linenum);
}