bool JSASTNode::Parse(const rapidjson::Value& value)
{
    assert(value.IsObject());

    for (Value::ConstMemberIterator itr = value.MemberBegin();
         itr != value.MemberEnd(); ++itr)
    {
        String name = itr->name.GetString();

        if (name == "loc")
        {
            ParseLoc(itr->value);
        }
        else if (name == "type")
        {
            // TODO: Verify type
        }
        else if (name == "range")
        {
            ParseRange(itr->value);
        }

    }

    return true;

}
Example #2
0
	virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) override
	{
		// Params: "<MinRelativeHeight>|<MaxRelativeHeight>", all optional
		m_MinRelHeight = 0;
		m_RelHeightRange = 1;
		return ParseRange(a_Params, m_MinRelHeight, m_RelHeightRange, a_LogWarnings);
	}
bool RequestParser::TestRange(bool expected,
                              const string& s,
                              int64_t expStart,
                              int64_t expEnd)
{
  int64_t start=-2, end=-2;
  bool r = ParseRange(s, start, end);
  return r == expected &&
          (!expected || start == expStart && end == expEnd);
}
void RequestParser::Parse(const string& s) {
  if (start == 0) {
    // Request line.
    ParseRequestLine(s);
  } else if (s.find("Range") == 0) {
    int64_t start,end;
    if (ParseRange(s, start, end)) {
      rangeStart = start;
      rangeEnd = end;
      hasRange = true;
    }
  }
}
Example #5
0
/* Parse an optional repetition specifier (?, +, * or { ... }), potentially
   followed by ?. */
