/**
        Check if current item is a "start group" tag with the given name and if so
        consumes that item.

        \param[in] name     Name of start group tag to check for.
        \param[in] dothrow  Should this function throw an exception if current
                            item is not a start group tag with the given name.
        
        \returns   true if current item is a start group tag with the given name,
                   else false.
        \throws    PersistUnexpectedDataException if next input is not the start of
                   expected group.
    */
    bool SCXFilePersistDataReader::ConsumeStartGroup(const std::wstring& name, bool dothrow /*= false*/)
    {
        std::wstreampos pos = m_Stream->tellg();
        try
        {
            Consume(L"<");
            Consume(L"Group");
            Consume(L"Name");
            Consume(L"=");
            ConsumeString(name);
            Consume(L">");
        }
        catch (PersistUnexpectedDataException& e)
        {
            m_Stream->seekg(pos);
            if (dothrow)
            {
                throw e;
            }
            return false;
        }
        
        m_StartedGroups.push_front(name);

        return true;
        
    }
Example #2
0
float TokParser::GetFloat()
{
	if(m_eof) { m_error = true; return 0.f; }
	if(m_tokType != T_NUMERIC)
	{
		m_error = true;
		Consume();
		return 0.f;
	}
	float value = (float)atof(m_token);
	Consume();
	// TODO: consider removing this and replacing with fprintf(out, "%1.8e", f)
	if(m_token[0] == ':')
	{
		Consume();
		char* endPtr;
		unsigned long rawValue = strtoul(m_token, &endPtr, 16);
		if(endPtr == m_token)
		{
			m_error = true;
			return 0.f;
		}
		unsigned int rawValue32 = (unsigned int)(rawValue);
		// TODO: correct endian-ness
		memcpy(&value, &rawValue32, sizeof(value));
		Consume();
	}
	return value;
}
int ConstExpression::P()
{
    Operator *op;
    if(op=GetOperator(Next()->type_id(),1)) // unary
    {
        Consume();
        int q = op->prec;
        int t = Exp(q);
        return MakeNode(op,t,0);
    }
    else if(Next()->type_id()==TKN_L_PAREN)
    {
        Consume();
        int t = Exp(0);
        Expect(TKN_R_PAREN);
        return t;
    }
    else if(Next()->type_id()==TKN_NUMBER)
    {
        int t = atoi(Next()->get_text().c_str());
        Consume();
        return t;
    }
    else
        exit(0);

}
Example #4
0
std::string PropertyParser::parseUnsigned() {
    switch(+CurrentTok.getKind()) {
    case clang::tok::kw_int:
        Consume();
        return "uint";
        break;
    case clang::tok::kw_long:
        Consume();
        if (Test(clang::tok::kw_int))
            return "unsigned long int";
        else if (Test(clang::tok::kw_long))
            return "unsigned long long";
        else
            return "ulong";
        break;
    case clang::tok::kw_char:
    case clang::tok::kw_short:
        Consume();
        if (Test(clang::tok::kw_int))
            return "unsigned short int";
        return "unsigned " + Spelling();
        break;
    default:
        return "unsigned";
        // do not consume;
    }
}
Example #5
0
    //{
    //   WriteMask 
    //   ReadMask
    //   Ref
    //   Comp
    //   Pass
    //   Fail
    //   ZFail
    // }
    NodePtr Parser::StencilBlock()
    {
        if (!Match(Token::TOK_LEFT_BRACE))
            return nullptr;
        NodePtr stencilNode = std::make_unique<StencilNode>();
        while (!AtEnd()) {
            if (LookAhead(Token::TOK_RIGHT_BRACE)) {
                Consume();
                break;
            }
            auto Next = Consume();
            FnInfix infix = s_StencilExpr[Next.GetType()].second;
            if (infix) {
                stencilNode = (this->*infix)(std::move(stencilNode), Next);
            } else {
                SpawnError("Parsing stencil block failed", "Unexpected token");
                break;
            }

            if (AtEnd()) {
                SpawnError("Unexpected EoF in Stencil block", "'}' expected");
                return nullptr;
            }
        }
        return stencilNode;
    }
    /**
        Check if current item is an "end group" tag with the given name and if so
        consumes that item.

        \param[in] dothrow  Should this function throw an exception if current
                            item is not an end group tag with expected name.

        \returns   true if current item is an end group tag with the given name,
                   else false.
        \throws SCXInvalidStateException if no group is opened.
        \throws PersistUnexpectedDataException if next tag is not a close tag
                of the currently open group and dothrow is true.
    */
    bool SCXFilePersistDataReader::ConsumeEndGroup(bool dothrow /*= false*/)
    {
        if (m_StartedGroups.empty())
        {
            throw SCXInvalidStateException(L"No open group when calling ConsumeEndGroup.", SCXSRCLOCATION);
        }

        std::wstreampos pos = m_Stream->tellg();
        try
        {
            Consume(L"</");
            Consume(L"Group");
            Consume(L">");
        }
        catch (PersistUnexpectedDataException& e)
        {
            m_Stream->seekg(pos);
            if (dothrow)
            {
                throw e;
            }
            return false;
        }
        
        m_StartedGroups.pop_front();

        return true;
    }
