예제 #1
0
파일: sig.c 프로젝트: aosm/boot
void
parseFile(FILE *file)
{
    char *line, c;
    int len, lineNumber;
    
    line = malloc(MAXLINE+1);
    lineNumber = 1;
    
    skipWhitespace(file);
    
    while (!feof(file)) {
	c = peekf(file);
	if (c == '#' || c == '/') {
	    len = getLineThru(file, line, '\n', MAXLINE);
	    if (c == '#')
		fprintf(ofile, line);
	} else {
	    len = getLineThru(file, line, ';', MAXLINE);
	    parseLine(line);
	}
	skipWhitespace(file);
    }
    free(line);
}
예제 #2
0
/**
 * Throws: std::invalid_argument upon invalid argument
 * and other std::exceptions's from string methods. 
 */
Http::Cookie::Cookie(const char *cookieStr) 
    : name(), value()
{
    const char *ptr;
    bool parsed = false;

    ptr = cookieStr;
    while (isToken(*ptr)) {
	ptr += 1;
    }

    if (ptr > cookieStr) {
	name.append(cookieStr, ptr - cookieStr);
	ptr = skipWhitespace(ptr);
	if ('=' == *ptr) {
	    const char *startPtr;

	    ptr = skipWhitespace(ptr + 1);
	    startPtr = ptr;
	    while (*ptr && ';' != *ptr) { 
		ptr += 1;
	    }
	    if (ptr > startPtr) {
		value.append(startPtr, ptr - startPtr);
		parsed = true;
	    }
	}
    }

    if (! parsed) {
	throw std::invalid_argument(cookieStr);
    }
}
예제 #3
0
bool CssParser::parseBlock (TokenList* tokens) {
  if (tokenizer->getTokenType() != Token::BRACKET_OPEN)
    return false;

  tokens->push(tokenizer->getToken()->clone());
  tokenizer->readNextToken();
  skipWhitespace();
  
  while (true) {
    if (!(parseAny(tokens) || parseBlock(tokens))) {
      if (tokenizer->getTokenType() == Token::ATKEYWORD) {
        tokens->push(tokenizer->getToken()->clone());
        tokenizer->readNextToken();
        parseWhitespace(tokens);
      } else if (tokenizer->getTokenType() == Token::DELIMITER) {
        tokens->push(tokenizer->getToken()->clone());
        tokenizer->readNextToken();
        skipWhitespace();
      } else
        break;
    }
  }

  if (tokenizer->getTokenType() != Token::BRACKET_CLOSED) {
    throw new ParseException(tokenizer->getToken()->str,
                             "end of block ('}')");
  }
  tokens->push(tokenizer->getToken()->clone());
  tokenizer->readNextToken();
  skipWhitespace();
  return true;
}
예제 #4
0
	ObjectPtr Object::fromJson(std::istream& is) {
		int next_ch = skipWhitespace(is);
		if (next_ch == -1)
			throw runtime_error(
			"JsonXObject::read(): Premature end of file");
		if (next_ch != '{')
			throw runtime_error(
			"Character '{' expected. Got: '" +
			to_string(static_cast<char>(next_ch)) + "'");
		unique_ptr<ObjectValue> pv{ new ObjectValue() };
		readChar(is);;
		next_ch = skipWhitespace(is);
		if (next_ch != '}') {
			while (true) {
				string key{ String::fromJsonRaw(is) };
				next_ch = skipWhitespace(is);
				if (next_ch != ':')
					throw runtime_error(
					"Expected ':'. Got: '" +
					to_string(static_cast<char>(next_ch)) + "'");
				readChar(is);
				pv.get()->push_back(ObjectEntry{ key, Value::fromJson(is) });
				next_ch = skipWhitespace(is);
				if (next_ch == '}')
					break;
				if (next_ch != ',')
					throw runtime_error(
					"Expected ',' or '}'. Got: '" +
					to_string(static_cast<char>(next_ch)) + "'");
				readChar(is);
			} // end while //
		}
		readChar(is);
		return Object::make(pv);
	}
