Пример #1
0
Token_type get_integer_token(FILE *fp, int *i)
{
    int c;

    c = skip_whitespace(fp);
    if (c == EOF)
        return Token_EOF;

    ungetc(c, fp);
    if (fscanf(fp, "%d", i) != 1)
        parse_error("integer constant expected");

    return Token_integer;
}
Пример #2
0
std::vector<std::string> wtss::cxx::client::list_coverages() const
{

  rapidjson::Document doc;
  doc.Parse<0>(wtss::cxx::request(
    wtss::cxx::client::server_uri + "/list_coverages").c_str());

  if (doc.HasParseError())
  {
    boost::format err_msg("Error parsing requested document '%1%/list_coverages: %2%.");

    throw parse_error() << error_description(
      (err_msg % server_uri %doc.GetParseError()).str());
  }

  if (!doc.IsObject())
    throw parse_error() << error_description(
        "Invalid JSON document: expecting a object!");

  if (!doc.HasMember("coverages"))
    throw parse_error() << error_description(
        "Invalid JSON document: expecting a member named \"coverages\"!");

  const rapidjson::Value& j_coverages = doc["coverages"];

  if (!j_coverages.IsArray())
    throw parse_error() << error_description(
        "Invalid JSON document: member named \"coverages\" must be an array!");

  std::vector<std::string> result;

  for (rapidjson::Value::ConstValueIterator itr = j_coverages.Begin();
       itr != j_coverages.End(); ++itr)
    result.push_back(itr->GetString());

  return result;
}
Пример #3
0
/*
 * Parses a set element.
 */