static ABool ParseRepeatType(ParseInfo *info, unsigned *pMin, unsigned *pOpt)
{
    unsigned min, opt;
    AWideChar ch;

    ch = info->str < info->strEnd ? *info->str : '\0';

    info->str++;

    switch (ch) {
    case '?':
        min = 0;
        opt = 1;
        break;

    case '+':
        min = 1;
        opt = A_INFINITE_REPEAT;
        break;

    case '*':
        min = 0;
        opt = A_INFINITE_REPEAT;
        break;

    case '{':
        ParseRange(info, &min, &opt);
        break;

    default:
        min = 1;
        opt = 0;
        info->str--;
        break;
    }

    *pMin = min;
    *pOpt = opt;

    if (info->str < info->strEnd && *info->str == '?') {
        info->str++;
        return TRUE;
    } else
        return FALSE;
}
// For reasons of efficiency, this method does not use CRef<CSeq_interval> to access range 
// information - RW-26
void CFastaDeflineReader::ParseDefline(const string& defline,
    const SDeflineParseInfo& info,
    const TIgnoredProblems& ignoredErrors,
    list<CRef<CSeq_id>>& ids,
    bool& hasRange,
    TSeqPos& rangeStart,
    TSeqPos& rangeEnd,
    TSeqTitles& seqTitles, 
    ILineErrorListener* pMessageListener) 
{
    size_t start = 1, pos, len = defline.length(), title_start;
    size_t range_len = 0;
    const TFastaFlags& fFastaFlags = info.fFastaFlags;
    const TSeqPos& lineNumber = info.lineNumber;

    // ignore spaces between '>' and the sequence ID
    for( ; start < len; ++start ) {
        if( ! isspace(defline[start]) ) {
            break;
        }
    }

    do {
        bool has_id = true;
        if ((fFastaFlags & CFastaReader::fNoParseID)) {
            title_start = start;
        } else {
            // This loop finds the end of the sequence ID
            for ( pos = start;  pos < len;  ++pos) {
                unsigned char c = defline[pos];
                
                if (c <= ' ' ) { // assumes ASCII
                    break;
                } else if( c == '[' ) {

                    // see if this is part of a FASTA mod, which
                    // implies a pattern like "[key=value]".  We only check
                    // that it looks *roughly* like a FASTA mod and only before the '='
                    //
                    // It might be worth it to put the body of this "if" into its own function,
                    // for clarity if nothing else.

                    const size_t left_bracket_pos = pos;
                    ++pos;

                    // arbitrary, but shouldn't be too much bigger than the largest possible mod key for efficiency
                    const static size_t kMaxCharsToLookAt = 30; 
                    // we give up much sooner than the length of the string, if the string is long.
                    // also note that we give up *before* the end so even if pos
                    // reaches bracket_give_up_pos, we can still say defline[pos] without worrying
                    // about array-out-of-bounds issues.
                    const size_t bracket_give_up_pos = min(len - 1, kMaxCharsToLookAt);
                    // keep track of the first space we find, because that becomes the end of the seqid
                    // if this turns out not to be a FASTA mod.
                    size_t first_space_pos = kMax_UI4;

                    // find the end of the key
                    for( ; pos < bracket_give_up_pos ; ++pos ) {
                        const unsigned char c = defline[pos];
                        if( c == '=' ) {
                            break;
                        } else if( c <= ' ' ) {
                            first_space_pos = min(first_space_pos, pos);
                            // keep going
                        } else if( isalnum(c) || c == '-' || c == '_' ) {
                            // this is fine; keep going
                        } else {
                            // bad character, so this is NOT a FASTA mod
                            break;
                        }
                    }

                    if( defline[pos] == '=' ) {
                        // this seems to be a FASTA mod, so consider the left square bracket
                        // to be the end of the seqid
                        pos = left_bracket_pos;
                        break;
                    } else {
                        // if we stopped on anything but an equal sign, this is NOT a 
                        // FASTA mod.
                        if( first_space_pos < len ) {
                            // If we've found a space at any point, we consider that the end of the seq-id
                            pos = first_space_pos;
                            break;
                        }

                        // it's not a FASTA mod and we didn't find any spaces, so just
                        // keep going as normal, continuing from where we let off at "pos"
                    }
                }
            }

            //range_len = ParseRange(substr(defline.data() + start, pos - start),
            range_len = ParseRange(defline.substr(start, pos - start),
                rangeStart, rangeEnd, pMessageListener);
            //has_id = ParseIDs(substr(defline.data() + start, pos - start - range_len), 
            has_id = ParseIDs(defline.substr(start, pos - start - range_len), 
                              info,
                              ignoredErrors,
                              ids, 
                              pMessageListener);
            if (has_id  &&  (fFastaFlags & CFastaReader::fAllSeqIds)  &&  defline[pos] == '\1') {
                start = pos + 1;
                continue;
            }
            title_start = pos;
            // trim leading whitespace from title (is this appropriate?)
            while (title_start < len
                   &&  isspace((unsigned char) defline[title_start])) {
                ++title_start;
            }
        }
        for (pos = title_start + 1;  pos < len;  ++pos) {
            if ((unsigned char) defline[pos] < ' ') {
                break;
            }
        }
        if ( !has_id ) {
            // no IDs after all, so take the whole line as a title
            // (done now rather than earlier to avoid rescanning)
            title_start = start;
        }
        if (title_start < min(pos, len)) {
            // we parse the titles after we know what molecule this is
            seqTitles.push_back(
                SLineTextAndLoc(
                defline.substr(title_start, pos - title_start), lineNumber));
        }
        start = pos + 1;
    } while ( (fFastaFlags & CFastaReader::fAllSeqIds)  &&  start < len  &&  defline[start - 1] == '\1'
             &&  !range_len);

    hasRange = (range_len>0);
}
Example #7
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;
}
Example #8
0
static int
IpcpSetCommand(Context ctx, int ac, char *av[], void *arg)
{
  IpcpState		const ipcp = &ctx->bund->ipcp;
  struct in_addr	*ips;

  if (ac == 0)
    return(-1);
  switch ((intptr_t)arg) {
    case SET_RANGES:
      {
	struct u_range	self_new_allow;
	struct u_range	peer_new_allow;
	int pos = 0, self_new_pool = -1, peer_new_pool = -1;

	/* Parse args */
	if (ac < 2)
	    return (-1);
	if (strcmp(av[pos], "ippool") == 0) {
	    self_new_pool = pos+1;
	    pos+=2;
	} else {
	    if (!ParseRange(av[pos], &self_new_allow, ALLOW_IPV4))
		return(-1);
	    pos++;
	}
	if (pos >= ac)
	    return (-1);
	if (strcmp(av[pos], "ippool") == 0) {
	    if ((pos + 1) >= ac)
		return (-1);
	    peer_new_pool = pos+1;
	    pos+=2;
	} else {
	    if (!ParseRange(av[pos], &peer_new_allow, ALLOW_IPV4))
		return(-1);
	    pos++;
	}
	if (pos != ac)
	    return (-1);

	if (self_new_pool >= 0)
	    strlcpy(ipcp->conf.self_ippool, av[self_new_pool], sizeof(ipcp->conf.self_ippool));
	else
	    ipcp->conf.self_ippool[0] = 0;
	if (peer_new_pool >= 0)
	    strlcpy(ipcp->conf.ippool, av[peer_new_pool], sizeof(ipcp->conf.ippool));
	else
	    ipcp->conf.ippool[0] = 0;
	ipcp->conf.self_allow = self_new_allow;
	ipcp->conf.peer_allow = peer_new_allow;

      }
      break;

    case SET_DNS:
      ips = ipcp->conf.peer_dns;
      goto getPrimSec;
      break;
    case SET_NBNS:
      ips = ipcp->conf.peer_nbns;
getPrimSec:
      if (!inet_aton(av[0], &ips[0]))
	Error("invalid IP address: \'%s\'", av[0]);
      ips[1].s_addr = 0;
      if (ac > 1 && !inet_aton(av[1], &ips[1]))
	Error("invalid IP address: \'%s\'", av[1]);
      break;

    case SET_ACCEPT:
      AcceptCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_DENY:
      DenyCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_ENABLE:
      EnableCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_DISABLE:
      DisableCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_YES:
      YesCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_NO:
      NoCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    default:
      assert(0);
  }
  return(0);
}