예제 #5
0
Declaration* CssParser::parseDeclaration () {
  Declaration* declaration = NULL;
  TokenList property;

  if (!parseProperty(&property))
    return NULL;
  
  skipWhitespace();

  declaration = new Declaration(property.toString());
  
  if (tokenizer->getTokenType() != Token::COLON) {
    throw new ParseException(tokenizer->getToken()->str,
                             "colon following property(':')");
  }
  tokenizer->readNextToken();
  skipWhitespace();

  TokenList* value = parseValue();
  if (value == NULL) {
    throw new ParseException(tokenizer->getToken()->str,
                             "value for property");
  }
  declaration->setValue(value);
  return declaration;
}
예제 #6
0
	ListPtr List::fromJson(std::istream& is) {
		int next_ch = skipWhitespace(is);
		if (next_ch == -1)
			throw runtime_error(
			"JsonXArray.ReadArray(): Premature end of file");
		if (next_ch != '[')
			throw runtime_error(
			"Character '[' expected. Got: '" +
			to_string(static_cast<char>(next_ch)) + "'");
		unique_ptr<ListValue> pv{ new ListValue() };
		readChar(is);
		next_ch = skipWhitespace(is);
		if (next_ch != ']') {
			while (true) {
				pv.get()->push_back(Value::fromJson(is));
				next_ch = skipWhitespace(is);
				if (next_ch == ']')
					break;
				if (next_ch != ',')
					throw runtime_error(
					"Expected ',' or ']'. Got: '" +
					to_string(static_cast<char>(next_ch)) + "'");
				readChar(is);
			} // end while //
		}
		readChar(is);
		return List::make(pv);
	}
예제 #7
0
bool LessParser::parseVariable (TokenList &value) {
  if (tokenizer->getTokenType() != Token::COLON)
    return false;
  
  tokenizer->readNextToken();
  skipWhitespace();
    
  if (parseValue(value) == false || value.size() == 0) {
    throw new ParseException(tokenizer->getToken(),
                             "value for variable",
                             tokenizer->getLineNumber(),
                             tokenizer->getColumn(),
                             tokenizer->getSource());
  }
  if (tokenizer->getTokenType() != Token::DELIMITER) {
    throw new ParseException(tokenizer->getToken(),
                             "delimiter (';') at end of @-rule",
                             tokenizer->getLineNumber(),
                             tokenizer->getColumn(),
                             tokenizer->getSource());
  }
  tokenizer->readNextToken();
  skipWhitespace();

  return true;
}
예제 #8
0
파일: Macro.cpp 프로젝트: LinHu2016/omr
/**
 * Checks if the cursor is at a valid type cast expression, after encountering
 * a left parenthesis. If it is, determine the signedness and bit width of the
 * type cast. If not, move the cursor back to the left parenthesis.
 *
 * @param[out] isSigned: the signedness of the resulting typecast
 * @param[out] bitWidth: the bit width of the resulting typecast
 *
 * @return: if the typecast expression is valid
 */
