Ejemplo n.º 1
0
NFA RE2NFA::parseBranch()
{
    NFA value = parsePiece();
    if (!hasNext())
        return value;
    NFA next;
    do {
        next = parsePiece();
        if (!next.isEmpty())
            value = NFA::createConcatenatingNFA(value, next);
    } while (!next.isEmpty() && hasNext());
    return value;
}
Ejemplo n.º 2
0
void PiecewiseReplacer::replace(const std::string& matchedKey, Parser& p)
{
	const char* start = p.curr;
	p.curr += matchedKey.length();

	std::unique_ptr<MacroOptions> options;
	decltype(p.parseBracketArgs()) argList;
	try {
		options = p.parseMacroOptions();
		argList = p.parseBracketArgs();
	}
	catch (const Exceptions::InvalidInputException& ex) {
		throw Exceptions::InvalidInputException(ex.message + " in " + matchedKey, __FUNCTION__);
	}

	if (options->opts.size() != 0)
		p.errorOnLine(matchedKey + " does not take options");

	if (options->flags.size() != 0)
		p.errorOnLine(matchedKey + " does not take flags");

	const size_t numArgs = argList->size();

	if (numArgs > 1)
		p.errorOnLine("Too many arguments for \\begin{piecewise}");

	bool rightBraceSeen = false;

	std::string replacement;

	if (numArgs == 1)
		replacement += argList->at(0) + " = ";

	replacement += "\\left\\{\\begin{array}{l l}\n";

	while (true) {
		p.readToNextLineText();
		if (p.curr >= p.end || std::distance(p.curr, p.end) <= (int)pieceKey.length())
			p.errorOnLine("End of file reached before reaching end of \"piecewise\" definition");

		if (strncmp(p.curr, endKey.c_str(), endKey.length()) == 0) {
			p.curr += endKey.length();
			break;
		}
		if (strncmp(p.curr, rbraceKey.c_str(), rbraceKey.length()) == 0) {
			if (rightBraceSeen)
				p.errorOnLine("\"" + rbraceKey + "\" seen twice (only needed once)");
			rightBraceSeen = true;
			p.curr += rbraceKey.length();
			continue;
		}
		replacement += parsePiece(p);
	}
	replacement += "\\end{array}\\right";
	replacement += (rightBraceSeen ? "\\}" : ".");

	p.replacements.emplace_back(start, p.curr, std::move(replacement));
}
Ejemplo n.º 3
0
/**
 * Reads text file
 */