static apr_status_t process_set (parser_rec *p, const char *element,
		int states, apr_table_t *attrs) {
        template_node_t *n;
	const char *names;
        char *name, *last;
        const char *sep = ", \t";
        int status;

        if ((states & TEMPLATE_SOPEN) != 0) {
		n = (template_node_t *) apr_array_push(p->t);
		n->type = TEMPLATE_TSET;
                n->set_names = apr_array_make(p->pool, 2, sizeof(const char *));
                names = apr_table_get(attrs, "names");
                if (names == NULL) {
                        return parse_error(p, "missing attribute 'names'");
                }
                name = apr_strtok(apr_pstrdup(p->pool, names), sep, &last);
                while (name != NULL) {
                        *((char **) apr_array_push(n->set_names)) = name;
                        name = apr_strtok(NULL, sep, &last);
                }
                if (apr_is_empty_array(n->set_names)) {
                        return parse_error(p, "empty 'names'");
                }
                n->set_expressions = apr_table_get(attrs, "expressions");
                if (n->set_expressions == NULL) {
                        return parse_error(p, "missing attribute "
					"'expressions'");
                }
                if ((status = compile_exp(p, n->set_expressions, &n->set_index))
				!= APR_SUCCESS) {
                        return status;
                }
	}

	return APR_SUCCESS;
}
Пример #4
0
bool
ConstVarDecl::parse(std::ostream & os, std::shared_ptr<Context> context) {
	auto toker = context->getTokenizer();

	m_position = toker->position();
	bool flag = true;

	m_ident = toker->word();

    // add a constant declaration
    if(context->createConstant_llvm(m_ident, nullptr) == false) {
        parse_error(os, context, "Redefinition of constant: " + m_ident);
        flag = false;
    }//if

	toker->next(); // eat the current identifier

	if(toker->token() != Token::tk_equal) {
		parse_error(os, context, "expect an '=' here for const identifier initialization");
		flag = false;
	} else {
		toker->next(); // eat the current '='
	}//if-else

	if(flag == true && toker->token() == Token::tk_number) {
		// make_unique was overlooked by c++11, a simple implementation
		auto int_num = auc::make_unique<IntegerLiteral>();
		if(!int_num->parse(os, context))
			flag = false;
		m_node = std::move(int_num);
	} else {
		parse_error(os, context, "A const declearation must be initialized with a integer number.");
		flag = false;
	}//if-else

	return flag;
}//parse(os, context)
Пример #5
0
void help_text_area::handle_jump_cfg(const config &cfg)
{
	const std::string amount_str = cfg["amount"];
	const std::string to_str = cfg["to"];
	if (amount_str == "" && to_str == "") {
		throw parse_error("Jump markup must have either a to or an amount attribute.");
	}
	unsigned jump_to = curr_loc_.first;
	if (amount_str != "") {
		unsigned amount;
		try {
			amount = lexical_cast<unsigned, std::string>(amount_str);
		}
		catch (bad_lexical_cast) {
			throw parse_error("Invalid amount the amount attribute in jump markup.");
		}
		jump_to += amount;
	}
	if (to_str != "") {
		unsigned to;
		try {
			to = lexical_cast<unsigned, std::string>(to_str);
		}
		catch (bad_lexical_cast) {
			throw parse_error("Invalid amount in the to attribute in jump markup.");
		}
		if (to < jump_to) {
			down_one_line();
		}
		jump_to = to;
	}
	if (jump_to != 0 && static_cast<int>(jump_to) <
            get_max_x(curr_loc_.first, curr_row_height_)) {

		curr_loc_.first = jump_to;
	}
}
Пример #6
0
static AST vardecl() { /* TODO: allow vars */
    Token *t = &tok;
    AST a=0;
    AST a1=0,a2=0,a3=0,a4=0;
    AST ft;
    int idx;

    a2 = typedecl();
    a1 = var();		

    if (t->sym == '(') { /* oops, it was func */
	gettoken();
	set_nodetype(a1, nNAME); /* change to NAME */
	insert_SYM(get_text(a1), ft=func_type(gen(fLOCAL),a2), fLOCAL,0 /* dummy */ );

	a3 = argdecls();
	set_argtypeofnode(ft,a3);

	if (t->sym == ')') gettoken();
	else parse_error("expected )");

	a4 = block();
	a  = make_AST_funcdecl(a1, a2, a3, a4);
    } else if (t->sym == ';') { /* vardecl */
	a = make_AST_vardecl(a1, a2, 0, 0);
	idx = insert_SYM(get_text(a1), a2, vLOCAL, a1); 
	set_ival(a1,idx);
	/*
	   } else if (t->sym == ',') {  // multiple vars 
	 *     contents must be made
	 *
	 */
    } else {
	parse_error("expected ; or (");
    }
    return a;
}
Пример #7
0
void TinySpawn::run()
{
  // Working directory.
  const gchar *workingdirectory = NULL;
  if (!myworkingdirectory.empty())
    workingdirectory = myworkingdirectory.c_str();
  // Store arguments in argv.
  char *argv [arguments.size() + 2];
  argv[0] = (char *)myprogram;
  for (unsigned int i = 0; i < arguments.size(); i++) {
    argv[i + 1] = (char *)arguments[i].c_str();
  }
  // Terminate argv.
  argv[arguments.size() + 1] = NULL;
  // Spawn flags.
  int flags = G_SPAWN_SEARCH_PATH;
  // Possible pipes.
  gchar *standard_output = NULL;
  gchar *standard_error = NULL;
  gchar **standard_output_pointer = NULL;
  gchar **standard_error_pointer = NULL;
  if (myread) {
    standard_output_pointer = &standard_output;
    standard_error_pointer = &standard_error;
  }
  // Spawn process.
  result = g_spawn_sync(workingdirectory, argv, NULL, (GSpawnFlags) flags, NULL, NULL, standard_output_pointer, standard_error_pointer, &exitstatus, NULL);
  // Handle case we didn't spawn the process.
  if (!result) {
    exitstatus = -1;
    string message = myprogram;
    message.append(_(" didn't spawn"));
    g_critical("%s", message.c_str());
    return;
  }
  // Handle reading the output.
  if (myread) {
    // In sync mode we have gchar * output.
    ParseLine parse_output (standard_output);
    standardout = parse_output.lines;
    ParseLine parse_error (standard_error);
    standarderr = parse_error.lines;
    // Free data.
    if (standard_output)
      g_free(standard_output);
    if (standard_error)
      g_free(standard_error);
  }
}
Пример #8
0
static void Initializer(sym_pt templt){
	sym_pt initializer, instance;
	
	add_sym(instance);
	
	instance->type    = templt->type;
	instance->storage = templt->storage;
	instance->qual    = templt->qual;
	//instance->parent  = templt->parent;
	//instance->mtype   = templt->mtype;
	
	Instantiate_auto_members(instance, templt);
	
	if (Scanner::token() == T_ASS){ // Initialized value
		Scanner::next_token();
		
		if(instance->type == &Syms::none)
			parse_error("Cannot initialize an undefined type");
		
		
		initializer=Expression();
		if (!initializer->set)
			parse_error("Using an uninitialized value");
		if (initializer->storage == sc_constant){
			instance->value = initializer->value;
			instance->init  = true;
		
			//Syms::remove(initializer->full_name());
		}
		else Context_Stack::emit_op(I_ASS, instance, initializer, NULL);
		
		instance->set   = true;
	}
	else if (instance->qual == q_ro)
		parse_error("No initialization for a read only object");
}
Пример #9
0
help_text_area::ALIGNMENT help_text_area::str_to_align(const std::string &cmp_str)
{
	if (cmp_str == "left") {
		return LEFT;
	} else if (cmp_str == "middle") {
		return MIDDLE;
	} else if (cmp_str == "right") {
		return RIGHT;
	} else if (cmp_str == "here" || cmp_str == "") { // Make the empty string be "here" alignment.
		return HERE;
	}
	std::stringstream msg;
	msg << "Invalid alignment string: '" << cmp_str << "'";
	throw parse_error(msg.str());
}
Пример #10
0
int print_dependents(char* module_name)
{
	int i, n;
	int j, m;
	int ct;
	Var* v;
	char* dep_name;

	ct = 0; /* keep a count of dependents */

	if (VERBOSE) {
		parse_error("Dependents of %s:", module_name);
	}

	n = Narray_count(loaded_modules);

	for (i = 0; i < n; i++) {
		Narray_get(loaded_modules, i, &dep_name, (void**)&v);
		m = V_MODULE(v).init_stuff.ndep;

		for (j = 0; j < m; j++) {
			if (strcmp(V_MODULE(v).init_stuff.dep[j].name, module_name) == 0) {
				if (VERBOSE) {
					parse_error("%s%s", ((ct == 0) ? "" : ", "), dep_name);
				}
				ct++;
			}
		}
	}

	if (VERBOSE) {
		parse_error("Total %d dependents.", ct);
	}

	return ct;
}
Пример #11
0
void	hub_client2(char **tabcmd, t_client clt)
{
	if (ft_strcmp(tabcmd[0], "lls") == 0)
		lls(tabcmd);
	else if (ft_strcmp(tabcmd[0], "lpwd") == 0)
		ft_putendl(getcwd(NULL, 0));
	else if (ft_strcmp(tabcmd[0], "lcd") == 0)
		lcd(tabcmd, clt);
	else if (ft_strcmp(tabcmd[0], "put") == 0)
		put_hub(tabcmd, clt);
	else if (ft_strcmp(tabcmd[0], "get") == 0)
		get_hub(tabcmd, clt);
	else
		parse_error(tabcmd[0]);
}
Пример #12
0
clan::Colorf SvgAttributeReader::get_color()
{
	if (!is_color()) parse_error("expected color");

	size_t end_pos = pos + 1;
	while (end_pos < attr.length())
	{
		bool is_hex_char = (attr[end_pos] >= 'a' && attr[end_pos] <= 'f') || (attr[end_pos] >= 'A' && attr[end_pos] <= 'F') || (attr[end_pos] >= '0' && attr[end_pos] <= '9');
		if (!is_hex_char) break;
		end_pos++;
	}

	if (end_pos != pos + 4 && end_pos != pos + 7) parse_error("invalid color");

	clan::Colorf color;
	std::string hexstr = attr.substr(pos + 1, end_pos - pos - 1);
	unsigned int value = strtoul(hexstr.c_str(), 0, 16);
	if (end_pos == pos + 4)
	{
		int red = ((((value >> 8) & 0xf) + 1) << 4) - 1;
		int green = ((((value >> 4) & 0xf) + 1) << 4) - 1;
		int blue = (((value & 0xf) + 1) << 4) - 1;
		color = clan::Colorf(red / 255.0f, green / 255.0f, blue / 255.0f);
	}
Пример #13
0
/*
 *	RETURN statement
 *	Handles RETURN [ <expression> ] ;
 */
void
parse_return(TOKEN *first_token)
{
    TOKEN	token;
    int	token_class;

    out_white_space(first_token);
    out_str("return");

    token_class = parse_expression(&token);
    if (token_class != END_OF_LINE)
        parse_error("';' expected");
    else
        out_token(&token);
}
static int parse_range_list(char_stream_t cs, int_list_t il) {
  if (!parse_range(cs, il)) return 0;
  set_ok_pos(cs);
  while (cur_char(cs) == ',') {
    next_char(cs);
    if (!parse_range(cs, il)) return 0;
    set_ok_pos(cs);
  }
  if (cur_char(cs) != '\0') { 
    next_char(cs);
    parse_error(cs, "junk at the end of CPU list"); 
    return 0;
  }
  return 1;			/* OK */
}
Пример #15
0
  RR parse(T& t, RR rr, int_<N>)
  {
    if (!rr.first)
      return throw_<_except_>( t, unexpected_end_fragment(), rr);

    rr = this->parse(t, rr, int_<0>() );

    if ( !try_<_except_>(t) )
      return rr;

    if ( (*rr.first & 192)==128 )
      return this->parse(t, rr, int_<N-1>() );

    return throw_<_except_>( t, parse_error( distance(rr.first) ), rr);
  }
Пример #16
0
static AST var() {
    Token *t = &tok;
    AST a=0;
    int idx;

    if (t->sym == ID) {
	char *s = strdup(t->text);
	gettoken();
	/* ival may be changed later */
	a = make_AST_var(s,0);
    } else {
	parse_error("expected ID");
    }
    return a;
}
Пример #17
0
void			invalid_argument(t_parser *p, char expected, char got)
{
	char	*error_msg;

	if (expected & got)
		return ;
	error_msg = "Invalid arg, expected ";
	if (!(error_msg = ft_strjoin(error_msg, get_expected_chars(expected))))
		ERROR("Failed to malloc invalid arg expected msg");
	if (!(error_msg = ft_strjoin_free1(error_msg, ", got ")))
		ERROR("Failed to malloc invalid arg msg");
	if (!(error_msg = ft_strjoin_free1(error_msg, get_expected_chars(got))))
		ERROR("Failed to malloc invalid arg got msg");
	parse_error(p, error_msg);
}
Пример #18
0
// TODO add lookahead for sensor and control expressions
Expr* APDEvaluator::expression(const char* string) {
  Expr* expr;

  if(string[G_STRING_ITERATOR] == '(' || isdigit(string[G_STRING_ITERATOR])|| string[G_STRING_ITERATOR]=='c'|| string[G_STRING_ITERATOR]=='s') {
    if(NULL == (expr = (Expr*)malloc(sizeof(Expr)))) {
      exit(1);			// TODO this is not the way to handle this
    }

    expr = term(string, expr);
    expr = term_right(string, expr);
    return expr;
  } else {
    parse_error(string);
  }
}
Пример #19
0
// Implements \newcolumntype{C}[opt]{body}
// as \newcommand\cmd[opt]{body}
// Here \cmd is some internal name, stored in nct_tok[C]
void Parser::T_newcolumn_type()
{
  TokenList L = mac_arg();
  uint c = 0; 
  if(L.empty()) parse_error("Empty argument to \\newcolumntype");
  else if(L.size() != 1)
    parse_error("More than one token in argument to \\newcolumntype");
  else {
    if(L.front().is_a_char())
      c = L.front().char_val().get_value();
    if(!(c>0 && c<nb_newcolumn)) {
      parse_error("Argument to \\newcolumntype is not a 7bit character");
      c= 0;
    }
  }
  Buffer& B = hash_table.my_buffer();
  B.reset();
  B.push_back("newcolumtype@");
  B.push_back(uchar(c)); // special hack if c=0 !
  cur_tok = hash_table.locate(B);
  new_array_object.add_a_type(c,cur_tok);
  back_input();
  get_new_command(rd_always,false); // definition is local
}
Пример #20
0
static int
process_ef(struct state *cur, struct block *info,
		const char *name, scconf_block *blk)
{
	struct state	state;

	init_state(cur, &state);
	if (name == NULL) {
		parse_error(cur, "No name given for EF object.");
		return 1;
	}
	if (!(state.file = new_file(cur, name, SC_FILE_TYPE_WORKING_EF)))
		return 1;
	return process_block(&state, info, name, blk);
}
Пример #21
0
void selfn_monitor_cores(const char *arg)
{
        char *cp = NULL, *str = NULL;
        char *saveptr = NULL;

        if (arg == NULL)
                parse_error(arg, "NULL pointer!");

        if (strlen(arg) <= 0)
                parse_error(arg, "Empty string!");

        selfn_strdup(&cp, arg);

        for (str = cp; ; str = NULL) {
                char *token = NULL;

                token = strtok_r(str, ";", &saveptr);
                if (token == NULL)
                        break;
                parse_monitor_event(token);
        }

        free(cp);
}
Пример #22
0
bool DataTypeClassNameParser::Parser::get_collection_params(NameAndTypeParamsVec* params) {
  if (is_eos()) {
    params->clear();
    return true;
  }

  if (str_[index_] != '(') {
    parse_error(str_, index_,  "Expected '(' before collection parameters");
    return false;
  }

  ++index_; // Skip '('

  return get_name_and_type_params(params);
}
Пример #23
0
static void Field_declaration(sym_pt parent, member_type privacy){
	switch (Scanner::token()){
//	case T_INHER   : Decl_Inheritance(Parent)         ; break;
//	case T_PREFIX  : Decl_Prefix     (parent, privacy); break;
//	case T_POSTFIX : Decl_Postfix    (parent, privacy); break;
//	case T_INFIX   : Decl_Infix      (parent, privacy); break;
//	case T_DFLT    : Decl_Default    (parent)         ; break;
//	case T_FUN     : Decl_Fun        (parent, privacy); break;
	case T_TYPENAME: Decl_Instance   (parent, privacy); break;
	case T_TYPE    : Decl_Type       (parent, privacy); break;
	default:
		sprintf(err_array, "Could not match '%s' to any rule", Scanner::text());
		parse_error(err_array);
	}
}
Пример #24
0
Value
Parser::string()
{
	char buf[256];
	unsigned len = 0;

	read();
	while (len < sizeof(buf) && c != '"')
		buf[len++] = read();
	read();
	if (len == sizeof(buf))
		parse_error("string too long");
	buf[len] = 0;
	return make_string(buf, len);
}
Пример #25
0
static char *
skip_const(Oid index, char *sql, const char *arg1, const char *arg2)
{
    size_t	len;

    if ((arg1 && strncmp(sql, arg1, (len = strlen(arg1))) == 0) ||
            (arg2 && strncmp(sql, arg2, (len = strlen(arg2))) == 0))
    {
        sql[len] = '\0';
        return sql + len + 1;
    }

    /* error */
    return parse_error(index);
}
Пример #26
0
/* Reading the character after a '\' at the start of a usenet subscription */
static int
lex_start_esc(usenet_parser_t self, int ch)
{
    /* Watch for EOF */
    if (ch == EOF || ch == '\n') {
        parse_error(self, "unexpected end of line");
        return -1;
    }

    /* Anything else is part of the group pattern */
    self->has_not = 0;
    self->token_pointer = self->token;
    self->state = lex_group;
    return append_char(self, ch);
}
Пример #27
0
/*
 *	GOTO statement
 */
void
parse_goto(TOKEN *first_token)
{
    TOKEN	token;

    out_white_space(first_token);
    out_str("goto");

    if (get_token(&token) != IDENTIFIER)
        parse_error("Illegal GOTO label");
    else {
        out_token(&token);
        check_eol();
    }
}
Пример #28
0
/*
 * Parse ACL list.
 * The way we do this is we first split things like CHV1
 * into a method (SC_AC_CHV) and a reference (1).
 * When we're finished parsing the profile, the fake references
 * are replaced by the real references given in KEY or PIN
 * commands
 */
static int
do_acl(struct state *cur, int argc, char **argv)
{
	struct sc_file	*file = cur->file->file;
	char		oper[64], *what = NULL;

	memset(oper, 0, sizeof(oper));
	while (argc--) {
		unsigned int	op, method, id;

		strlcpy(oper, *argv++, sizeof(oper));
		if ((what = strchr(oper, '=')) == NULL)
			goto bad;
		*what++ = '\0';

		if (*what == '$') {
			method = SC_AC_SYMBOLIC;
			if (map_str2int(cur, what+1, &id, pinIdNames))
				return 1;
		} else
		if (get_authid(cur, what, &method, &id))
			goto bad;

		if (!strcmp(oper, "*")) {
			for (op = 0; op < SC_MAX_AC_OPS; op++) {
				sc_file_clear_acl_entries(file, op);
				sc_file_add_acl_entry(file, op, method, id);
			}
		} else {
			const sc_acl_entry_t *acl;

			if (map_str2int(cur, oper, &op, fileOpNames))
				goto bad;
			acl = sc_file_get_acl_entry(file, op);
			if (acl->method == SC_AC_NEVER
			 || acl->method == SC_AC_NONE
			 || acl->method == SC_AC_UNKNOWN)
				sc_file_clear_acl_entries(file, op);
			sc_file_add_acl_entry(file, op, method, id);
		}
	}
	return 0;

bad:	parse_error(cur, 
		"Invalid ACL \"%s%s%s\"\n",
		oper, what? "=" : "", what? what : "");
	return 1;
}
Пример #29
0
/* skip an unknown attribute (or abort if flags forbid unknown attributes) */
static void
unknown_attribute (XMPParseContext  *context,
                   GError          **error,
                   const gchar      *element_name,
                   const gchar      *attribute_name,
                   const gchar      *attribute_value)
{
  if (context->flags & XMP_FLAG_NO_UNKNOWN_ATTRIBUTES)
    parse_error (context, error, XMP_ERROR_UNKNOWN_ATTRIBUTE,
                 _("Unknown attribute \"%s\"=\"%s\" in element <%s>"),
                 attribute_name, attribute_value, element_name);
#ifdef DEBUG_XMP_PARSER
  g_print ("skipping unknown attribute \"%s\"=\"%s\" in element <%s>\n",
           attribute_name, attribute_value, element_name);
#endif
}
Пример #30
0
/*
 *	ENABLE or DISABLE statement
 */
void
parse_int_ctl(TOKEN *first_token)
{
    TOKEN	token;
    int	token_class;

    out_token(first_token);
    out_str("()");

    token_class = get_token(&token);
    if (token_class != END_OF_LINE) {
        parse_error("';' expected");
        return;
    }
    out_token(&token);
}