Beispiel #1
0
void PipelineReaderJSON::readPipeline(std::istream& input)
{
    Json::Value root;
    Json::CharReaderBuilder builder;
    builder["rejectDupKeys"] = true;
    std::string err;
    if (!parseFromStream(builder, input, &root, &err))
    {
        err = "JSON pipeline: Unable to parse pipeline:\n" + err;
        throw pdal_error(err);
    }

    if (root.isObject() && root.isMember("pipeline"))
    {
        parsePipeline(root["pipeline"]);
    }
    else if (root.isArray())
    {
        parsePipeline(root);
    }
    else
    {
        throw pdal_error("JSON pipeline: Root element is not a Pipeline");
    }
}
Beispiel #2
0
void PipelineReaderJSON::readPipeline(std::istream& input)
{
    Json::Value root;
    Json::Reader jsonReader;
    if (!jsonReader.parse(input, root))
        throw pdal_error("JSON pipeline: Unable to parse pipeline");

    Json::Value& subtree = root["pipeline"];
    if (!subtree)
        throw pdal_error("JSON pipeline: Root element is not a Pipeline");
    parsePipeline(subtree);
}
Beispiel #3
0
CMD *parsePipeline(token **lstHead)
{
	CMD *cmd = parseStage(lstHead);
	if(cmd->type == ERROR)
	{
		//propagate an error
		return cmd;
	}

	//check to make sure that end of linked list not reached and cmd not NULL!
	if(cmd && *lstHead && ISPIPE((*lstHead)->type))
	{
		CMD *stageCMD = cmd;
		cmd = mallocCMD();
		cmd->type = (*lstHead)->type;
		cmd->left = stageCMD;
		*lstHead = (*lstHead)->next;
		if(*lstHead == NULL)
		{
			//error..incomplete pipeline!
			fprintf(stderr,"%s\n","Error: Incomplete pipeline command");
			return errorCMD(cmd);
		}
		cmd->right = parsePipeline(lstHead);

		if(cmd->right == NULL)
		{
			//case of no right argument for pipe
			fprintf(stderr,"%s\n","Error: Incomplete pipeline command");
			return errorCMD(cmd);
		}

		if(cmd->right->type == ERROR)
		{
			//propagate along an error
			return cmd->right;
		}

		if(stageCMD->toFile != NULL || cmd->right->fromFile != NULL)
		{
			//case of multiple redirections involving a pipeline
			fprintf(stderr,"%s\n","Error: Multiple redirections");
			return errorCMD(cmd);
		}
	}
	return cmd;
}
Beispiel #4
0
enum ParserResult parse(struct Parser* parser,
        struct CompleteCommand* command) {
    enum ParserResult result = parsePipeline(parser, &command->pipeline);

    assert(result != PARSER_BACKTRACK);

    if (result == PARSER_MATCH &&
            parser->offset < parser->tokenizer->numTokens - 1) {
        syntaxError(getToken(parser));
        return PARSER_SYNTAX;
    }

    if (result == PARSER_SYNTAX) {
        syntaxError(getToken(parser));
    }
    return result;
}
Beispiel #5
0
CMD *parseAndOr(token **lstHead)
{
	CMD *cmd = parsePipeline(lstHead);
	if(cmd->type == ERROR)
	{
		//propagate an error
		return cmd;
	}

	//check to make sure that end of linked list not reached
	if(cmd && *lstHead && ((*lstHead)->type == SEP_AND || 
							(*lstHead)->type == SEP_OR))
	{
		CMD *pipelineCMD = cmd;
		cmd = mallocCMD();
		cmd->type = (*lstHead)->type;
		cmd->left = pipelineCMD;
		*lstHead = (*lstHead)->next;
		if(*lstHead == NULL)
		{
			//error..incomplete and/or
			fprintf(stderr,"%s\n","Error: Incomplete and/or command");
			return errorCMD(cmd);
		}
		cmd->right = parseAndOr(lstHead);

		if(cmd->right == NULL)
		{
			//case of no right arguments for and/or
			fprintf(stderr,"%s\n","Error: Incomplete and/or command");
			return errorCMD(cmd);
		}

		if(cmd->right->type == ERROR)
		{
			//propagate along an error
			return cmd->right;
		}
	}
	return cmd;
}