Пример #1
0
AST* ParseLogicalExpression(ParserState* parser) {
	AST* valueNode = ParseValue(parser);
	AST* lexpNode = NULL;

	switch(parser->currentToken.type) {
		case TOKEN_LT:
			lexpNode = CreateASTNode(SEM_LT, VALUE_EMPTY);
			break;
		case TOKEN_EQ:
			lexpNode = CreateASTNode(SEM_EQ, VALUE_EMPTY);
			break;
		case TOKEN_GT:
			lexpNode = CreateASTNode(SEM_GT, VALUE_EMPTY);
			break;
		case TOKEN_LTE:
			lexpNode = CreateASTNode(SEM_LTE, VALUE_EMPTY);
			break;
		case TOKEN_GTE:
			lexpNode = CreateASTNode(SEM_GTE, VALUE_EMPTY);
			break;
		default:
			return valueNode;
	}

	Advance(parser);

	AST* rhs = ParseValue(parser);

	AddASTChild(lexpNode, valueNode);
	AddASTChild(lexpNode, rhs);

	return lexpNode;
}
nsresult
nsSVGTransformSMILAttr::ValueFromString(const nsAString& aStr,
                                     const nsISMILAnimationElement* aSrcElement,
                                     nsSMILValue& aValue,
                                     PRBool& aPreventCachingOfSandwich) const
{
  NS_ENSURE_TRUE(aSrcElement, NS_ERROR_FAILURE);
  NS_ASSERTION(aValue.IsNull(),
    "aValue should have been cleared before calling ValueFromString");

  const nsAttrValue* typeAttr = aSrcElement->GetAnimAttr(nsGkAtoms::type);
  const nsIAtom* transformType = nsGkAtoms::translate;
  if (typeAttr) {
    if (typeAttr->Type() != nsAttrValue::eAtom) {
      // Recognized values of |type| are parsed as an atom -- so if we have
      // something other than an atom, then it means our |type| was invalid.
      return NS_ERROR_FAILURE;
    }
    transformType = typeAttr->GetAtomValue();
  }

  ParseValue(aStr, transformType, aValue);
  aPreventCachingOfSandwich = PR_FALSE;
  return aValue.IsNull() ? NS_ERROR_FAILURE : NS_OK;
}
nsresult
nsSVGAnimatedTransformList::SMILAnimatedTransformList::ValueFromString(
  const nsAString& aStr,
  const dom::SVGAnimationElement* aSrcElement,
  nsSMILValue& aValue,
  bool& aPreventCachingOfSandwich) const
{
  NS_ENSURE_TRUE(aSrcElement, NS_ERROR_FAILURE);
  MOZ_ASSERT(aValue.IsNull(),
             "aValue should have been cleared before calling ValueFromString");

  const nsAttrValue* typeAttr = aSrcElement->GetAnimAttr(nsGkAtoms::type);
  const nsIAtom* transformType = nsGkAtoms::translate; // default val
  if (typeAttr) {
    if (typeAttr->Type() != nsAttrValue::eAtom) {
      // Recognized values of |type| are parsed as an atom -- so if we have
      // something other than an atom, then we know already our |type| is
      // invalid.
      return NS_ERROR_FAILURE;
    }
    transformType = typeAttr->GetAtomValue();
  }

  ParseValue(aStr, transformType, aValue);
  aPreventCachingOfSandwich = false;
  return aValue.IsNull() ? NS_ERROR_FAILURE : NS_OK;
}
Пример #4
0
/* IScanner */
static inline int ParseSection(struct IParse *parse, struct ISettings *settings)
{
	ParseComment(parse);
	ParseSkip(parse);

	int code = ParsePeek(parse, 0);
	if (!(code == '[')) {
		return 0;
	}

	ParseRead(parse); /* [ */
	ParseSkip(parse);

	/* Section Name */
	char name[MAX_NAME];
	if (!ParseName(parse, name, MAX_NAME)) {
		return 0;
	}

	ParseSkip(parse);
	code = ParsePeek(parse, 0);
	if (!(code == ']')) {
		return 0;
	}

	ParseRead(parse); /* "]" */

	HSECTION section = NULL;
	if (!(section = CreateSection(settings, name))) {
		return 0;
	}

	while (ParseValue(parse, section));
	return 1;
}
Пример #5
0
/* helper. sets custom user attributes for user */
static void SetCustomAttributes(struct SystemManifest *policy)
{
  int i;
  int count;
  char *environment;
  char *buf[BIG_ENOUGH_SPACE], **tokens = buf;

  assert(policy != NULL);
  assert(policy->envp == NULL);

  /* get environment */
  environment = GetValueByKey(MFT_ENVIRONMENT);
  if(environment == NULL) return;

  /* parse and check count of attributes */
  count = ParseValue(environment, ", \t", tokens, BIG_ENOUGH_SPACE);
  ZLOGFAIL(count % 2 != 0, EFAULT, "odd number of user environment variables");
  ZLOGFAIL(count == 0, EFAULT, "invalid user environment");
  ZLOGFAIL(count == BIG_ENOUGH_SPACE, EFAULT, "user environment exceeded the limit");

  /* allocate space to hold string pointers */
  count >>= 1;
  policy->envp = g_malloc0((count + 1) * sizeof(*policy->envp));

  /* construct array of environment variables */
  for(i = 0; i < count; ++i)
  {
    char *key = *tokens++;
    char *value = *tokens++;
    int length = strlen(key) + strlen(value) + 1 + 1; /* + '=' + '\0' */

    policy->envp[i] = g_malloc0((length + 1) * sizeof(*policy->envp[0]));
    sprintf(policy->envp[i], "%s=%s", key, value);
  }
}
Пример #6
0
/* sets node_id in nap object and user argv[0] */
static void SetNodeName(struct NaClApp *nap)
{
  int i;
  char *buf[BIG_ENOUGH_SPACE], **tokens = buf;
  char *pgm_name = GetValueByKey(MFT_NODE);

  assert(nap != NULL);
  assert(nap->system_manifest != NULL);
  assert(nap->system_manifest->cmd_line != NULL);
  assert(nap->system_manifest->cmd_line_size > 0);

  /* set the node name (0st parameter) and node id (n/a for the user) */
  if(pgm_name == NULL)
  {
    nap->system_manifest->cmd_line[0] = NEXE_PGM_NAME;
    nap->system_manifest->node_id = 0;
  }
  else
  {
    i = ParseValue(pgm_name, ",", tokens, BIG_ENOUGH_SPACE);
    ZLOGFAIL(i != 2, EFAULT, "invalid NodeName specified");
    ZLOGFAIL(tokens[0] == NULL, EFAULT, "invalid node name");
    ZLOGFAIL(tokens[1] == NULL, EFAULT, "invalid node id");
    nap->system_manifest->cmd_line[0] = tokens[0];
    nap->system_manifest->node_id = ATOI(tokens[1]);
    ZLOGFAIL(nap->system_manifest->node_id == 0, EFAULT, "node id must be > 0");
  }

  /* put node name and id to the log */
  ZLOGS(LOG_DEBUG, "node name = %s, node id = %d",
      nap->system_manifest->cmd_line[0], nap->system_manifest->node_id);
}
Пример #7
0
bool json::Reader::ParseArray(ConfigValue& value)
{
	value.SetEmptyArray();
	
	_cur++; // Skip '['
	SkipSpaces();
	if(*_cur == ']')
	{
		_cur++;
		return true;
	}
	while(1)
	{
		ConfigValue& elem = value.Append();
		
		if(!ParseValue(elem))
			return false;
		
		SkipSpaces();

		char c = *_cur;
		if(c == ',') // Separator between elements (Optional)
		{
			_cur++;
			continue;
		}
		if(c == ']') // End of array
		{
			_cur++;
			break;
		}
	}
	return true;
}
Пример #8
0
/* helper. sets command line parameters for the user */
static void SetCommandLine(struct SystemManifest *policy)
{
  int i;
  char *parameters;
  char *buf[BIG_ENOUGH_SPACE], **tokens = buf;

  assert(policy != NULL);
  assert(policy->cmd_line == NULL);
  assert(policy->cmd_line_size == 0);

  /* get parameters */
  parameters = GetValueByKey(MFT_COMMANDLINE);

  /* if there is command line parse and check count of parameters */
  if(parameters != NULL)
  {
    policy->cmd_line_size = ParseValue(parameters, " \t", tokens, BIG_ENOUGH_SPACE);
    ZLOGFAIL(policy->cmd_line_size == 0, EFAULT, "invalid user parameters");
    ZLOGFAIL(policy->cmd_line_size == BIG_ENOUGH_SPACE, EFAULT, "too long user command line");
  }

  /*
   * allocate space to hold string pointers. 0st element reserved for argv[0].
   * also, the last element should be NULL so 1 extra element must be reserved
   */
  ++policy->cmd_line_size;
  policy->cmd_line = g_malloc0((policy->cmd_line_size + 1) * sizeof *policy->cmd_line);

  /* populate command line arguments array with pointers */
  for(i = 0; i < policy->cmd_line_size - 1; ++i)
    policy->cmd_line[i + 1] = tokens[i];
}
Пример #9
0
// ["?"]Keyword [["^"]Option["/"Translation]] 
// [":" 
//   ["^"]Value ["/" Translation].
// ]
Statement* Parser::ParseStatement()
{
	AutoDelete<Statement> statement(new Statement());
	
	if (!ParseKeyword(statement.Get())) {
		return NULL;
	}
	SkipWhitespaceSeparator();
	
	if (!ParseOption(statement.Get())) {
		return NULL;
	}
	
	SkipWhitespaceSeparator();
	// [":" ... ]
	if (GetCurrentChar() == ':') {
		NextChar();
		SkipWhitespaceSeparator();
		if (!ParseValue(statement.Get())) {
			return NULL;
		}
	}
	SkipWhitespaceSeparator();
	if (GetCurrentChar() == kEof || GetCurrentChar() == kLf || GetCurrentChar() == kCr) {
		UpdateStatementType(statement.Get());
		Statement* result = statement.Release();	
		return result;
	} else {
		Error("Newline expected at end of statement");
		return NULL;
	}
}
Пример #10
0
static const char *ParseObject(ParseArgs& args, const char *data)
{
    data = SkipWS(data + 1);
    if ('}' == *data)
        return data + 1;

    size_t pathIdx = args.path.Size();
    for (;;) {
        data = SkipWS(data);
        if ('"' != *data)
            return NULL;
        args.path.Append('/');
        data = ExtractString(args.path, data);
        if (!data)
            return NULL;
        data = SkipWS(data);
        if (':' != *data)
            return NULL;

        data = ParseValue(args, data + 1);
        if (args.canceled || !data)
            return data;
        args.path.RemoveAt(pathIdx, args.path.Size() - pathIdx);

        data = SkipWS(data);
        if ('}' == *data)
            return data + 1;
        if (',' != *data)
            return NULL;
        data++;
    }
}
Пример #11
0
CJsonNode CNetScheduleStructuredOutputParser::ParseObject(char closing_char)
{
    CJsonNode result(CJsonNode::NewObjectNode());

    while (isspace((unsigned char) *m_Ch))
        ++m_Ch;

    if (*m_Ch == closing_char) {
        ++m_Ch;
        return result;
    }

    while (*m_Ch == '\'' || *m_Ch == '"') {
        // New attribute/value pair
        string attr_name(ParseString(GetRemainder()));

        while (isspace((unsigned char) *m_Ch))
            ++m_Ch;
        if (*m_Ch == ':' || *m_Ch == '=')
            while (isspace((unsigned char) *++m_Ch))
                ;

        result.SetByKey(attr_name, ParseValue());

        if (!MoreNodes()) {
            if (*m_Ch != closing_char)
                break;
            ++m_Ch;
            return result;
        }
    }

    INVALID_FORMAT_ERROR();
}
Пример #12
0
_JATTA_EXPORT Jatta::JSON::Value Jatta::JSON::Parse(Jatta::String str)
{
    //Remove the unnecessary whitespacing.
    String newStr;
    bool insideString = false;
    for (UInt32 i = 0; i < str.GetLength(); i++)
    {
        if (insideString)
        {
            if (str[i] == Grammar::Structural::STRING_DELIMITOR)
            {
                newStr += str[i];
                insideString = false;
            }
            else
            {
                newStr += str[i];
            }
        }
        else if (str[i] == Grammar::Structural::STRING_DELIMITOR)
        {
            newStr += str[i];
            insideString = true;
        }
        else if (str[i] != ' ' && str[i] != '\t' && str[i] != '\n' && str[i] != '\r')
        {
            newStr += str[i];
        }
    }

    //Parse!
    return ParseValue(newStr);
}
Пример #13
0
	void SPropertyItemColor::SetStringOnly( const SStringT & strValue )
	{

		COLORREF crTmp;
		crTmp = CR_INVALID;
		ParseValue(strValue,crTmp);
		m_crValue = crTmp;
	}