Example #7
0
 unique_ptr<QueryRuntimeFilter> Array() {
     if (!Consume("["))
         Error("[");
     kb_.PushArray();
     unique_ptr<QueryRuntimeFilter> filter = Bool();
     kb_.PopArray();
     if (!Consume("]"))
         Error("]");
     return filter;
 }
Example #8
0
 unique_ptr<QueryRuntimeFilter> Factor() {
     if (Consume("(")) {
         unique_ptr<QueryRuntimeFilter> filter = Bool();
         if (!Consume(")"))
             Error(")");
         return filter;
     } else if (CouldConsume("[")) {
         return Array();
     }
     Error("Missing expression");
     return nullptr;
 }
Example #9
0
double TokParser::GetDouble()
{
	if(m_eof) { m_error = true; return 0.0; }
	if(m_tokType != T_NUMERIC)
	{
		m_error = true;
		Consume();
		return 0.0;
	}
	double value = (double)atof(m_token);
	Consume();
	return value;
}
Example #10
0
bool TGztParser::ParseGztFileOption(TGztFileDescriptorProto* file) {
  DO(Consume("option"));
  Stroka option_name;
  DO(ConsumeString(&option_name, "Expected an option name."));
  if (option_name == "strip-names" || option_name == "strip_names" || option_name == "strip names")
      file->set_strip_names(true);
  //else if <other option here>
  else {
      AddError(Substitute("Unrecognized option \"$0\".", option_name));
      return false;
  }
  DO(Consume(";"));
  return true;
}
Example #11
0
unsigned int TokParser::GetUInt()
{
	if(m_eof) { m_error = true; return 0U; }
	if(m_tokType != T_NUMERIC)
	{
		m_error = true;
		Consume();
		return 0U;
	}
	unsigned long longval = strtoul(m_token, nullptr, 10);
	unsigned int value = (unsigned int)longval;
	Consume();
	return value;
}
Example #12
0
int TokParser::GetInt()
{
	if(m_eof) { m_error = true; return 0; }
	if(m_tokType != T_NUMERIC)
	{
		m_error = true;
		Consume();
		return 0;
	}

	int value = atoi(m_token);
	Consume();
	return value;
}
Example #13
0
bool TGztParser::ParseEncoding(Stroka* encoding_name) {
  DO(Consume("encoding"));
  DO(ConsumeString(encoding_name, "Expected a string naming the encoding to use."));
  ECharset enc = CharsetByName(encoding_name->c_str());
  if (enc == CODES_UNKNOWN) {
      AddError(Substitute("Unrecognized encoding \"$0\".", *encoding_name));
      return false;
  }
  DO(Consume(";"));

  SetEncoding(enc);

  return true;
}
Example #14
0
bool TokParser::ExpectTok(const char* str)
{
	if(m_eof) { m_error = true; return false; }
	if(m_tokType != T_TOK)
	{
		m_error = true;
		Consume();
		return 0;
	}
	bool result = strcmp(str, m_token) == 0;
	Consume();
	if(!result)
		m_error = true;
	return result;
}
Example #15
0
int TokParser::GetEnum(const TokFlagDef* def, int numFlags)
{
	if(m_eof) { m_error = true; return 0; }

	for(int i = 0; i < numFlags; ++i)
	{
		if(StrCaseEqual(def[i].m_name, m_token))
		{
			Consume();
			return def[i].m_flag;
		}
	}
	Consume();
	return 0;
}
Example #16
0
 bool Parser::ParseBlendFactor(ngfx::BlendFactor & src, ngfx::BlendFactor & dst)
 {
     if (!LookAhead(Token::TOK_IDENTIFIER) || !IsBlendFactor(Cur().Str())) {
         SpawnError("Parsing source Blend factor failed", "Unexpected token !");
         return false;
     }
     src = blendFactorKeywords[Consume().Str()];
     if (!LookAhead(Token::TOK_IDENTIFIER) || !IsBlendFactor(Cur().Str()))
     {
         SpawnError("Parsing dest Blend factor failed", "Unexpected token !");
         return false;
     }
     dst = blendFactorKeywords[Consume().Str()];
     return true;
 }