void EquipReaderTxt::read(QString filename)
{
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qCritical() << "Unable to open file for reading: " << filename;
        return;
    }

    QTextStream in(&file);
    QString line;
    QString extraData;
    while (!in.atEnd()) {
        line = in.readLine();
        if (!parsePiece(line) && !line.isEmpty()) {
            extraData += line + '\n';
        }
    }

    if (!extraData.isEmpty()) {
        m_equip->setExtraData(extraData);
    }
}
Ejemplo n.º 4
0
static bool parseSexp(Game& game, sexp_t* expression)
{
  sexp_t* sub, *subsub;
  if( !expression ) return false;
  expression = expression->list;
  if( !expression ) return false;
  if(expression->val != NULL && strcmp(expression->val, "status") == 0)
  {
    GameState gs;
    while(expression->next != NULL)
    {
      expression = expression->next;
      sub = expression->list;
      if ( !sub ) return false;
      if(string(sub->val) == "game")
      {
          sub = sub->next;
          if ( !sub ) return false;
          gs.turnNumber = atoi(sub->val);
          sub = sub->next;
          if ( !sub ) return false;
          gs.playerID = atoi(sub->val);
          sub = sub->next;
          if ( !sub ) return false;
          gs.gameNumber = atoi(sub->val);
          sub = sub->next;
          if ( !sub ) return false;
          gs.TurnsToStalemate = atoi(sub->val);
          sub = sub->next;
      }
      else if(string(sub->val) == "Move")
      {
        sub = sub->next;
        bool flag = true;
        while(sub && flag)
        {
          Move object;
          flag = parseMove(object, sub);
          gs.moves[object.id] = object;
          sub = sub->next;
        }
        if ( !flag ) return false;
      }
      else if(string(sub->val) == "Piece")
      {
        sub = sub->next;
        bool flag = true;
        while(sub && flag)
        {
          Piece object;
          flag = parsePiece(object, sub);
          gs.pieces[object.id] = object;
          sub = sub->next;
        }
        if ( !flag ) return false;
      }
      else if(string(sub->val) == "Player")
      {
        sub = sub->next;
        bool flag = true;
        while(sub && flag)
        {
          Player object;
          flag = parsePlayer(object, sub);
          gs.players[object.id] = object;
          sub = sub->next;
        }
        if ( !flag ) return false;
      }
    }
    game.states.push_back(gs);
  }
  else if(string(expression->val) == "animations")
  {
    std::map< int, std::vector< SmartPointer< Animation > > > animations;
    while(expression->next)
    {
      expression = expression->next;
      sub = expression->list;
      if ( !sub ) return false;
      if(string(ToLower( sub->val ) ) == "move")
      {
        SmartPointer<move> animation = new move;
        if ( !parseMove(*animation, expression) )
          return false;

        animations[ ((AnimOwner*)&*animation)->owner ].push_back( animation );
      }
    }
    game.states[game.states.size()-1].animations = animations;
  }
  else if(string(expression->val) == "ident")
  {
    expression = expression->next;
    if ( !expression ) return false;
    sub = expression->list;
    while(sub)
    {
      subsub = sub->list;
      if ( !subsub ) return false;
      int number = atoi(subsub->val);
      if(number >= 0)
      {
        subsub = subsub->next;
        if ( !subsub ) return false;
        subsub = subsub->next;
        if ( !subsub ) return false;
        game.players[number] = subsub->val;
      }
      sub = sub->next;
    }
  }
  else if(string(expression->val) == "game-winner")
  {
    expression = expression->next;
    if ( !expression ) return false;
    expression = expression->next;
    if ( !expression ) return false;
    expression = expression->next;
    if ( !expression ) return false;
    game.winner = atoi(expression->val);
		expression = expression->next;
		if( !expression ) return false;
		game.winReason = expression->val;
  }

  return true;
}
Ejemplo n.º 5
0
void processInfo(char * txt, char * info , int * i, int len, bt_info_t *inf){
  //needs to increment i pass next item in dict
  //we care about:

  //char name[FILE_NAME_MAX]; //name of file
  //int piece_length; //number of bytes in each piece
  //int length; //length of the file in bytes
  //int num_pieces; //number of pieces, computed based on above two values
  //char ** piece_hashes; //pointer to 20 byte data buffers containing the sha1sum of each of the pieces

  if(!strcmp(info,"name")){
    char * name=parseString(txt,len,i);
    strcpy(inf->name,name);
    return;
  }
  if(!strcmp(info,"piece length")){
    inf->piece_length=parseInt(txt,len,i);
    //now i should be on the character after the "e"
    return;
  }
  if(!strcmp(info,"length")){
    inf->length=parseInt(txt,len,i);
    //now i should be on the character after the "e"
    return;
  }
  if(txt[*i]=='p'){
      return parseDict(txt,len,i,inf);
  }
  if(!strcmp(info,"pieces")){
    //shoudl be on colon now
    inf->num_pieces=(strToInt(txt,len,i)/20);
    if(txt[*i]==':') *i=*i+1;
    else fprintf(stderr,"wrong stuff bro\n");
    int j;
    //printf("pl=%d\n",inf->num_pieces);
    inf->piece_hashes=(char**)malloc(sizeof(char*)*inf->num_pieces);
    for(j=0;j<inf->num_pieces;j++){
        *(inf->piece_hashes+j)=(char*)malloc(20);
    }
    for(j=0;j<inf->num_pieces;j++){
        char * s=parsePiece(txt,len,i);
        memcpy(*(inf->piece_hashes+j), s, 20);
        free(s);
    }
    return;
  }
  else {
    char * temp; 
    //need to go through whatever follows the item in the dict
    switch (txt[*i]) {
      case '0' ... '9':
      //case '1':
      //case '2':
      //case '3':
      //case '4':
      //case '5':
      //case '6':
      //case '7':
      //case '8':
      //case '9':      
        temp=parseString(txt, len, i);
        free(temp);
        break;
      case 'd':
        parseDict(txt,len, i, inf);
        break;
      case 'i':
        parseInt(txt, len, i);
        break;
    }
  }

}