void component::parse
	(const parsingContext& ctx,
	 ref <utility::inputStream> inputStream, const utility::stream::size_type position,
	 const utility::stream::size_type end, utility::stream::size_type* newPosition)
{
	m_parsedOffset = m_parsedLength = 0;

	ref <utility::seekableInputStream> seekableStream =
		inputStream.dynamicCast <utility::seekableInputStream>();

	if (seekableStream == NULL || end == 0)
	{
		// Read the whole stream into a buffer
		std::ostringstream oss;
		utility::outputStreamAdapter ossAdapter(oss);

		utility::bufferedStreamCopyRange(*inputStream, ossAdapter, position, end - position);

		const string buffer = oss.str();
		parseImpl(ctx, buffer, 0, buffer.length(), NULL);
	}
	else
	{
		ref <utility::parserInputStreamAdapter> parser =
			vmime::create <utility::parserInputStreamAdapter>(seekableStream);

		parseImpl(ctx, parser, position, end, newPosition);
	}
}
Esempio n. 2
0
void component::parse	(const parsingContext& ctx,
												shared_ptr <utility::inputStream> inputStream,
												size_t position,
												size_t end,
												size_t* newPosition)
{
	m_parsedOffset = m_parsedLength = 0;

	shared_ptr <utility::seekableInputStream> seekableStream =
		dynamicCast <utility::seekableInputStream>(inputStream);

	if (seekableStream == NULL || end == 0)
	{
		// Read the whole stream into a buffer
		std::ostringstream oss;
		utility::outputStreamAdapter ossAdapter(oss);

		utility::bufferedStreamCopyRange(*inputStream, ossAdapter, position, end - position);

		const string &buffer = oss.str();
		parseImpl(ctx, buffer, 0, buffer.length(), NULL);
	}
	else
	{
		shared_ptr <utility::parserInputStreamAdapter> parser =
			make_shared <utility::parserInputStreamAdapter>(seekableStream);

		parseImpl(ctx, parser, position, end, newPosition);
	}
}
Esempio n. 3
0
bool IParserBase::parse(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
	Pos begin = pos;
	Pos new_max_parsed_pos = pos;
	Expected new_expected = getName();

	bool res = parseImpl(pos, end, node, new_max_parsed_pos, new_expected);

	if (pos > new_max_parsed_pos)
		new_max_parsed_pos = pos;

	if (new_max_parsed_pos > max_parsed_pos)
		max_parsed_pos = new_max_parsed_pos;

	if (new_max_parsed_pos >= max_parsed_pos)
		expected = new_expected;

	if (pos > end)
		throw Exception("Logical error: pos > end.", ErrorCodes::LOGICAL_ERROR);

	if (!res)
	{
		node = nullptr;
		pos = begin;
	}

	return res;
}
Esempio n. 4
0
void component::parse
	(const string& buffer, const size_t position,
	 const size_t end, size_t* newPosition)
{
	m_parsedOffset = m_parsedLength = 0;

	parseImpl(parsingContext::getDefaultContext(), buffer, position, end, newPosition);
}
Esempio n. 5
0
void component::parse
	(const string& buffer, const string::size_type position,
	 const string::size_type end, string::size_type* newPosition)
{
	m_parsedOffset = m_parsedLength = 0;

	parseImpl(buffer, position, end, newPosition);
}
Esempio n. 6
0
static bool parseArray(const char* json, const tinyjson_token* tokens, int ntokens, Impl* impl) {
	impl->arrChildren.resize(ntokens);
	for (int ii = 0; ii < ntokens; ++ii)
		if (!parseImpl(json + tokens[ii].start, tokens[ii].length, tokens[ii].type, &impl->arrChildren[ii]))
			return false;

	return true;
}
Esempio n. 7
0
void component::parse
	(const parsingContext& ctx,
	 const string& buffer, const size_t position,
	 const size_t end, size_t* newPosition)
{
	m_parsedOffset = m_parsedLength = 0;

	parseImpl(ctx, buffer, position, end, newPosition);
}
Esempio n. 8
0
void component::parseImpl
	(const string& buffer, const string::size_type position,
	 const string::size_type end, string::size_type* newPosition)
{
	ref <utility::seekableInputStream> stream =
		vmime::create <utility::inputStreamStringAdapter>(buffer);

	ref <utility::parserInputStreamAdapter> parser =
		vmime::create <utility::parserInputStreamAdapter>(stream);

	parseImpl(parser, position, end, newPosition);
}
Esempio n. 9
0
void component::parseImpl
	(ref <utility::parserInputStreamAdapter> parser, const utility::stream::size_type position,
	 const utility::stream::size_type end, utility::stream::size_type* newPosition)
{
	const std::string buffer = parser->extract(position, end);
	parseImpl(buffer, 0, buffer.length(), newPosition);

	// Recursivey offset parsed bounds on children
	if (position != 0)
		offsetParsedBounds(position);

	if (newPosition != NULL)
		*newPosition += position;
}
Esempio n. 10
0
bool IParserBase::parse(Pos & pos, ASTPtr & node, Expected & expected)
{
    Pos begin = pos;
    expected.add(pos, getName());

    bool res = parseImpl(pos, node, expected);

    if (!res)
    {
        node = nullptr;
        pos = begin;
    }

    return res;
}
Esempio n. 11
0
void component::parseImpl
	(const parsingContext& ctx, const string& buffer, size_t position,
	 size_t end, size_t* newPosition)
{
	// This is the default implementation for parsing from a string:
	// actually, we encapsulate the string buffer in an input stream, then use
	// the "parse from input stream" implementation
	shared_ptr <utility::seekableInputStream> stream =
		make_shared <utility::inputStreamStringAdapter>(buffer);

	shared_ptr <utility::parserInputStreamAdapter> parser =
		make_shared <utility::parserInputStreamAdapter>(stream);

	parseImpl(ctx, parser, position, end, newPosition);
}
void component::parseImpl
	(const parsingContext& ctx, const string& buffer, const string::size_type position,
	 const string::size_type end, string::size_type* newPosition)
{
	// This is the default implementation for parsing from a string:
	// actually, we encapsulate the string buffer in an input stream, then use
	// the "parse from input stream" implementation
	ref <utility::seekableInputStream> stream =
		vmime::create <utility::inputStreamStringAdapter>(buffer);

	ref <utility::parserInputStreamAdapter> parser =
		vmime::create <utility::parserInputStreamAdapter>(stream);

	parseImpl(ctx, parser, position, end, newPosition);
}
Esempio n. 13
0
void component::parseImpl
	(const parsingContext& ctx, shared_ptr <utility::parserInputStreamAdapter> parser,
	 size_t position, size_t end, size_t* newPosition)
{
	// This is the default implementation for parsing from an input stream:
	// actually, we extract the substring and use the "parse from string" implementation
	const string &buffer = parser->extract(position, end);
	parseImpl(ctx, buffer, 0, buffer.length(), newPosition);

	// Recursivey offset parsed bounds on children
	if (position != 0)
		offsetParsedBounds(position);

	if (newPosition)
		*newPosition += position;
}
Esempio n. 14
0
static bool parseObject(const char* json, const tinyjson_token* tokens, int ntokens, Impl* impl) {
	if (ntokens % 2)
		return false;

	for (int ii = 0; ii < ntokens; ii += 2) {
		if (tokens[ii].type != MYJSON_TOKEN_STRING)
			return false;

		const InternalString key = {json + tokens[ii].start, (int)tokens[ii].length};
		Impl& child = impl->objChildren[key];
		if (!parseImpl(json + tokens[ii + 1].start, tokens[ii + 1].length, tokens[ii + 1].type, &child))
			return false;
	}

	return true;
}
Esempio n. 15
0
bool JsonObject::parse(const char* json, int length, JsonObject* object) {
	if(length == 0)
		return false;
	
	if (length && json[0] != '{')
		return false;

	Impl *impl = new Impl;
	if (!parseImpl(json, length, MYJSON_TOKEN_OBJECT, impl)) {
		delete impl;
		return false;
	}

	if (object->impl && object->shouldDelete)
		delete object->impl;

	object->impl = impl;
	object->shouldDelete = true;
	return true;
}
Esempio n. 16
0
UserAgent UserAgentParser::parse(const std::string& ua) const {
  return parseImpl(ua, static_cast<const UAStore*>(ua_store_));
}
Esempio n. 17
0
void component::parse(const string& buffer)
{
	m_parsedOffset = m_parsedLength = 0;

	parseImpl(buffer, 0, buffer.length(), NULL);
}
Esempio n. 18
0
/*
 * Rust is very liberal with nesting, so this function is used pretty much for any block
 */