Example #17
0
 // Fog {}
 NodePtr Parser::Fog(std::unique_ptr<ParserNode> left, const Token & tok)
 {
     if (!Match(Token::TOK_LEFT_BRACE)) {
         SpawnError("Failed to parse Fog state", "Expected { here");
         return left;
     }
     while (!AtEnd()) {
         if (LookAhead(Token::TOK_RIGHT_BRACE)) {
             Consume();
             break;
         }
         Consume();
     }
     return left;
 }
Example #18
0
int TokParser::GetFlag(const TokFlagDef* def, int numFlags)
{
	if(m_eof) { m_error = true; return 0; }
	int value = 0;
	const char* curWord = m_token;
	const char* cursor = m_token;
	for(;;) {
		if(*cursor == '+' || !*cursor) {
			auto const len = cursor - curWord;
			for(int flag = 0; flag < numFlags; ++flag)
			{
				if(StrNCaseEqual(def[flag].m_name, curWord, static_cast<unsigned int>(len)))
				{
					value |= def[flag].m_flag;
					break;
				}
			}
			// warn here if flag not recognized?

			if(!*cursor)
				break;

			++cursor;
			curWord = cursor;
		}
		else
			++cursor;
	}
	Consume();
	return value;
}
Example #19
0
bool TGztParser::ParseBracketedValuesList(TFieldValueDescriptorProto* value)
{
    DO(Consume("["));
    value->set_type(TFieldValueDescriptorProto::TYPE_LIST);
    value->mutable_list()->set_type(TValuesListDescriptorProto::BRACKETED);
    bool last_was_delimiter = false;
    while (last_was_delimiter || !TryConsume(']')) {
        if (AtEnd()) {
            AddError("Unexpected end of stream while parsing bracketed list.");
            return false;
        }
        if (LookingAt('}')) {
            AddError("Missing ']'.");
            return false;
        }
        // Note that a bracketed list could contain any type of sub-value, including sub-lists of any type.
        DO(ParseChainedFieldValues(value->mutable_list()->add_value()));

        // consume items delimiter (if any), but only one.
        if (TryConsume(','))
            last_was_delimiter = true;
        else
            last_was_delimiter = TryConsume(';');
    }
    return true;
}
Example #20
0
bool TGztParser::ParseArticleBlock(NProtoBuf::RepeatedPtrField<TArticleFieldDescriptorProto>* article_fields)
{
    DO(Consume("{"));

    bool had_keyword_fields = false;
    while (!TryConsume('}')) {
        if (AtEnd()) {
            AddError("Reached end of input in article definition (missing '}').");
            return false;
        }
        if (!ParseArticleField(article_fields))
            // This statement failed to parse.  Skip it, but keep looping to parse
            // other statements.
            SkipStatement();
        else {
            //check if there is forbidden keyword/positional fields sequence
            bool last_is_keyword_field = article_fields->Get(article_fields->size()-1).has_name();
            if (last_is_keyword_field)
                had_keyword_fields = true;
            else if (had_keyword_fields) {
                AddError("Positional field (i.e. only a value without explicit field name) could not be used after non-positional (named) fields.");
                SkipStatement();
            }
        }

    }
    return true;
}
Example #21
0
ssize_t
DaemonSocketPDU::Send(int aFd)
{
  struct iovec iv;
  memset(&iv, 0, sizeof(iv));
  iv.iov_base = GetData(GetLeadingSpace());
  iv.iov_len = GetSize();

  struct msghdr msg;
  memset(&msg, 0, sizeof(msg));
  msg.msg_iov = &iv;
  msg.msg_iovlen = 1;
  msg.msg_control = nullptr;
  msg.msg_controllen = 0;

  ssize_t res = TEMP_FAILURE_RETRY(sendmsg(aFd, &msg, 0));
  if (res < 0) {
    MOZ_ASSERT(errno != EBADF); /* internal error */
    OnError("sendmsg", errno);
    return -1;
  }

  Consume(res);

  if (mConsumer) {
    // We successfully sent a PDU, now store the
    // result runnable in the consumer.
    mConsumer->StoreUserData(*this);
  }

  return res;
}
Example #22
0
int TokParser::GetSymbol(char* buffer, int maxLen)
{
	if(m_eof) { m_error = true; return 0; }
	if(m_tokType != T_SYMBOL)
	{
		m_error = true;
		Consume();
		return 0;
	}
	int i, len = maxLen - 1;
	for(i = 0; i < len && m_token[i]; ++i)
		buffer[i] = m_token[i];
	buffer[i] = '\0';
	Consume();
	return i;
}
Example #23
0
static void DoStatement (void)
/* Handle the 'do' statement */
{
    /* Get the loop control labels */
    unsigned LoopLabel      = GetLocalLabel ();
    unsigned BreakLabel     = GetLocalLabel ();
    unsigned ContinueLabel  = GetLocalLabel ();

    /* Skip the while token */
    NextToken ();

    /* Add the loop to the loop stack */
    AddLoop (BreakLabel, ContinueLabel);

    /* Define the loop label */
    g_defcodelabel (LoopLabel);

    /* Parse the loop body */
    Statement (0);

    /* Output the label for a continue */
    g_defcodelabel (ContinueLabel);

    /* Parse the end condition */
    Consume (TOK_WHILE, "`while' expected");
    TestInParens (LoopLabel, 1);
    ConsumeSemi ();

    /* Define the break label */
    g_defcodelabel (BreakLabel);

    /* Remove the loop from the loop stack */
    DelLoop ();
}
Example #24
0
    std::string TaskFactory::GetNextToken(char const * & text)
    {
        std::string token;

        SkipWhite(text);

        if (*text == '"')
        {
            // Quoted string literal
            ++text;
            while (*text != '"')
            {
                if (*text == '\0')
                {
                    RecoverableError error("Expected closing \" in string literal.");
                    throw error;
                }
                token.push_back(*text);
                ++text;
            }
            Consume(text, '"');
        }
        else if (*text != '\0')
        {
            // Non-quoted literal.
            std::string s;
            while (!IsSpace(*text) && *text != '\0')
            {
                token.push_back(*text);
                ++text;
            }
        }

        return token;
    }