Пример #14
0
SEXP ParseArray(yajl_val node, int bigint){
  int len = YAJL_GET_ARRAY(node)->len;
  SEXP vec = PROTECT(allocVector(VECSXP, len));
  for (int i = 0; i < len; ++i) {
    SET_VECTOR_ELT(vec, i, ParseValue(YAJL_GET_ARRAY(node)->values[i], bigint));
  }
  UNPROTECT(1);
  return vec;
}
Пример #15
0
bool LinkPartition::ParseAttributes( LinkTokenizer &spec)
{
    /* optional */
    if (spec.Matches(LinkTokenizer::eBracketOpen))
    {
        bool done = false;
        spec.NextToken();
        while (!done)
        {
            switch(spec.GetTokenType())
            {
                LinkExpression *value;
                case LinkTokenizer::eAddr:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetAddress(value);
                    break;
                case LinkTokenizer::eSize:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetSize(value);
                    break;
                case LinkTokenizer::eMaxSize:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetMaxSize(value);
                    break;
                case LinkTokenizer::eRoundSize:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetRoundSize(value);
                    break;
                case LinkTokenizer::eFill:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetFill(value);
                    break;
                case LinkTokenizer::eAlign:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetAlign(value);
                    break;
                case LinkTokenizer::eVirtual:
                    if (!ParseValue(spec, &value))
                        return false;
                    attribs.SetVirtualOffset(value);
                    break;
                default:
                    return false;
            }
            if (spec.GetTokenType() != LinkTokenizer::eComma)
                done = true;
            else
                spec.NextToken();
        }
        return spec.MustMatch(LinkTokenizer:: eBracketClose);
    }
    return true;
}
Пример #16
0
void JsonReader::ParseStream()
{
    log_trace();
    SkipWhiteSpace();

    if (!is_.Eof())
    {
        ParseValue();
    }
}
Пример #17
0
bool Parse(const char *data, ValueVisitor *visitor)
{
    ParseArgs args(visitor);
    if (str::StartsWith(data, UTF8_BOM))
        data += 3;
    const char *end = ParseValue(args, data);
    if (!end)
        return false;
    return args.canceled || !*SkipWS(end);
}
Пример #18
0
//-------------------------------------------------------------------------------
bool json::Reader::Read(const char* doc, int64_t length, ConfigValue& root)
{
	_cur = _begin = doc;
	_end = doc + length;

	SkipSpaces();
	if(*_cur == '{')
		return ParseObject(root);
	
	// Assume root is an object
	root.SetEmptyObject();

	std::string name;
	while(1)
	{
		SkipSpaces();
		if(_cur == _end)
			break;


		name = "";
		if(!ParseString(name))
		{
			Error("Failed to parse string");
			return false;
		}

		SkipSpaces();
		if(*_cur != '=' && *_cur != ':')
		{
			Error("Expected '=' or ':'");
			return false;
		}
		_cur++;
		
		ConfigValue& elem = root[name.c_str()];
		if(!ParseValue(elem))
		{
			return false; // Failed to parse value
		}

		SkipSpaces();

		char c = *_cur;
		if(c == ',') // Separator between elements (Optional)
		{
			_cur++;
			continue;
		}
	}

	return true;
}
Пример #19
0
bool json::Reader::ParseObject(ConfigValue& value)
{
	value.SetEmptyObject();
	
	_cur++; // Skip '{'
	SkipSpaces();
	if(*_cur == '}') // Empty object
	{
		_cur++;
		return true;
	}	

	std::string name;
	while(1)
	{
		SkipSpaces();

		name = "";
		if(!ParseString(name))
		{
			Error("Failed to parse string");
			break; // Failed to parse string
		}

		SkipSpaces();
		if(*_cur != '=' && *_cur != ':')
		{
			Error("Expected '=' or ':'");
			return false;
		}
		_cur++;

		ConfigValue& elem = value[name.c_str()];
		if(!ParseValue(elem))
			break; // Failed to parse value

		SkipSpaces();

		char c = *_cur;
		if(c == ',') // Separator between elements (Optional)
		{
			_cur++;
			continue;
		}
		if(c == '}') // End of object
		{
			_cur++;
			return true;
		}		
	}	

	return false;
}
Пример #20
0
    void SPropertyItemColor::SetString( const SStringT & strValue )
    {

		COLORREF crTmp;
		crTmp = CR_INVALID;
		ParseValue(strValue,crTmp);
		if (m_crValue != crTmp)
		{
			m_crValue = crTmp;
			OnValueChanged();
		}
    }
