Beispiel #1
0
		static void serialize(storage_type& s, const Alternative<T1, T2>& in)
			{
			s.serialize(in.isLeft());
			if (in.isLeft())
				s.serialize(in.left());
				else
				s.serialize(in.right());
			}
Beispiel #2
0
    void ControlList::addItem(const Alternative<String, const XBMCAddon::xbmcgui::ListItem* > & item, bool sendMessage)
    {
      XBMC_TRACE;

      if (item.which() == first)
        internAddListItem(ListItem::fromString(item.former()),sendMessage);
      else
        internAddListItem(item.later(),sendMessage);
    }
Beispiel #3
0
void AddAlternativeDefinitionImpl::operator()( boost::ptr_vector<Alternative> & alts, boost::ptr_vector<Matcher> & matchers, boost::ptr_map<AttributeKey,Expression> & bindings, const std::string & source, const std::string & transformSource ) const {
	Alternative * alternative = new Alternative( source, transformSource ); // Добавляем новую альтернативу к шаблону

	alternative->addMatchers( matchers ); // Добавляем сопоставители
	alternative->addBindings( bindings ); // Добавляем связывания
	alternative->updateDependencies(); // Обновляем зависимости альтернативы

	alts.push_back( alternative );
}
Beispiel #4
0
		bool operator==(const Alternative& in) const
			{
			if (isLeft() != in.isLeft())
				return false;
			if (isLeft())
				return in.left() == left();
				else
				return in.right() == right();
			}
Beispiel #5
0
		bool operator<(const Alternative& in) const
			{
			if (isLeft() && !in.isLeft())
				return false;
			if (!isLeft() && in.isLeft())
				return true;
			if (isLeft())
				return left() < in.left();
				else
				return right() < in.right();
			}
Beispiel #6
0
    void Player::play(const Alternative<String, const PlayList* > & item,
                      const XBMCAddon::xbmcgui::ListItem* listitem, bool windowed, int startpos)
    {
      XBMC_TRACE;

      if (&item == &defaultPlayParameter)
        playCurrent(windowed);
      else if (item.which() == XBMCAddon::first)
        playStream(item.former(), listitem, windowed);
      else // item is a PlayListItem
        playPlaylist(item.later(),windowed,startpos);
    }
Beispiel #7
0
Alternative<String, std::vector<String> > Dialog::browse(int type, const String& heading,
        const String& s_shares, const String& maskparam, bool useThumbs,
        bool useFileDirectories, const String& defaultt,
        bool enableMultiple) throw (WindowException)
{
    Alternative<String, std::vector<String> > ret;
    if (enableMultiple)
        ret.later() = browseMultiple(type,heading,s_shares,maskparam,useThumbs,useFileDirectories,defaultt);
    else
        ret.former() = browseSingle(type,heading,s_shares,maskparam,useThumbs,useFileDirectories,defaultt);
    return ret;
}
Beispiel #8
0
    void Player::play(const Alternative<String, const PlayList* > & item,
                      const XBMCAddon::xbmcgui::ListItem* listitem, bool windowed, int startpos)
    {
      TRACE;

      if (Alternative<String, const PlayList*>::isNullReference(item))
        playCurrent(windowed);
      else if (item.which() == XBMCAddon::first)
        playStream(item.former(), listitem, windowed);
      else // item is a PlayListItem
        playPlaylist(item.later(),windowed,startpos);
    }
void EpsilonNFA::NFAGenerator::visit(Alternative& node)
{
    NFAGenerator left, right;
    node.left()->accept(left);
    node.right()->accept(right);

    adopt_pool(left._pool);
    adopt_pool(right._pool);

    right.start->edges.push_back(Edge{ '\0', left.start });
    left.end->edges.push_back(Edge{ '\0', right.end });

    start = right.start;
    end = right.end;
    end->stateInfo = _info;
}
Beispiel #10
0
 virtual ParserResult handle_read(sip0x::utils::InputTokenStream& iss, FactoryContext* ctx) const override {
   return _alternative.read(iss, ctx);
 }