Example #25
0
/**
expect( tok ) is
   if next = tok
       consume
   else
       error
*/
int ConstExpression::Expect(QUEX_TYPE_TOKEN_ID op)
{
    if (Next()->type_id() == op)
        Consume();
    else
        exit(0);

}
Example #26
0
unsigned TimeOutReceiver::TimeOutWait(unsigned expected_message_count,unsigned time_out_in_ms){
	unsigned long long int start=curtick();
	unsigned count(0);
	while(count<expected_message_count&&getMilliSecond(start)<time_out_in_ms){
		count+=Consume(expected_message_count-count);
	}
	return count;
}
Example #27
0
TokParser::TokParser(const char* data, size_t size)
	: m_tokenizer(data, size)
	, m_token()
	, m_error(false)
	, m_eof(false)
{
	Consume();
}
Example #28
0
void
UniString::LStrip(void)
{
	size_t i = 0;
	while (i < Length() && uni_isspace(At(i)))
		i++;
	Consume(i);
}
Example #29
0
void Active::Run() {
	if (m_BeginInThreadCallback){
		m_BeginInThreadCallback();
	}
	while (true){
		Consume();
	}
}
    /**
        Check if current item is a "value" tag with the given name and if so
        consumes that item and retrive the value.

        \param[in]  name     Name of value tag to check for.
        \param[out] value    Return value.
        \param[in]  dothrow  Should this function throw an exception if current
                             item is not a value tag with the given name.

        \returns   true if current item is a value tag with the given name, else
                   false.
    */
    bool SCXFilePersistDataReader::ConsumeValue(const std::wstring& name, std::wstring& value, bool dothrow /*= false*/)
    {
        std::wstreampos pos = m_Stream->tellg();
        try
        {
            Consume(L"<");
            Consume(L"Value");
            Consume(L"Name");
            Consume(L"=");
            ConsumeString(name);
            Consume(L"Value");
            Consume(L"=");
            value = ConsumeString();
            Consume(L"/>");
        }
        catch (PersistUnexpectedDataException& e)
        {
            m_Stream->seekg(pos);
            if (dothrow)
            {
                throw e;
            }
            return false;
        }
        
        return true;
    }