Exemplo n.º 1
0
static bool parse_http_version(Iterator& it, Request& request)
{
    skipws(it);
    bool res = expect(it, "HTTP/");
    std::string major, minor;
    res = res && consumeUntil(it, major, ".");
    res = res && expect(it, ".");
    res = res && consumeUntil(it, minor, "\r");

    if (res)
    {
        try
        {
            request.major = std::stoi(major);
            request.minor = std::stoi(minor);
        }
        catch (std::exception const& ex)
        {
            LOG(parser_logger, error) << "Cannot parse Major/Minor: "
                                      << ex.what();
            return false;
        }
    }

    return res;
}
Exemplo n.º 2
0
static bool parse_headers(Iterator& it, Request& request)
{
    bool res = true;
    while (res)
    {
        std::string key;
        std::string value;

        res = consumeUntil(it, key, ": \r");
        if (key.empty())
        {
            return res;
        }

        skipws(it);
        res = res && expect(it, ":");

        while (match(it, ' '))
        {
        }

        res = res && consumeUntil(it, value, "\r");

        if (res)
        {
            request.headers.emplace_back(std::move(key), std::move(value));
        }

        res = res && expect(it, HTTP_DELIMITER);
    }

    return false;
}
Exemplo n.º 3
0
static bool parse_uri(Iterator& it, Request& request)
{

    skipws(it);

    consumeUntil(it, request.uri, "? ");
    if (match(it, '?'))
    {
        do
        {
            std::string key;
            std::string value;

            bool res = consumeUntil(it, key, "&= ");
            if (match(it, '=')) {
                res = res && consumeUntil(it, value, "& ");
                key = UTILS::url_decode(key);
                value = UTILS::url_decode(value);
                request.query_params.emplace_back(std::move(key), std::move(value));
            }
            else
            {
                request.query_params.emplace_back(std::move(key), "");
            }

            if (!res)
            {
                return res;
            }
        } while (match(it, '&'));
    }

    return it != EOS;
}
Exemplo n.º 4
0
Token Scanner::readMethodDefinition()
{
    consumeUntil(".(#", "!?");
    QStringRef value = m_src.value();
    if (value == "self")
        return Token(Token::KeywordSelf, m_src.anchor(), m_src.length());

    if (!std::strchr("!?", m_src.peek(-1).toLatin1()))
        consumeUntil("(#", "!?");
    return Token(Token::Method, m_src.anchor(), m_src.length());
}
Exemplo n.º 5
0
bool FlowParser::importDecl(Unit* unit)
{
	FNTRACE();

	// 'import' NAME_OR_NAMELIST ['from' PATH] ';'
	nextToken(); // skip 'import'

	std::list<std::string> names;
	if (!importOne(names)) {
		consumeUntil(FlowToken::Semicolon);
		return false;
	}

	while (token() == FlowToken::Comma) {
		nextToken();
		if (!importOne(names)) {
			consumeUntil(FlowToken::Semicolon);
			return false;
		}
	}

	std::string path;
	if (consumeIf(FlowToken::From)) {
		path = stringValue();

		if (!consumeOne(FlowToken::String, FlowToken::RawString)) {
			consumeUntil(FlowToken::Semicolon);
			return false;
		}

		if (!path.empty() && path[0] != '/') {
			std::string base(lexer_->location().filename);

			size_t r = base.rfind('/');
			if (r != std::string::npos)
				++r;

			base = base.substr(0, r);
			path = base + path;
		}
	}

	for (auto i = names.begin(), e = names.end(); i != e; ++i) {
		if (importHandler && !importHandler(*i, path))
			return false;

		unit->import(*i, path);
	}

	consumeIf(FlowToken::Semicolon);
	return true;
}
Exemplo n.º 6
0
/**
 * Production:
 * 		stmt -> 'IF_IDEN' 'PAREN_S' expr 'PAREN_E' 'BRACE_S' stmt 'BRACE_E'
 */