static void parseBlock (lexerState *lexer, boolean delim, int kind, vString *scope)
{
	int level = 1;
	if (delim)
	{
		if (lexer->cur_token != '{')
			return;
		advanceToken(lexer, TRUE);
	}
	while (lexer->cur_token != TOKEN_EOF)
	{
		if (lexer->cur_token == TOKEN_IDENT)
		{
			size_t old_scope_len = vStringLength(scope);
			if (strcmp(lexer->token_str->buffer, "fn") == 0)
			{
				parseFn(lexer, scope, kind);
			}
			else if(strcmp(lexer->token_str->buffer, "mod") == 0)
			{
				parseMod(lexer, scope, kind);
			}
			else if(strcmp(lexer->token_str->buffer, "static") == 0)
			{
				parseStatic(lexer, scope, kind);
			}
			else if(strcmp(lexer->token_str->buffer, "trait") == 0)
			{
				parseTrait(lexer, scope, kind);
			}
			else if(strcmp(lexer->token_str->buffer, "type") == 0)
			{
				parseType(lexer, scope, kind);
			}
			else if(strcmp(lexer->token_str->buffer, "impl") == 0)
			{
				parseImpl(lexer, scope, kind);
			}
			else if(strcmp(lexer->token_str->buffer, "struct") == 0)
			{
				parseStructOrEnum(lexer, scope, kind, TRUE);
			}
			else if(strcmp(lexer->token_str->buffer, "enum") == 0)
			{
				parseStructOrEnum(lexer, scope, kind, FALSE);
			}
			else if(strcmp(lexer->token_str->buffer, "macro_rules") == 0)
			{
				parseMacroRules(lexer, scope, kind);
			}
			else
			{
				advanceToken(lexer, TRUE);
				if (lexer->cur_token == '!')
				{
					skipMacro(lexer);
				}
			}
			resetScope(scope, old_scope_len);
		}
		else if (lexer->cur_token == '{')
		{
			level++;
			advanceToken(lexer, TRUE);
		}
		else if (lexer->cur_token == '}')
		{
			level--;
			advanceToken(lexer, TRUE);
		}
		else if (lexer->cur_token == '\'')
		{
			/* Skip over the 'static lifetime, as it confuses the static parser above */
			advanceToken(lexer, TRUE);
			if (lexer->cur_token == TOKEN_IDENT && strcmp(lexer->token_str->buffer, "static") == 0)
				advanceToken(lexer, TRUE);
		}
		else
		{
			advanceToken(lexer, TRUE);
		}
		if (delim && level <= 0)
			break;
	}
}
Esempio n. 19
0
void BulletMLParserTinyXML::parse() {

    TiXmlDocument doc(name_);
    doc.LoadFile();
    parseImpl(doc);
}
void BulletMLParserTinyXML::parse() {
    TiXmlDocument doc(xmlFile_.c_str());
    doc.LoadFile();
	parseImpl(doc);
}
Esempio n. 21
0
void component::parse(const string& buffer)
{
	m_parsedOffset = m_parsedLength = 0;

	parseImpl(parsingContext::getDefaultContext(), buffer, 0, buffer.length(), NULL);
}
Esempio n. 22
0
void component::parse(const parsingContext& ctx, const string& buffer)
{
	m_parsedOffset = m_parsedLength = 0;

	parseImpl(ctx, buffer, 0, buffer.length(), NULL);
}
Esempio n. 23
0
Dynamic::Var ParserImpl::parseImpl(std::istream& in)
{
	std::ostringstream os;
	StreamCopier::copyStream(in, os);
	return parseImpl(os.str());
}