Ejemplo n.º 1
0
StringType Filter(SourceCode& sourceCode)
{

	StringType res;
	while (true)
	{
		if (sourceCode.AdvanceIfMatch('\"'))
		{
			res += OnLiterals(sourceCode,'\"');
		}
		else if (sourceCode.AdvanceIfMatch('\''))
		{
			res += OnLiterals(sourceCode,'\'');
		}
		else if (sourceCode.AdvanceIfMatch("/*"s))
		{
			OnMultiLine(sourceCode);
		}
		else if (sourceCode.AdvanceIfMatch("//"s))
		{
			OnSingleLine(sourceCode);
		}
		else
		{
			auto c = sourceCode.NextChar();
			if (c == InvalidCharacter)
				break;
			res += c;
		}
	}
	return res;
}
Ejemplo n.º 2
0
StringType OnLiterals(SourceCode& sourceCode,char endChar)
{
	StringType res;
	res += endChar;
	while (true)
	{
		if (sourceCode.AdvanceIfMatch('\\'))
		{
			res += '\\';
			res += sourceCode.NextChar();			
		}
		else if (sourceCode.AdvanceIfMatch(endChar))
		{
			res += endChar;
			return std::move(res);
		}
		else
		{
			auto c = sourceCode.NextChar();
			if (c == InvalidCharacter)
				break;			
			res += c;
		}
	}
	std::string exp;
	(exp += endChar) += " lost";
	throw SyntaxError(exp.c_str());
}
Ejemplo n.º 3
0
void OnMultiLine(SourceCode& sourceCode)
{
	while (sourceCode.IsPosValid())
		if (sourceCode.AdvanceIfMatch("*/"s))
			return;
		else
			sourceCode.AdvanceChar();
	throw SyntaxError("*/ lost");
}