bool
MacroScanner::validTypeCast(bool *isSigned, size_t *bitWidth)
{
	char const *const savedCursor = _cursor;

	if (!atSymbol(LPAREN)) {
		return false;
	}

	skipWhitespace();

	const char *start = _cursor;
	const char *end = start;

	while (isalpha(*_cursor)) {
		do {
			_cursor += 1;
		} while (('_' == *_cursor) || isalnum(*_cursor));

		end = _cursor;

		skipWhitespace();
	}

	if (!atSymbol(RPAREN)) {
		_cursor = savedCursor;
		return false;
	}

	return Type::isStandardType(start, (size_t)(end - start), isSigned, bitWidth);
}
예제 #9
0
파일: parser.cpp 프로젝트: dunk8888/Cube4
byte parser(
  char       *message,
  byte        length,
  bytecode_t *bytecode) {

  byte errorCode = 0;
  byte position = 0;

  skipWhitespace(message, length, & position);

  command_t *command;

  errorCode = parseCommand(message, length, & position, & command);

  if (errorCode == 0) {
    skipWhitespace(message, length, & position);

    errorCode =
      (command->parser)(message, length, & position, command, bytecode);

    if (errorCode == 0) {
      skipWhitespace(message, length, & position);
    }
  }

  return(errorCode);
}
예제 #10
0
파일: parser.cpp 프로젝트: dunk8888/Cube4
byte parseCommandSphere(
  char       *message,
  byte        length,
  byte       *position,
  command_t  *command,
  bytecode_t *bytecode) {

  byte positionX1;
  byte positionY1;
  byte positionZ1;
  byte size;
  byte errorCode = 0;
  bytecode->executer = command->executer;

  skipWhitespace(message, length, position);
  errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1);
  skipWhitespace(message, length, position);
  errorCode = parseOffset(message, length, position, & size);
  skipWhitespace(message, length, position);
  errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom);
  skipWhitespace(message, length, position);
  errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorTo);
  if (errorCode) {
    errorCode = 0;
    bytecode->u.lit.colorTo = BLACK;
  }

  if (errorCode == 0) cubeSphere( positionX1, positionY1, positionZ1, size, bytecode->u.lit.colorFrom, bytecode->u.lit.colorTo);

  return(errorCode);
};
예제 #11
0
파일: parser.cpp 프로젝트: dunk8888/Cube4
byte parseCommandMoveplane(
  char       *message,
  byte        length,
  byte       *position,
  command_t  *command,
  bytecode_t *bytecode) {

  byte axis;
  byte offset;
  byte destination;
  rgb_t rgb;
  byte errorCode = 0;
  bytecode->executer = command->executer;

  skipWhitespace(message, length, position);
  errorCode = parseAxis(message, length, position, & axis);
  skipWhitespace(message, length, position);
  errorCode = parseOffset(message, length, position, & offset);
  skipWhitespace(message, length, position);
  errorCode = parseOffset(message, length, position, & destination);
  skipWhitespace(message, length, position);
  errorCode = parseRGB(message, length, position, & rgb);

  if (errorCode == 0) cubeMoveplane(axis, offset, destination, rgb);

  return(errorCode);
};
예제 #12
0
bool LessParser::parseRuleset (LessStylesheet &stylesheet,
                               Selector &selector,
                               LessRuleset* parent) {
  LessRuleset* ruleset;
  
  if (tokenizer->getTokenType() != Token::BRACKET_OPEN)
    return false;

  tokenizer->readNextToken();
  skipWhitespace();

#ifdef WITH_LIBGLOG
  VLOG(2) << "Parse: Ruleset";
#endif

  // Create the ruleset and parse ruleset statements.
  if (parent == NULL) 
    ruleset = stylesheet.createLessRuleset();
  else
    ruleset = parent->createNestedRule();
  ruleset->setReference(reference);
  ruleset->setSelector(selector);
  
  parseRulesetStatements(stylesheet, *ruleset);
  
  if (tokenizer->getTokenType() != Token::BRACKET_CLOSED) {
    throw new ParseException(tokenizer->getToken(),
                             "end of declaration block ('}')");
  } 
  tokenizer->readNextToken();
  skipWhitespace();
  
  return true;
}
예제 #13
0
파일: parser.cpp 프로젝트: dunk8888/Cube4
byte parseCommandLine(
  char       *message,
  byte        length,
  byte       *position,
  command_t  *command,
  bytecode_t *bytecode) {

  byte positionX1;
  byte positionY1;
  byte positionZ1;
  byte positionX2;
  byte positionY2;
  byte positionZ2;
  byte errorCode = 0;
  bytecode->executer = command->executer;

  skipWhitespace(message, length, position);
  errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1);
  skipWhitespace(message, length, position);
  errorCode = parsePosition(message, length, position, & positionX2, & positionY2, & positionZ2);
  skipWhitespace(message, length, position);
  errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom);

  if (errorCode == 0) cubeLine( positionX1, positionY1, positionZ1, positionX2, positionY2, positionZ2, bytecode->u.lit.colorFrom);

  return(errorCode);
};
예제 #14
0
int Parser::getNextToken()
{
    int saveIndex = m_index;

    skipWhitespace();
    if (isdigit(nextChar())) {
        // At this point we know that there is a valid number in the
        // string.  The only question now, is whether it is an int or a
        // float.

        parseInt(&m_intVal);

        skipWhitespace();
        if (nextChar() == '.') {
            m_index = saveIndex;

            // No need to check since we already know it is correct.
            (void) parseSimpleFloat(&m_floatVal);
            m_nextToken = FLOAT_TOKEN;
        } else {
            m_nextToken = INT_TOKEN;
        }
    } else if (nextChar() != -1) {
        // Any character.
        m_nextToken = nextChar();
        getNextChar();
    } else {
        // End of string.
        m_nextToken = -1;
    }

    return m_nextToken;
}
예제 #15
0
void InText::readString(std::string& value, PhysicalInStream& stream)
{
  value = "";
  skipWhitespace(stream);
  bool containsSpaces = theChar == '"';
  if(containsSpaces && !isEof(stream))
    nextChar(stream);
  while(!isEof(stream) && (containsSpaces || !isWhitespace()) && (!containsSpaces || theChar != '"'))
  {
    if(theChar == '\\')
    {
      nextChar(stream);
      if(theChar == 'n')
        theChar = '\n';
      else if(theChar == 'r')
        theChar = '\r';
      else if(theChar == 't')
        theChar = '\t';
    }
    value += theChar;
    if(!isEof(stream))
      nextChar(stream);
  }
  if(containsSpaces && !isEof(stream))
    nextChar(stream);
  skipWhitespace(stream);
}
예제 #16
0
파일: parser.c 프로젝트: WCP52/gpha
/**
 * Interface to the application. Adds data to system buffer and try to search
 * command line termination. If the termination is found or if len=0, command
 * parser is called.
 * 
 * @param context
 * @param data - data to process
 * @param len - length of data
 * @return 
 */