Пример #21
0
/*
============
Term
============
*/
def_t *Compiler::Term( void )
{
	def_t	   *e;
	int      op;
	etype_t	t;
	
	if ( lex.Check( "!" ) )
	{
		e = Expression( NOT_PRIORITY );
		t = e->type->type;
		switch( t )
		{
		case ev_float :
			op = OP_NOT_F;
            break;
			
		case ev_string :
            op = OP_NOT_S;
            break;
			
		case ev_entity :
			op = OP_NOT_ENT;
            break;
			
		case ev_vector :
            op = OP_NOT_V;
            break;
			
		case ev_function :
            op = OP_NOT_FNC;
            break;
			
		default :
			lex.ParseError( "type mismatch for !" );
			
            // shut up compiler
            op = OP_NOT_FNC;
            break;
		}
		
		return Statement( &pr_opcodes[ op ], e, 0 );
	}
	
	if ( lex.Check( "(" ) )
	{
		e = Expression( TOP_PRIORITY );
		lex.Expect( ")" );
		
		return e;
	}
	
	return ParseValue();
}
Пример #22
0
SEXP ParseObject(yajl_val node, int bigint){
  int len = YAJL_GET_OBJECT(node)->len;
  SEXP keys = PROTECT(allocVector(STRSXP, len));
  SEXP vec = PROTECT(allocVector(VECSXP, len));
  for (int i = 0; i < len; ++i) {
    SET_STRING_ELT(keys, i, mkCharCE(YAJL_GET_OBJECT(node)->keys[i], CE_UTF8));
    SET_VECTOR_ELT(vec, i, ParseValue(YAJL_GET_OBJECT(node)->values[i], bigint));
  }
  setAttrib(vec, R_NamesSymbol, keys);
  UNPROTECT(2);
  return vec;
}
Пример #23
0
DateTime::DateTime(const std::string& value, const std::string& pattern)	
	:
	m_year				(ParseValue(value, pattern, "%YYYY")),
	m_month				(ParseValue(value, pattern, "%MM")),
	m_day					(ParseValue(value, pattern, "%DD")),
	m_hour				(ParseValue(value, pattern, "%hh")),
	m_minute			(ParseValue(value, pattern, "%mm")),
	m_second			(ParseValue(value, pattern, "%ss")),
	m_millisecond	(ParseValue(value, pattern, "%ms"))
{
}
Пример #24
0
AST* ParseArgumentList(ParserState* parser) {
	AST* arglist = CreateASTNode(SEM_EMPTY, VALUE_EMPTY);	

	/* FIXME: At this time, ArgumentList is used both for calling
	 * and defining functions, which is wrong as it allows using
	 * constants as formal arguments of a function */
	while(parser->currentToken.type != TOKEN_RIGHTBRACKET) {
		AST* argument = ParseValue(parser);
		AddASTChild(arglist, argument);
		if(parser->currentToken.type != TOKEN_RIGHTBRACKET)
			Match(parser, TOKEN_COMMA);
	}

	return arglist;
}
Пример #25
0
 const State* Transition(const Token& tok, FormatTokensVisitor& visitor) const override
 {
   switch (tok.Type)
   {
   case DELIMITER:
     return this;
   case OPERATION:
     return ParseOperation(tok, visitor);
   case CONSTANT:
   case MASK:
     return ParseValue(tok, visitor);
   default:
     return State::Error();
   }
 }
