Exemplo n.º 1
0
	const Number FloatLiteralParser::ParseFractional(NumberBuilder & numberBuilder)
	{
		// Assert( NeedChar() == '.' )

		numberBuilder.SetFloat();
		Advance();
		if (AtEnd() || NotInClass(CharClass::DECIMAL))
		{
			if (config_.allow_trailing_point)
			{
				return numberBuilder.Release();
			}
			ThrowError("Decimal digit expected");
		}

		do
		{
			numberBuilder.OnFractionalDigit(GetChar() - '0');

			Advance();
			if (AtEnd())
			{
				return numberBuilder.Release();
			}
		}
		while (InClass(CharClass::DECIMAL));

		char c = GetChar();
		if (c == 'e' || c == 'E')
		{
			return ParseExponent(numberBuilder);
		}

		return numberBuilder.Release();
	}
Exemplo n.º 2
0
void StringTokenizer::GetNextToken()
{
    // skip till end of token
    while( !AtEnd() && IsWhitespace(*mCurrentPos) )
        mCurrentPos++;

    // this is the start of the token
    mCurToken = (char*)mCurrentPos;

    // skip till end of token
    for(; !AtEnd(); ++mCurrentPos)
    {
        if( IsWhitespace(*mCurrentPos) )
            break;

        if( IsDelimiter(*mCurrentPos) )
        {
            if( mCurrentPos == (Byte*)mCurToken )
                ++mCurrentPos;
            break;
        }
    }

    // end of search condition
    if( mCurrentPos == (Byte*)mCurToken )
    {
        mCurToken = 0;
        mCurTokenLength = 0;
    }
    else
    {
        mCurTokenLength = mCurrentPos - (Byte*)mCurToken;
    }
}
Exemplo n.º 3
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;
    }
Exemplo n.º 4
0
	bool CNumberRangeEnumerator::MoveToNext()
	{
		if (!AtEnd())
		{
			m_iEnumerator++;
		}
		return	AtEnd();
	}
Exemplo n.º 5
0
void CValidError_CI::Next(void)
{
    if ( AtEnd() ) {
        return;
    }

    do {
        ++m_Current;
    } while ( !AtEnd()  &&  !Filter(**m_Current) );
}
Exemplo n.º 6
0
	const Number IntegerLiteralParser::Parse()
	{
		// Assert( NotAtEnd() && InClass(CharClass::NUMBER_HEAD) )

		char c = GetChar();

		IntegerBuilder integerBuilder;

		if (c == '0')
		{
			Advance();
			if (AtEnd())
			{
				return Number::ZERO();
			}

			switch (GetChar())
			{
				case 'b' : return ParseBinary();
				case 'x' : return ParseHexadecimal();
			}

			if (NotInClass(CharClass::DECIMAL))
			{
				return Number::ZERO();
			}

			// if (config_.parse_octal)
			{
				return ParseOctal();
			}
		}
		else if (c == '-')
		{
			integerBuilder.SetNegative();
			Advance();
			if (AtEnd() || NotInClass(CharClass::DECIMAL))
			{
				ThrowError("Decimal digit expected");
			}
		}

		// Assert( NotAtEnd() && InClass(CharClass::DECIMAL) )
		do
		{
			integerBuilder.OnDecimalDigit(GetChar() - '0');

			Advance();
		}
		while (NotAtEnd() && InClass(CharClass::DECIMAL));

		return integerBuilder.Release();
	}