int SCPI_Input(scpi_t * context, const char * data, size_t len) {
    int result = 0;
    const char * cmd_term;
    if (len == 0) {
        context->buffer.data[context->buffer.position] = 0;
        result = SCPI_Parse(context, context->buffer.data, context->buffer.position);
        context->buffer.position = 0;
    } else {
        size_t buffer_free;
        int ws;
        buffer_free = context->buffer.length - context->buffer.position;
        if (len > (buffer_free - 1)) {
            return -1;
        }
        memcpy(&context->buffer.data[context->buffer.position], data, len);
        context->buffer.position += len;
        context->buffer.data[context->buffer.position] = 0;

        ws = skipWhitespace(context->buffer.data, context->buffer.position);
        cmd_term = cmdlineTerminator(context->buffer.data + ws, context->buffer.position - ws);
        while (cmd_term != NULL) {
            int curr_len = cmd_term - context->buffer.data;
            result = SCPI_Parse(context, context->buffer.data + ws, curr_len - ws);
            memmove(context->buffer.data, cmd_term, context->buffer.position - curr_len);
            context->buffer.position -= curr_len;
    
            ws = skipWhitespace(context->buffer.data, context->buffer.position);
            cmd_term = cmdlineTerminator(context->buffer.data + ws, context->buffer.position - ws);
        }
    }

    return result;
}
예제 #17
0
AtomListPtr
findProxyClient(char *line)
{
    AtomListPtr alv;
    AtomPtr name, value;
    int i=0;
    alv = makeAtomList(NULL, 0);
    if(alv == NULL) {
        do_log(L_ERROR, "couldn't allocate atom list.\n");
        return NULL;
    }
    while(1) {
        i = parseAtom1(line, i, &value,1);
        //if(i < 0) goto syntax;
        if(!value) {
            do_log(L_ERROR, "couldn't allocate atom.\n");
            return NULL;
        }
        //printf("%s\n",value->string);
        atomListCons(value, alv);
        i = skipWhitespace(line, i);
        if(line[i] == '\n' || line[i] == '\0' || line[i] == '#')
            break;
        if(line[i] != ',') {
            destroyAtomList(alv);
            //goto syntax;
        }
        i = skipWhitespace(line, i + 1);
    }
    return alv;
}
예제 #18
0
bool ValueProcessor::validateCondition(const TokenList &value,
                                       const ValueScope &scope,
                                       bool defaultVal) const {
  TokenList::const_iterator i = value.begin();
  TokenList::const_iterator end = value.end();
  bool negate = false;
  bool ret;

  skipWhitespace(i, end);

  if (*i == "not") {
    negate = true;
    i++;
  }
    
  ret = validateValue(i, end, scope, defaultVal);

  skipWhitespace(i, end);

  while (ret == true && i != value.end() && *i == "and") {
    i++;

    skipWhitespace(i, end);

    ret = validateValue(i, end, scope, defaultVal);

    skipWhitespace(i, end);
  }

  return negate ? !ret : ret;
}
예제 #19
0
 Dictionary<Base, Base> *Reader::parseObject()
 {
     next(); // {
     
     auto object = make<Dictionary<Base, Base>>();
     
     while (this->more() && current() != kObjectEnd) {
         skipWhitespace();
         
         auto key = parseExpression();
         skipWhitespace();
         if(current() == kObjectKeyValueSeparator) {
             next();
             skipWhitespace();
         } else {
             fail(String::Builder() << "expected ':', got '" << current()  << "'.");
         }
         
         auto value = parseExpression();
         
         object->set(key, value);
         
         skipWhitespace();
         if(current() == kStatementSeparator)
             next();
         skipWhitespace();
     }
     
     requireCondition(more(), str("expected '}', got end of file."));
     requireCondition(current() == kObjectEnd, (String::Builder() << "expected '}', got '" << current() << "'."));
     
     next(); // }
     
     return object;
 }