Пример #26
0
/**
 * @brief Parse a JSON array and fill it with data elements from the lexer.
 */
bool JsonProcessor::ParseArray (
    Lexer::iterator& ct,
    Lexer::iterator& end,
    JsonValueArray*        value
) {
    // proper usage of this function is to hand over a valid pointer to a json array, so check
    // for this here.
    assert(value);

    if (ct == end || !ct->IsBracket("[")) {
        LOG_WARN << "JSON array does not start with '[' at " << ct->at() << ".";
        return false;
    }

    ++ct;
    while (ct != end) {
        // proccess the array element
        JsonValue* element = nullptr;
        if (!ParseValue(ct, end, element)) {
            return false;
        }
        value->Add(element);

        // check for end of array, leave if found
        if (ct == end || ct->IsBracket("]")) {
            break;
        }

        // check for delimiter comma (indicates that there are more elements following)
        if (!ct->IsOperator(",")) {
            LOG_WARN << "JSON array does not contain comma between elements at " << ct->at() << ".";
            return false;
        }
        ++ct;
    }

    // the while loop above only stops when ct points to the end or to a closing bracket. in the
    // first case, we have an error; in the second, we are done with this object and can skip the
    // bracket.
    if (ct == end) {
        LOG_WARN << "JSON array ended unexpectedly.";
        return false;
    }
    ++ct;
    return true;
}
Пример #27
0
void CScriptFile::ParseAndSetItemValueL(const TDesC& aText, const TLex& aInput, TInt aCurrentItemStart, CScriptSectionItem*& arCurrentItem)
	{
	if (arCurrentItem)
		{
		delete arCurrentItem->iValue;
		arCurrentItem->iValue = NULL;
		arCurrentItem->iValue = ParseValue(aText, aInput, aCurrentItemStart).AllocL();
		arCurrentItem->iValue->Des().Trim();
		ReplaceL(KScriptCRLF, KScriptLF, arCurrentItem->iValue);

		if (arCurrentItem->Item().CompareF(KDefaults) == 0)
			{
			CopyInDefaultsL(arCurrentItem->iParent, arCurrentItem->Value());
			}
		}

	arCurrentItem = NULL;
	}