Beispiel #11
0
// Atom ::= "(" Expression ")" | "[" [^] Range "]" | Characters
Instruction* ParseAtom(const char **ppc, ParseInfo &info)
{
  Instruction *i = 0;
  const char *pc = *ppc;
  
  switch (*pc)
  {
    case '(':
    {
      Group::TriState dnl = Group::Inherit;
      Group::TriState nc = Group::Inherit;
      Group::TriState ml = Group::Inherit;
      bool capture = true;
      bool consume = true;
      bool invert = false;
      bool reverse = false;
      std::string name = "";
      
      ++pc;
      
      if (*pc == '?')
      {
        ++pc;
        if (*pc == '#')
        {
          // skip everything until ) and from behave as if ParseAtom was
          // called starting next character
          ++pc;
          while (*pc != ')')
          {
            if (*pc == '\0')
            {
              return 0;
            }
            ++pc;
          }
          *ppc = ++pc;
          return ParseAtom(ppc, info);
        }
        if (*pc == ':')
        {
          capture = false;
          ++pc;
        }
        else if (*pc == '(')
        {
          // conditional
          ++pc;
          
          std::string cond;
          while (*pc != ')')
          {
            if (*pc == '\0')
            {
              return 0;
            }
            cond.push_back(*pc);
            ++pc;
          }
          ++pc;
          
          Instruction *ci = ParseExpression(&pc, info);
          if (!ci || *pc != ')')
          {
            if (ci)
            {
              delete ci;
            }
            return 0;
          }
          ++pc;
          
          Alternative *alt = dynamic_cast<Alternative*>(ci);
          Instruction *ifTrue, *ifFalse;
          if (alt == 0)
          {
            ifTrue = ci;
            ifFalse = 0;
          }
          else
          {
            ifTrue = alt->first()->clone();
            ifFalse = alt->second()->clone();
            delete alt;
          }
          
          *ppc = pc;
          int index = 0;
          if (sscanf(cond.c_str(), "%d", &index) != 1)
          {
            return new Conditional(cond, ifTrue, ifFalse);
          }
          else
          {
            return new Conditional(index, ifTrue, ifFalse);
          }
        }
        else if (*pc == 'P')
        {
          ++pc;
          if (*pc == '<')
          {
            ++pc;
            while (*pc != '>')
            {
              if (*pc == '\0')
              {
                return 0;
              }
              name.push_back(*pc);
              ++pc;
            }
            ++pc;
          }
          else if (*pc == '=')
          {
            std::string name;
            ++pc;
            while (*pc != ')')
            {
              if (*pc == '\0')
              {
                return 0;
              }
              name.push_back(*pc);
              ++pc;
            }
            ++pc;
            *ppc = pc;
            return new Backsubst(name);
          }
          else
          {
            return 0;
          }
        }
        else if (*pc == '=')
        {
          // positive lookahead
          capture = false;
          consume = false;
          ++pc;
        }
        else if (*pc == '!')
        {
          // negative lookahead
          capture = false;
          consume = false;
          invert = true;
          ++pc;
        }
        else if (*pc == '<')
        {
          ++pc;
          if (*pc == '=')
          {
            // positive lookbehind
            capture = false;
            consume = false;
            reverse = true;
            ++pc;
          }
          else if (*pc == '!')
          {
            // negative lookbehind
            capture = false;
            consume = false;
            reverse = true;
            invert = true;
            ++pc;
          }
          else
          {
            Log::PrintError("[gcore] rex/ParseAtom: Invalid group format");
            return 0;
          }
        }
        else if (*pc == 'i' || *pc == 'm' || *pc == 's' || *pc == '-')
        {
          //capture = false;
          //consume = false;
          if (*pc == 'i')
          {
            // case sensitive off
            nc = Group::On;
            ++pc;
          }
          if (*pc == 'm')
          {
            // multiline on (. matches \r\n)
            ml = Group::On;
            ++pc;
          }
          if (*pc == 's')
          {
            // dot matches new line on
            dnl = Group::On;
            ++pc;
          }
          if (*pc == '-')
          {
            ++pc;
            if (*pc == 'i')
            {
              // case sensitive on
              nc = Group::Off;
              ++pc;
            }
            if (*pc == 'm')
            {
              // multiline off
              ml = Group::Off;
              ++pc;
            }
            if (*pc == 's')
            {
              // dot matches newline off
              dnl = Group::Off;
              ++pc;
            }
          }
          if (*pc != ':' && *pc != ')')
          {
            // either followed by : or group end (meaning we just want to change exp exec flags)
            Log::PrintError("[gcore] rex/ParseAtom: Invalid group format");
            return 0;
          }
          
          if (*pc == ':')
          {
            ++pc;
            // would having a closing parent here be problematic
          }
          else
          {
            capture = false;
            consume = false;
          }
        }
      }
      
      int gidx = (capture ? (++(info.numGroups)) : -1);
      unsigned short flags = (unsigned short)(reverse ? Rex::Reverse : 0);
      
      if (*pc != ')')
      {
        i = ParseExpression(&pc, info);
      }

      if (*pc != ')')
      {
        if (i)
        {
          delete i;
        }
        return 0;
      }
      
#ifdef _DEBUG_REX
      Log::PrintDebug("[gcore] rex/ParseAtom: Create group");
      Log::SetIndentLevel(Log::GetIndentLevel()+1);
      Log::PrintDebug("index: %d", gidx);
      Log::PrintDebug("invert: %d", invert);
      Log::PrintDebug("consume: %d", consume);
      Log::PrintDebug("flags: %d", flags);
      Log::PrintDebug("nc: %d", nc);
      Log::PrintDebug("ml: %d", ml);
      Log::PrintDebug("dnl: %d", dnl);
      Log::PrintDebug("name: %d", name.c_str());
      Log::PrintDebug("code: ");
      if (i)
      {
        std::ostringstream oss;
        
        Log::SetIndentLevel(Log::GetIndentLevel()+1)
        i->toStream(oss);
        Log::PrintDebug(oss.str().c_str());
        Log::SetIndentLevel(Log::GetIndentLevel()-1)
      }
      Log::SetIndentLevel(Log::GetIndentLevel()-1);
#endif
      
      i = new Group(gidx, i, !consume, invert, flags, nc, ml, dnl, name);
      
#ifdef _DEBUG_REX
      Log::PrintDebug("[gcore] rex/ParseAtom: Group created");
#endif
      ++pc;
      
      break;
    }
    case '[':
    {
      bool inv = false;
      ++pc;
      if (*pc == '^')
      {
        inv = true;
        ++pc;
      }
      i = ParseRange(&pc, inv, info);
      if (!i)
      {
        return 0;
      }
      if (*pc != ']')
      {
        Log::PrintError("[gcore] rex/ParseAtom: Invalid character '%c' in expression, expected ']'", *pc);
        if (i)
        {
          delete i;
        }
        return 0;
      }
      ++pc;
      break;
    }
    default:
      i = ParseCharacters(&pc, info);
      if (!i)
      {
        i = ParseZerowidth(&pc, info);
        if (!i)
        {
          return 0;
        }
      }
  }
  *ppc = pc;
  return i;
}
Beispiel #12
0
bool operator | (const Alternative<T1, T2>& alt, const Match<TMatch>& m)
	{
	return (alt.isLeft() ? (alt.left() |  m) : (alt.right() | m));
	}
Beispiel #13
0
bool operator == (const Alternative<T3, Alternative<T1, T2> >& alt, const TMatch& m)
	{
	return alt.isRight() && alt.right() == m;
	}
Beispiel #14
0
bool operator == (const Alternative<Alternative<T1, T2>, T3>& alt, const TMatch& m)
	{
	return alt.isLeft() && alt.left() == m;
	}