コード例 #1
0
ファイル: Regexp.cpp プロジェクト: 108518/eos
static NFA::CharSet parseLit(const char*& nextChar)
{
	NFA::CharSet result;
	const char c = parseChar<inSet>(nextChar);
	if(inSet && *nextChar == '-')
	{
		++nextChar;
		const char d = parseChar<inSet>(nextChar);
		result.addRange((U8)c,(U8)d);
	}
	else { result.add((U8)c); }
	return result;
}
コード例 #2
0
ファイル: Regexp.cpp プロジェクト: 108518/eos
static NFA::CharSet parseCharClass(const char*& nextChar)
{
	if(*nextChar != '\\') { return parseLit<inSet>(nextChar); }
	else
	{
		NFA::CharSet result;
		switch(nextChar[1])
		{
		case 'd': result.addRange('0','9'); break;
		case 'w': result.addRange('a','z'); result.addRange('A','Z'); result.addRange('0','9'); result.add('_'); break;
		case 's': result.add(' '); result.add('\t'); result.add('\f'); result.add('\r'); result.add('\n'); break;
		default:
			if(!isMetachar<inSet>(nextChar[1]))
			{
				Errors::fatalf("'%c' is not a metachar in this context",nextChar[1]);
			}
			result.add(nextChar[1]);
			break;
		};
		nextChar += 2;
		return result;
	}
}