nsresult
nsSVGTransformSMILAttr::ValueFromString(const nsAString& aStr,
                                     const nsISMILAnimationElement* aSrcElement,
                                     nsSMILValue& aValue,
                                     PRBool& aCanCache) const
{
  NS_ENSURE_TRUE(aSrcElement, NS_ERROR_FAILURE);
  NS_ASSERTION(aValue.IsNull(),
    "aValue should have been cleared before calling ValueFromString");

  const nsAttrValue* typeAttr = aSrcElement->GetAnimAttr(nsGkAtoms::type);
  const nsIAtom* transformType = typeAttr
                               ? typeAttr->GetAtomValue()
                               : nsGkAtoms::translate;

  ParseValue(aStr, transformType, aValue);
  aCanCache = PR_TRUE;
  return aValue.IsNull() ? NS_ERROR_FAILURE : NS_OK;
}
Пример #29
0
static bool ParsePair(ParserT *parser, JsonPairT *pair) {
  TokenT *string = ParserMatch(parser, TOK_STRING);

  if (!string) {
    parser->errmsg = "string expected";
    return false;
  }

  if (!ParserMatch(parser, TOK_COLON)) {
    parser->errmsg = "':' expected";
    return false;
  }

  if (!ParseValue(parser, &pair->value))
    return false;

  pair->key = StrNDup(string->value + 1, string->size - 2);
  return true;
}
bool GenericXMLParser::ParseAttribute(String &name, String &value)
{
	StartTrace(GenericXMLParser.ParseAttribute);
	name = ParseName();
	name.ToLower(); // XHTML conformance all attribute names are lower case
	Trace("attribute name:" << name);
	value = "";
	SkipWhitespace();
	int c = Peek();
	if (c != '=') {
		return false;
	}
	c = Get();
	(void)c;
	SkipWhitespace();
	value = ParseValue();
	return true;
	// otherwise it is a syntax error, we just ignore silently for now.
}