예제 #20
0
std::string Context::getCommand(bool skipNewlines) {
	
	const char * esdat = script->data;
	
	skipWhitespace(skipNewlines);
	
	std::string word;
	
	// now take chars until it finds a space or unused char
	for(; pos != script->size && !isWhitespace(esdat[pos]); pos++) {
		
		char c = esdat[pos];
		if(c == '"') {
			ScriptParserWarning << "unexpected '\"' in command name";
		} else if(c == '~') {
			ScriptParserWarning << "unexpected '~' in command name";
		} else if(c == '\n') {
			break;
		} else if(c == '/' && pos + 1 != script->size && esdat[pos + 1] == '/') {
			pos = std::find(esdat + pos + 2, esdat + script->size, '\n') - esdat;
			if(!word.empty()) {
				break;
			}
			skipWhitespace(skipNewlines), pos--;
		} else {
			word.push_back(c);
		}
	}
	
	return word;
}
예제 #21
0
/** Reads XML tags from an input file. */
void Parser::parse() {
	
	Tag tag;
	
	// Read and process tags
	tags.clear();
	skipWhitespace();
	try {
		while (file) {
			if (character != '<') {
				throw BasicException("[Parser] Tags must start with '<'.");
			} else if (match("<!--")) {
				skip("-->");
			} else {
				tag = create(findTag());
				tag.setFilename(filename);
				tag.setLine(lineNumber);
				tags.push_back(tag);
			}
			skipWhitespace();
		}
		file.close();
	} catch (BasicException e) {
		file.close();
		BasicException ex;
		ex << Tag::toLocation(filename, lineNumber) << e.what();
		throw ex;
	}
}
예제 #22
0
파일: settings.c 프로젝트: An00bIS47/gbMon2
// ---------------------------------------------------------------------------
int Settings_Load(char* file) {
	if(settings != NULL) Settings_Unload();
	settings = (SettingsFile*)malloc(sizeof(SettingsFile));
	settings->category = NULL;
	settings->cats = 0;
	FILE* f = fopen(file, "r");
	if(f == NULL) return 0;
	char buffer[256];
	char* line;
	int current_cat = -1;
	while(fgets(buffer, 256, f) != NULL) {
		line = trim(&buffer[0]);
		if(strlen(line) == 0) continue; // blank line
		if(line[0] == '#') continue; // just a comment
		// new category
		if(line[0] == '[') {
			line++;
			line[strlen(line) - 1] = 0;
			char* cat_name = (char*)malloc(sizeof(char) * (1 + strlen(line)));
            strcpy(cat_name, line);
			addCategory(cat_name);
            current_cat = settings->cats - 1;
            //printf("Cat: %s\r\n", line);
		}
		// new value
		else {
			// value without category -> error
			if(current_cat == -1) {
				fclose(f);
				return 0;
			}
			// get key and value
			char* ptr = strtok(line, "=");
			if(ptr == NULL) {
				fclose(f);
				return 0;
			}
			ptr = skipWhitespace(ptr);
			char* key = (char*)malloc(sizeof(char) * (1 + strlen(ptr)));
			strcpy(key, ptr);
			key = trim(key);
			ptr = strtok(NULL, "\1");
			//ptr += strlen(ptr) + 1;
			if(ptr == NULL) {
				fclose(f);
				return 0;
			}
			ptr = skipWhitespace(ptr);
			char* value = (char*)malloc(sizeof(char) * (1 + strlen(ptr)));
			strcpy(value, ptr);
			value = trim(value);
            addValue(current_cat, key, value);
            printf(" -> %s: %s\r\n", key, value);
		}
	}
	fclose(f);
	return 1;
}
예제 #23
0
bool CssParser::parseAny (TokenList* tokens) {
  
  switch(tokenizer->getTokenType()) {
  case Token::NUMBER:
  case Token::PERCENTAGE:
  case Token::DIMENSION:
  case Token::STRING:
  case Token::URL:
  case Token::HASH:
  case Token::UNICODE_RANGE:
  case Token::INCLUDES:
  case Token::DASHMATCH:
  case Token::COLON:
  case Token::OTHER:
    tokens->push(tokenizer->getToken()->clone());
    tokenizer->readNextToken();
    break;

  case Token::PAREN_OPEN:
    tokens->push(tokenizer->getToken()->clone());
    tokenizer->readNextToken();
    skipWhitespace();

    while (parseAny(tokens) || parseUnused(tokens)) {}
    if (tokenizer->getTokenType() != Token::PAREN_CLOSED) {
      throw new ParseException(tokenizer->getToken()->str,
                               "closing parenthesis (')')");
    }
    tokens->push(tokenizer->getToken()->clone());
    tokenizer->readNextToken();
    break;
      
  case Token::IDENTIFIER:
    tokens->push(tokenizer->getToken()->clone());
    tokenizer->readNextToken();
    break;
    
  case Token::BRACE_OPEN:
    tokens->push(tokenizer->getToken()->clone());
    tokenizer->readNextToken();
    skipWhitespace();
    while (parseAny(tokens) || parseUnused(tokens)) {}
    if (tokenizer->getTokenType() != Token::BRACE_CLOSED) {
      throw new ParseException(tokenizer->getToken()->str,
                               "closing brace (']')");
    }
    tokens->push(tokenizer->getToken()->clone());
    tokenizer->readNextToken();
    break;

  default:
    return false;
  }
  parseWhitespace(tokens);
  return true;
}
예제 #24
0
QVariant QJson::parseArray(const QString &json, int &index, DecodeOptions options, bool &success, QString *errorMessage)
{
	Q_ASSERT(json[index] == '[');
	index++;
	skipWhitespace(json, index);

	QVariantList array;

	while (checkAvailable(json, index, success, errorMessage))
	{
		if (json[index] == QChar::fromLatin1(']'))
		{
			index++;
			return array;
		}
		else
		{
			QVariant value = QJson::parseValue(json, index, options, success, errorMessage);
			if (!success)
				return QVariant();

			// Add the value pair to the array
			array.append(value);

			int skippedWhitespaces = skipWhitespace(json, index);
			checkAvailable(json, index, success, errorMessage);

			switch (json[index].toLatin1())
			{
			case ',':
				index++;
				skipWhitespace(json, index);
				break;

			case ']':
				//']' will be processed in the next iteration
				break;

			default:
				// Only allow missing comma if there is at least one whitespace instead of the comma!
				if ((options & AllowMissingComma) && skippedWhitespaces > 0)
					break;
				else
				{
					success = false;
					if (errorMessage)
						*errorMessage = QString("Unexpected character at index %1").arg(index);
					return QVariant();
				}
			}
		}
	}

	return QVariant();
}
예제 #25
0
void InText::readUInt(unsigned int& d, PhysicalInStream& stream)
{
  buf = "";
  skipWhitespace(stream);
  while(!isEof(stream) && isdigit(theChar))
  {
    buf += theChar;
    nextChar(stream);
  }
  d = static_cast<unsigned>(strtoul(buf.c_str(), nullptr, 0));
  skipWhitespace(stream);
}
예제 #26
0
void CssParser::parseStylesheet(Stylesheet* stylesheet){
  tokenizer->readNextToken();
  
  skipWhitespace();
  while (parseStatement(stylesheet)) {
    skipWhitespace();
  }
  
  // stream should end here
  if (tokenizer->getTokenType() != Token::EOS) {
    throw new ParseException(tokenizer->getToken()->str,
                             "end of input");
  }
}
예제 #27
0
StringLocalizationInfo*
LocDataParser::doParse(void) {
    skipWhitespace();
    if (!checkInc(OPEN_ANGLE)) {
        ERROR("Missing open angle");
    } else {
        VArray array(DeleteFn);
        UBool mightHaveNext = TRUE;
        int32_t requiredLength = -1;
        while (mightHaveNext) {
            mightHaveNext = FALSE;
            UChar** elem = nextArray(requiredLength);
            skipWhitespace();
            UBool haveComma = check(COMMA);
            if (elem) {
                array.add(elem, ec);
                if (haveComma) {
                    inc();
                    mightHaveNext = TRUE;
                }
            } else if (haveComma) {
                ERROR("Unexpected character");
            }
        }

        skipWhitespace();
        if (!checkInc(CLOSE_ANGLE)) {
            if (check(OPEN_ANGLE)) {
                ERROR("Missing comma in outer array");
            } else {
                ERROR("Missing close angle bracket in outer array");
            }
        }

        skipWhitespace();
        if (p != e) {
            ERROR("Extra text after close of localization data");
        }

        array.add(NULL, ec);
        if (U_SUCCESS(ec)) {
            int32_t numLocs = array.length() - 2; // subtract first, NULL
            UChar*** result = (UChar***)array.release();

            return new StringLocalizationInfo(data, result, requiredLength-2, numLocs); // subtract first, NULL
        }
    }

    ERROR("Unknown error");
}
예제 #28
0
am_status_t Properties::parseBuffer(char *buffer)
{
    am_status_t status = AM_SUCCESS;
    char *nextLine;
#if defined(_AMD64_)
    size_t len;
#else
    int len;
#endif

    try {
	for (buffer = skipWhitespaceAndComments(buffer);
	     *buffer;
	     buffer = skipWhitespaceAndComments(nextLine)) {

	    char *start = buffer;
	    nextLine = terminateLine(buffer);

	    // XXX - Should handle backslash escapes in the key
	    buffer = findSeparator(start);
	    if (start == buffer) {
		break;
	    }

	    std::string key(start, buffer - start);

	    buffer = skipWhitespace(buffer);
	    if (*buffer && isSeparator(*buffer)) {
		buffer += 1;
		buffer = skipWhitespace(buffer);
	    }

	    len = strlen(buffer) -1;
	    while ((len > 0) && (buffer[len] == ' ')) {
		buffer[len--] = '\0';
	    }
            
            // XXX - Should handle backslash escapes in the value
            set(key, buffer);
	}
	if (*buffer) {
	    status = AM_FAILURE;
	}
    } catch (const std::bad_alloc&) {
	status = AM_NO_MEMORY;
    }

    return status;
}
예제 #29
0
UnprocessedStatement* LessParser::parseRulesetStatement (LessRuleset &ruleset) {
  UnprocessedStatement* statement;
  Selector tokens;
  size_t property_i;
  
  while (parseProperty(tokens) || parsePropertyVariable(tokens)) {}
  
  property_i = tokens.size();

  parseWhitespace(tokens);
  parseSelector(tokens);
  tokens.trim();

  if (tokens.empty())
    return NULL;

  statement = ruleset.createUnprocessedStatement();
  
  statement->getTokens()->swap(tokens);
  statement->property_i = property_i;
    
  if (tokenizer->getTokenType() == Token::BRACKET_OPEN) 
    return statement;
  
  parseValue(*statement->getTokens());
  
  if (tokenizer->getTokenType() == Token::DELIMITER) {
    tokenizer->readNextToken();
    skipWhitespace();
  } 
  return statement;
}
예제 #30
0
Value *ValueProcessor::processNegative(TokenList::const_iterator &i,
                                       TokenList::const_iterator &end,
                                       const ValueScope &scope) const {
  Token minus;
  Value *constant;
  Value *zero, *ret;
  Token t_zero("0", Token::NUMBER, 0, 0, "generated");

  if (i == end || (*i) != "-")
    return NULL;

  minus = *i;
  i++;

  skipWhitespace(i, end);

  constant = processConstant(i, end, scope);
  if (constant == NULL) {
    i--;
    return NULL;
  }

  zero = new NumberValue(t_zero);
  ret = *zero - *constant;

  ret->setLocation(minus);

  delete constant;
  delete zero;

  return ret;
}