Exemplo n.º 7
0
bool hsStream::ReadLn(char *s, uint32_t maxLen, const char beginComment, const char endComment)
{
    char c;
    char endCom;
        endCom = endComment;

    while( true )
    {
        while( !AtEnd() && strchr("\r\n",c = ReadByte()) )
            c = c;
            ;
        if( AtEnd() )
            return false;

        if( beginComment != c )
            break;

        // skip to end of comment
        while( !AtEnd() && (endCom != (c = ReadByte())) )
            c= c;
            ;
    }

    s[0] = c;
    uint32_t k = 1;
    while( !AtEnd() && !strchr("\r\n",c = ReadByte()) )
    {
        if( k < maxLen )
            s[k++] = c;
    }
    s[k] = 0;


    if( (k > 0)&&!stricmp(s, "skip") )
    {
        int depth = 1;
        while( depth && ReadLn(s, maxLen, beginComment, endCom) )
        {
            if( !stricmp(s, "skip") )
                depth++;
            else
            if( !stricmp(s, "piks") )
                depth--;
        }
        return ReadLn(s, maxLen, beginComment, endCom);
    }

    return true;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
void MeaXMLNode::Dump() const
{
    static int indent = 0;

    CString indentStr(_T(' '), indent);

    TRACE(_T("%sNode Type: "), (LPCTSTR)indentStr);
    switch (m_type) {
    case Unknown:
        TRACE(_T("Unknown\n"));
        break;
    case Element:
        TRACE(_T("Element - %s\n"), m_data);
        break;
    case Data:
        TRACE(_T("Data - '%s'\n"), m_data);
        break;
    }

    for (NodeIter_c iter = GetChildIter(); !AtEnd(iter); ++iter) {
        indent += 4;
        (*iter)->Dump();
        indent -= 4;
    }
}
Exemplo n.º 10
0
    /// Tokenize the string using the specified set of char delimiters.
    ///
    /// @param target
    ///   Output container. 
    ///   Tokens defined in "str" by using symbols from "delim" are added
    ///   to the list "target".
    /// @param token_pos
    ///   Container for the tokens' positions in "str".
    /// @param empty_str
    ///   String added to target when there are no other characters between
    ///   delimiters
    ///
    void Do(TContainer&        target,
            TPosContainer&     token_pos,
            const TString&     empty_str = TString())
    {
        // Special cases
        if (m_Str.empty()) {
            return;
        } else if (m_Delim.empty()) {
            target.push_back(m_Str);
            token_pos.push_back(0);
            return;
        }

        // Do target space reservation (if applicable)
        TReserveTrait::Reserve(*this, target, token_pos);

        // Reposition to just after any initial delimiters
        m_Pos = 0;
        SkipDelims();

        // Tokenization
        //
        CTempStringList part_collector(m_Storage);
        SIZE_TYPE       prev_pos;
        do {
            prev_pos = m_Pos;
            if (Advance(&part_collector)) {
                target.push_back(empty_str);
                part_collector.Join(&target.back());
                part_collector.Clear();
                token_pos.push_back(prev_pos);
            }
        } while ( !AtEnd() );
    }
Exemplo n.º 11
0
/*----------------------------------------------------------------------------------------------
	Get the current feature values and character properties from the stream.
----------------------------------------------------------------------------------------------*/
void GrCharStream::CurrentFeatures(GrTableManager * ptman, GrFeatureValues * pfval)
{
	if (m_ichrRunOffset == kPosInfinity)
	{
		//	Not yet set up.
		if (AtEnd())
		{
			//	Empty stream; no valid values.
			Assert(false);
			return;
		}

		// Get the settings from the first character.
		int ichrSegOffset;
		int ichrPosSave = m_ichrPos;
		int ichrRunOffsetSave = m_ichrRunOffset;
		int ichlRunOffsetSave = m_ichlRunOffset;
		int cMapSize = m_vislotNextChunkMap.size();
		int cchrConsumed;
		NextGet(ptman, pfval, &ichrSegOffset, &cchrConsumed);
		// Put the character back.
		m_ichrPos = ichrPosSave;
		m_ichrRunOffset = ichrRunOffsetSave;
		m_ichlRunOffset = ichlRunOffsetSave;
		while (signed(m_vislotNextChunkMap.size()) > cMapSize)
			m_vislotNextChunkMap.pop_back();
	}
	else
	{
		*pfval = m_fvalRunFeats;
		//*ppchrp = &m_chrpRun;
	}
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
void AudioPrefsDialog::load()
{
	bug_fun();
	cfg.load();
	cfg.dump();

	for(auto page: pages)
	{
		bug_var(page);

		for(auto iter = page->GetIterator(); !iter.AtEnd(); iter.Next())
		{
			auto prop = iter.GetProperty();
			auto key = prop->GetName().ToStdString();
			if(!cfg.has(key))
				continue;
			if(auto p = dynamic_cast<wxStringProperty*>(prop))
				p->SetValueFromString(cfg.get(key, p->GetDefaultValue().GetString().ToStdString()));
			else if(auto p = dynamic_cast<wxColourProperty*>(prop))
				{}
			else if(auto p = dynamic_cast<wxEnumProperty*>(prop))
			{
				p->SetValueFromString(cfg.get(key, p->GetDefaultValue().GetString().ToStdString()));
			}
			else if(auto p = dynamic_cast<wxIntProperty*>(prop))
				p->SetValueFromInt(cfg.get(key, p->GetDefaultValue().GetInteger()));
			else if(auto p = dynamic_cast<wxFontProperty*>(prop))
			{
				bug_var(p->GetValue().GetString().ToStdString());
				p->SetValueFromInt(cfg.get(key, p->GetDefaultValue().GetInteger()));
			}
		}
	}
}
Exemplo n.º 14
0
bool TGztParser::ParseImports(Tokenizer* input, TGztFileDescriptorProto* file)
{
    TTokenizer tokenizer(input);
    Start(&tokenizer);
    if (CurrentEncoding() != CODES_UNKNOWN)
        file->set_encoding(NameByCharset(CurrentEncoding()));

    // Repeatedly parse statements until we reach the end of the file.
    while (!AtEnd())
    {
        if (TryConsume(';'))
            // empty statement; ignore
            continue;

        if (!LookingAt("import") || !ParseImport(file->add_dependency()))
        {
            // Parse imports or skip whole statement, but keep looping to parse
            // other statements.
            SkipStatement();
            SkipBlockEnd();
        }
    }

    return Finish();
}
Exemplo n.º 15
0
void RubberGroup::RemoveCur() {
    RubberList* doomed = cur;
    
    if (!AtEnd()) {
	cur = cur->Next();
	rlist->Delete(doomed);
    }
}
Exemplo n.º 16
0
	char Parser::NeedChar() const
	{
		if (AtEnd())
		{
			throw EndOfFile();
		}

		return GetChar();
	}
Exemplo n.º 17
0
Boolean PtrDynArrayIterator<T>::More() const
{
  if (_ArrayVarPtr->RunLength() == 0)
  {
    PtrDynArrayIterator<T>* const LocalThis_ = (PtrDynArrayIterator<T>* const)this;
    LocalThis_->_Index = SizeType(-1);
  }

  return !AtEnd();
}
Exemplo n.º 18
0
PtrDynArrayIterator<T>& PtrDynArrayIterator<T>::operator = (T* Ptr_)
{
  if (_ArrayVarPtr == NULL)
    Xnullp();

  if (!AtEnd())
    (*_ArrayVarPtr)[_Index] = Ptr_;

  return *this;
}
Exemplo n.º 19
0
	bool Parser::SkipChar(char c)
	{
		if (AtEnd() || GetChar() != c)
		{
			return false;
		}

		Advance();
		return true;
	}
Exemplo n.º 20
0
// Adjust the weights of all the samples to be uniform in the given charset.
// Returns the number of samples in the iterator.
int SampleIterator::UniformSamples() {
  int num_good_samples = 0;
  for (Begin(); !AtEnd(); Next()) {
    TrainingSample* sample = MutableSample();
    sample->set_weight(1.0);
    ++num_good_samples;
  }
  NormalizeSamples();
  return num_good_samples;
}
Exemplo n.º 21
0
        void Advance()
        {
            if (AtEnd())
            {
                return;
            }

            ++current_;

            FindNextBit();
        }
Exemplo n.º 22
0
PictSelection::PictSelection (Graphic* gs) : (gs) {
    valid = true;
}

// PictSelection knows it's the outermost PictSelection because it was
// called with a FILE* pointer, so it must read a version number, skip
// over its name, read its graphic state and children, and scale
// itself back to screen coordinates when it's finished.

PictSelection::PictSelection (FILE* stream, State* state) : (nil) {
    int fd = fileno(stream);
    istream from(fd);
    ReadVersion(from);
    ReadGridSpacing(from);
    if (versionnumber < 3) {
	Skip(from);
    }
    ReadPictGS(from, state);
    ReadChildren(from, state);
    ScaleToScreenCoords();
    valid = from.good();
}

// Copy returns a copy of the PictSelection.

Graphic* PictSelection::Copy () {
    Selection* copy = new PictSelection(this);
    for (First(); !AtEnd(); Next()) {
	copy->Append(GetCurrent()->Copy());
    }
    return copy;
}

// HasChildren returns true so Idraw can ungroup this Picture.

boolean PictSelection::HasChildren () {
    return Picture::HasChildren();
}

// Propagate must preserve the PictSelection's transformation matrix
// if it has any.

void PictSelection::Propagate () {
    Transformer* original = GetTransformer();
    if (original != nil) {
	original->Reference();
	Selection::Propagate();
	SetTransformer(original);
	delete original;
    } else {
	Selection::Propagate();
    }
}
Exemplo n.º 23
0
// Normalize the weights of all the samples in the charset_map so they sum
// to 1. Returns the minimum assigned sample weight.
double SampleIterator::NormalizeSamples() {
  double total_weight = 0.0;
  int sample_count = 0;
  for (Begin(); !AtEnd(); Next()) {
    const TrainingSample& sample = GetSample();
    total_weight += sample.weight();
    ++sample_count;
  }
  // Normalize samples.
  double min_assigned_sample_weight = 1.0;
  if (total_weight > 0.0) {
    for (Begin(); !AtEnd(); Next()) {
      TrainingSample* sample = MutableSample();
      double weight = sample->weight() / total_weight;
      if (weight < min_assigned_sample_weight)
        min_assigned_sample_weight = weight;
      sample->set_weight(weight);
    }
  }
  return min_assigned_sample_weight;
}
Exemplo n.º 24
0
const char* CTokenParser::NextCSVToken(CString &s)
  {
  s = NextToken(); //get value
  if (s==",")
    s = "";
  else
    {
    if (!AtLastToken() && !AtEnd())
      NextToken(); //get ',' separater
    }
  return (const char*)s;
  }
Exemplo n.º 25
0
void PictSelection::WriteData (ostream& to) {
    to << "Begin " << startdata << " Pict\n";
    WritePictGS(to);
    to << "\n";

    for (First(); !AtEnd(); Next()) {
	Selection* s = GetCurrent();
	s->WriteData(to);
    }

    to << "End " << startdata << " eop\n\n";
}
Exemplo n.º 26
0
PtrDynArrayIterator<T>& PtrDynArrayIterator<T>::operator [] (SizeType Index_)
{
  if (_ArrayVarPtr == NULL)
    Xnullp();

  _Index = Index_;
  if (!AtEnd())
    ((*_ArrayVarPtr)[_Index]);
  else
    ((*_ArrayVarPtr)[0]);

  return *this;
}
Exemplo n.º 27
0
bool TGztParser::Parse(Tokenizer* input, TGztFileDescriptorProto* file)
{
    TTokenizer tokenizer(input);
    Start(&tokenizer);
    if (CurrentEncoding() != CODES_UNKNOWN)
        file->set_encoding(NameByCharset(CurrentEncoding()));

    // Repeatedly parse statements until we reach the end of the file.
    while (!AtEnd())
        ParseTopLevelStatementOrSkip(file);

    return Finish();
}
Exemplo n.º 28
0
	const Number FloatLiteralParser::ParseExponent(NumberBuilder & numberBuilder)
	{
		// Assert( NeedChar() == 'e' || NeedChar() == 'E' )

		numberBuilder.SetFloat();
		Advance();
		if (AtEnd())
		{
			ThrowError("Decimal digit expected");
		}

		switch (GetChar())
		{
			case '-':
				numberBuilder.SetNegativeExponent();
			case '+':
				Advance();
				if (AtEnd())
				{
					ThrowError("Decimal digit expected");
				}
				break;
		}

		if (NotInClass(CharClass::DECIMAL))
		{
			ThrowError("Decimal digit expected");
		}

		do
		{
			numberBuilder.OnExponentDigit(GetChar() - '0');
			Advance();
		}
		while (NotAtEnd() && InClass(CharClass::DECIMAL));

		return numberBuilder.Release();
	}
Exemplo n.º 29
0
	const Number IntegerLiteralParser::ParseHexadecimal()
	{
		// Assert( NeedChar() == 'x' )

		IntegerBuilder integerBuilder;

		Advance();
		if (AtEnd() || NotInClass(CharClass::HEXADECIMAL))
		{
			ThrowError("Hexadecimal digit expected");
		}

		try
		{
			do
			{
				integerBuilder.OnHexadecimalDigit(HexToInt(GetChar()));

				Advance();
				if (AtEnd())
				{
					return integerBuilder.Release();
				}
			}
			while (InClass(CharClass::HEXADECIMAL));
		}
		catch (const IntegerBuilder::OverflowError &)
		{
			ThrowError("Hexadecimal number is too big");
		}

		if (InClass(CharClass::LETTER))
		{
			ThrowError("Hexadecimal digit expected");
		}

		return integerBuilder.Release();
	}
Exemplo n.º 30
0
	const Number IntegerLiteralParser::ParseBinary()
	{
		// Assert( NeedChar() == 'b' )

		IntegerBuilder integerBuilder;

		Advance();
		if (AtEnd() || NotInClass(CharClass::BINARY))
		{
			ThrowError("Binary digit expected");
		}

		try
		{
			do
			{
				integerBuilder.OnBinaryDigit(GetChar() - '0');

				Advance();
				if (AtEnd())
				{
					return integerBuilder.Release();
				}
			}
			while (InClass(CharClass::BINARY));
		}
		catch (const IntegerBuilder::OverflowError &)
		{
			ThrowError("Binary number is too big");
		}

		if (InClass(CharClass::DECIMAL))
		{
			ThrowError("Binary digit expected");
		}

		return integerBuilder.Release();
	}