void ifStatement(struct Term *term, FILE *input, ProgramData *prog){
	
	// vars
	char value;
	const unsigned int buf_size = 64;
	char misc_buf[buf_size];
	struct Term * new_term;
	
	// The 'IF_IDEN' terminal has already been consumed, process all else
	value = readNonEmptyChar(input, prog);
	if(value == PAREN_S){
		addChildTerm(createSingleCharTerm(PAREN_S), term);
	}
	else{
		// produce error
	}
	
	// consume the expression until the 'PAREN_E' is found
	if(consumeUntil(input, misc_buf, buf_size, PAREN_E, prog) == -1){
		// produce error
	}
	
	// produce a Term for the expression, then attempt to parse it
	addChildTerm(createTerm(misc_buf, buf_size), term);
	
	// parse statement within the if-statement
	// STUB
	
	// check parsed statement
	if(prog->has_error)
		return; // someone beneath us failed
	
	// add the closing parenthesis
	addChildTerm(createSingleCharTerm(PAREN_S), term);
	
	// next, consume the 'BRACE_S' identifier
	value = readNonEmptyChar(input, prog);
	if(value == PAREN_S){
		addChildTerm(createSingleCharTerm(BRACE_S), term);
	}
	else{
		// produce error
	}
	
	// consume the following statement
	
	
	// consume the final identifier, 'BRACE_E'
	
	
}
Exemplo n.º 7
0
void IOSCfgParser::certificate() {
	
	try {      // for error handling
		match(CERTIFICATE);
		match(WORD);
		if ( inputState->guessing==0 ) {
#line 185 "iosacl.g"
			
			consumeUntil(NEWLINE);
			consumeUntil(QUIT);
			
#line 536 "IOSCfgParser.cpp"
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}
Exemplo n.º 8
0
void IOSCfgParser::ip_unused_command() {
	
	try {      // for error handling
		switch ( LA(1)) {
		case ICMP:
		{
			match(ICMP);
			break;
		}
		case TCP:
		{
			match(TCP);
			break;
		}
		case HOST:
		{
			match(HOST);
			if ( inputState->guessing==0 ) {
#line 164 "iosacl.g"
				
				consumeUntil(NEWLINE);
				
#line 736 "IOSCfgParser.cpp"
			}
			break;
		}
		default:
		{
			throw ANTLR_USE_NAMESPACE(antlr)NoViableAltException(LT(1), getFilename());
		}
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}
Exemplo n.º 9
0
void IOSCfgParser::vlan() {
	
	try {      // for error handling
		match(VLAN);
		{
		switch ( LA(1)) {
		case WORD:
		{
			match(WORD);
			break;
		}
		case INT_CONST:
		{
			match(INT_CONST);
			break;
		}
		default:
		{
			throw ANTLR_USE_NAMESPACE(antlr)NoViableAltException(LT(1), getFilename());
		}
		}
		}
		if ( inputState->guessing==0 ) {
#line 507 "iosacl.g"
			
			importer->setCurrentLineNumber(LT(0)->getLine());
			importer->clearCurrentInterface();
			consumeUntil(NEWLINE);
			
#line 393 "IOSCfgParser.cpp"
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}
Exemplo n.º 10
0
void IOSCfgParser::community_list_command() {
	
	try {      // for error handling
		match(COMMUNITY_LIST);
		if ( inputState->guessing==0 ) {
#line 171 "iosacl.g"
			
			consumeUntil(NEWLINE);
			
#line 701 "IOSCfgParser.cpp"
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}
Exemplo n.º 11
0
void IOSCfgParser::unknown_command() {
	
	try {      // for error handling
		match(WORD);
		if ( inputState->guessing==0 ) {
#line 178 "iosacl.g"
			
			consumeUntil(NEWLINE);
			
#line 580 "IOSCfgParser.cpp"
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}
Exemplo n.º 12
0
int ANTLRParser::
_match_wdfltsig(ANTLRTokenType tokenWanted, SetWordType *whatFollows)
{
	if ( dirty==LLk ) consume();

	if ( LA(1)!=tokenWanted )
	{
        syntaxErrCount++;                                   /* MR11 */
		fprintf(stderr,
				"line %d: syntax error at \"%s\" missing %s\n",
				LT(1)->getLine(),
				(LA(1)==eofToken && LT(1)->getText()[0] == '@')?"<eof>":LT(1)->getText(), /* MR21a */
				token_tbl[tokenWanted]);
		consumeUntil( whatFollows );
		return 0;
	}
	else {
		dirty++;
		labase = (labase+1)&(LLk-1); // labase maintained even if !demand look
/*		if ( !demand_look ) consume(); */
		return 1;
	}
}
Exemplo n.º 13
0
void IOSCfgParser::controller() {
	
	try {      // for error handling
		match(CONTROLLER);
		if ( inputState->guessing==0 ) {
#line 517 "iosacl.g"
			
			importer->setCurrentLineNumber(LT(0)->getLine());
			importer->clearCurrentInterface();
			consumeUntil(NEWLINE);
			
#line 351 "IOSCfgParser.cpp"
		}
	}
	catch (ANTLR_USE_NAMESPACE(antlr)RecognitionException& ex) {
		if( inputState->guessing == 0 ) {
			reportError(ex);
			recover(ex,_tokenSet_2);
		} else {
			throw;
		}
	}
}