Пример #1
0
static int get_next_char()
{
    int c, nxt;
    c = fileGetc();
    if (c == EOF)
	return c;
    nxt = fileGetc();
    if (nxt == EOF)
	return c;
    fileUngetc(nxt);
    
    if (c == '-' && nxt == '-') {
	skip_rest_of_line();
	return get_next_char();
    }
    if (c == '{' && nxt == '-') {
	int last = '\0';
	do {
	    last = c;
	    c = get_next_char();
	} while (! (c == EOF || (last == '-' && c == '}')));
	return get_next_char();
    }
    return c;
}
Пример #2
0
istream& 
configpar<float>::readVal(std::istream &in) {
	float tmp = 0.0;

	in >> tmp;

	if ( ! in.good() && ! in.eof() )
		throw configParExceptionParseError("parsing float failed");

	skip_rest_of_line(in);

	value= tmp;

	return in;
}
Пример #3
0
istream& 
configpar<bool>::readVal(std::istream &in) {
	std::string tmp;

	in >> tmp;

	if ( tmp == "true" || tmp == "on" || tmp == "yes" || tmp == "1" )
		value = true;
	else if ( tmp == "false" || tmp == "off" || tmp == "no" || tmp == "0" )
		value = false;
	else
		throw configParExceptionParseError("parsing boolean type failed");

	skip_rest_of_line(in);

	return in;
}
Пример #4
0
/** returns inner content of a quoted string
 *  Matches pattern "[^"]*"\s* and returns matching part without quotes
 *
 */
std::string 
configparBase::parse_quoted_string(std::istream &in) {

	if ( in.get() != '"' )
		throw configParExceptionParseError("string doesn't start with a quotation mark");

	bool escape = false;
	std::string tmp;
	char c;

	while ( in.get(c) ) {
		if ( escape ) {
			if ( c == '\\' || c == '"' )
				tmp += c;
			else
				throw configParExceptionParseError("invalid escape sequence");

			escape = false;
		}
		else {
			if ( c == '"' )
				break;
			else if ( c == '\\' )
				escape = true;
			else
				tmp += c;
		}
	}

	// we should be on the closing quotation mark
	if ( c != '"' )
		throw configParExceptionParseError("unterminated string");

	skip_rest_of_line(in);

	return tmp;
}
Пример #5
0
static void findHaskellTags (int is_literate)
{
    vString *name = vStringNew ();
    char token[1001], arg[1001];
    int c;
    int in_tex_lit_code = 0;
    c = get_next_char();

    while (c != EOF)
    {
	if (c == '\n') {
	    c = get_next_char();
	    continue;
	}

	if (isspace(c)) {
	    skip_rest_of_line();
	    c = get_next_char();
	    continue;
	}
        if (is_literate && !in_tex_lit_code) {
            if (c == '>') {
                c = fileGetc();
                if (c == ' ') {
                    c = get_next_char();
		    if (!isident(c)) {
			    skip_rest_of_line();
			    c = get_next_char();
			    continue;
		    }
                } else {
                    skip_rest_of_line();
                    c = get_next_char();
                    continue;
                }
            } else if (c == '\\') {
                int n = get_line(token);
                if (strncmp(token, "begin{code}", 11) == 0) {
                    in_tex_lit_code = 1;
                    c = get_next_char();
                    continue;
		} else {
		    if (n > 0 && token[n-1] != '\n')
			skip_rest_of_line();
		    else
			c = get_next_char();
		}
		continue;
            } else {
                skip_rest_of_line();
                c = get_next_char();
                continue;
            }   
        }
        if (is_literate && in_tex_lit_code && c == '\\') {
            if (strncmp(token, "end{code}", 9) == 0) {
                in_tex_lit_code = 0;
                c = get_next_char();
                continue;
            }
        }
	token[0] = c;
	token[1] = '\0';
	if (!isident(c)) {
		skip_rest_of_line();
		c = get_next_char();
		continue;
	}
	if (!get_token(token, 1)) {
		c = get_next_char();
		continue;
	}
	do {
	    if ((c = fileGetc()) == EOF)
		return;
	} while (c == ' ' || c == '\t');
	arg[0] = c;
	get_token(arg, 1);
	if (strcmp(token, "data") == 0 || strcmp(token, "newtype") == 0) {
	    add_tag(arg, K_TYPE, name);
	    c = inside_datatype(name);
	    continue;
	}
	if (strcmp(token, "type") == 0)
	    add_tag(arg, K_TYPE, name);
	else if (strcmp(token, "module") == 0)
	    add_tag(arg, K_MODULE, name);
	else if (strcmp(token, "instance") == 0 ||
		 strcmp(token, "foreign") == 0 ||
		 strcmp(token, "import") == 0)
	    ;
	else {
	    if (arg[0] != ':')
		add_tag(token, K_FUNCTION, name);
	}
	skip_rest_of_line();
	c = get_next_char();
    }
    vStringDelete(name);
}
Пример #6
0
static int inside_datatype(vString *name)
{
    enum Find_State st = Find_Eq;
    int c;
    char token[1001];

    while (1) {
	if (st == Find_Eq)
	{
	    do {
		c = get_next_char();
		if (c == '\n') {
		    c = get_next_char();
		    if (! (c == ' ' || c == '\t')) {
			return c;
		    }
		}
	    } while (c != '=');
	    st = Find_Constr;
	}
	else if (st == Find_Constr)
	{
	    do {
		c = get_next_char();
	    } while (isspace(c));
	    if (!isupper(c)) {
		    skip_rest_of_line();
		    return '\n';
	    }
	    token[0] = c;
	    if (!get_token(token, 1))
		return '\n';
	    add_tag(token, K_CONSTRUCTOR, name);
	    st = Find_Extr;
	}
	else if (st == Find_Extr)
	{
	    c = get_next_char();
    	    if (c == '{')
		st = Get_Extr;
	    else if (c == '|')
		st = Find_Constr;
	    else if (c == '\n') {
		    c = get_next_char();
		    if (! (c == ' ' || c == '\t')) {
			return c;
		    }
	    }
	    else if (!isspace(c))
		st = Find_Bar;
	}
	else if (st == Get_Extr)
	{
	    do {
		c = fileGetc();
	    } while (isspace(c));
	    if (c == EOF)
		return c;
	    token[0] = c;
	    get_token(token, 1);
	    add_tag(token, K_FUNCTION, name);
	    do {
		c = get_next_char();
		if (c == '}') {
		    st = Find_Bar;
		    break;
		}
	    } while (c != ',');
	}
	else if (st == Find_Bar)
	{
	    do {
		c = get_next_char();
		if (c == '\n') {
		    c = get_next_char();
		    if (! (c == ' ' || c == '\t')) {
			return c;
		    }
		}
	    } while (c != EOF && c != '|');
	    st = Find_Constr;
	}
    }
    return '\n';
}