Exemple #1
0
static int matchEscape(CSSParser *p)
{
    if (match(p,'\\')) {
        int hexCount = 0;
        for (; hexCount < 6; hexCount++) {
            if ((p->pos < p->length) && isHexChar(p->chars[p->pos])) {
                hexCount++;
                p->pos++;
            }
        }
        if (hexCount > 0) {
            if (matchTwo(p,'\r','\n'))
                return 1;
            else if (match(p,' '))
                return 1;
            else if (match(p,'\t'))
                return 1;
            else if (match(p,'\r'))
                return 1;
            else if (match(p,'\n'))
                return 1;
            else if (match(p,'\f'))
                return 1;
            else
                return 1;
        }
        else {
            p->pos++;
            return 1;
        }
    }
    else {
        return 0;
    }
}
	int str2int(char* str,char* end = TAG_DLT)
	{
		char* t_str = str;
		int ntemp = 0;
		/* 目前只有十六进制,十进制 */
		if (0 == strncmp(t_str, TAG_HEX_1, TAG_HEX_L)
			|| 0 == strncmp(t_str, TAG_HEX_2, TAG_HEX_L))
		{
			/* 0x开头 十六进制 */
			t_str += TAG_HEX_L;
			while (t_str && *t_str && 0 != strncmp(t_str, end, strlen(end)))
			{
				if (isHexChar(*t_str))
				{
					ntemp = ntemp*HEX + char2hex(*t_str);
					t_str++;
				}
				else
				{
					break;
				}
			}
			return ntemp;
		}
		else
		{
			return atoi(t_str);
		}
	}
Exemple #3
0
	static char getDimChar(char dimchar){
		if (isHexChar(dimchar)){
			return dimchar;
		}else if (DIMFLAG == dimchar){
			return '0';
		}else
			return 0;
	}
Exemple #4
0
FlowToken FlowLexer::parseNumber()
{
	stringValue_.clear();
	numberValue_ = 0;

	while (std::isdigit(currentChar())) {
		numberValue_ *= 10;
		numberValue_ += currentChar() - '0';
		stringValue_ += static_cast<char>(currentChar());
		nextChar();
	}

	// ipv6HexDigit4 *(':' ipv6HexDigit4) ['::' [ipv6HexSeq]]
	if (stringValue_.size() <= 4 && currentChar() == ':')
		return continueParseIPv6(true);

	if (stringValue_.size() < 4 && isHexChar())
		return continueParseIPv6(false);

	if (currentChar() != '.')
		return token_ = FlowToken::Number;

	// 2nd IP component
	stringValue_ += '.';
	nextChar();
	while (std::isdigit(currentChar())) {
		stringValue_ += static_cast<char>(currentChar());
		nextChar();
	}

	// 3rd IP component
	if (!consume('.'))
		return token_ = FlowToken::Unknown;

	stringValue_ += '.';
	while (std::isdigit(currentChar())) {
		stringValue_ += static_cast<char>(currentChar());
		nextChar();
	}

	// 4th IP component
	if (!consume('.'))
		return token_ = FlowToken::Unknown;

	stringValue_ += '.';
	while (std::isdigit(currentChar())) {
		stringValue_ += static_cast<char>(currentChar());
		nextChar();
	}

	ipValue_.set(stringValue_.c_str(), IPAddress::V4);

	return token_ = FlowToken::IP;
}
Exemple #5
0
static int srecReadByte(SrecLoader * loader, uint8_t * count){
    char chars[3];
    int i;
    
    for(i = 0 ; i < 2; i++){
        chars[i] = loader->nextChar(loader->userdata);
        if(!isHexChar(chars[i]))
            return 1;
    }
    chars[2] = 0;
    *count = (uint8_t) strtoul(&chars[0],0,16);
    return 0;
}
Exemple #6
0
// 1*4HEXDIGIT
bool FlowLexer::ipv6HexDigit4()
{
	size_t i = ipv6HexDigits_;

	while (isHexChar()) {
		stringValue_ += currentChar();
		nextChar();
		++i;
	}

	ipv6HexDigits_ = 0;

	return i >= 1 && i <= 4;
}
Exemple #7
0
// IPv6_HexPart ::= IPv6_HexSeq                        # (1)
//                | IPv6_HexSeq "::" [IPv6_HexSeq]     # (2)
//                            | "::" [IPv6_HexSeq]     # (3)
//
bool FlowLexer::ipv6HexPart()
{
	bool rv;

	if (currentChar() == ':' && peekChar() == ':') { // (3)
		stringValue_ = "::";
		nextChar(); // skip ':'
		nextChar(); // skip ':'
		rv = isHexChar() ? ipv6HexSeq() : true;
	} else if (!!(rv = ipv6HexSeq())) {
		if (currentChar() == ':' && peekChar() == ':') { // (2)
			stringValue_ += "::";
			nextChar(); // skip ':'
			nextChar(); // skip ':'
			rv = isHexChar() ? ipv6HexSeq() : true;
		}
	}

	if (std::isalnum(currentChar_) || currentChar_ == ':')
		rv = false;

	return rv;
}
Exemple #8
0
static int srecReadAddress(SrecLoader * loader, uint32_t * addr){
    char chars[9];
    int i;
    
    for(i = 0 ; i < 8; i++){
        chars[i] = loader->nextChar(loader->userdata);
        if(!isHexChar(chars[i]))
            return 1;
    }
    chars[8] = 0;
    
    *addr = strtoul(&chars[0],0,16);
    return 0;
}
Exemple #9
0
int SglExprLex::tryScanTagToken()
{
  if (current() == '0')
  {
    ++index;
    if (!atEnd() && isLetter())
    {
      ++index;
      while ( !atEnd() && isLetter() && !isHexChar() )
        ++index;
      end = index;
      ScanResult sr = lookup();
      if (sr.symbol && sr.symbol->type() == tagSym)
        return sr.type;
    }
  }
  return UNKNOWNTOKEN;
}
Exemple #10
0
// ipv6HexDigit4 *(':' ipv6HexDigit4) ['::' [ipv6HexSeq]]
// where the first component, ipv6HexDigit4 is already parsed
FlowToken FlowLexer::continueParseIPv6(bool firstComplete)
{
	bool rv = true;
	if (firstComplete) {
		while (currentChar() == ':' && peekChar() != ':') {
			stringValue_ += ':';
			nextChar();

			if (!ipv6HexDigit4())
				return false;
		}

		if (currentChar() == ':' && peekChar() == ':') {
			stringValue_ += "::";
			nextChar();
			nextChar();
			rv = isHexChar() ? ipv6HexSeq() : true;
		}
	} else {
		ipv6HexDigits_ = stringValue_.size();
		rv = ipv6HexPart();
	}

	// parse embedded IPv4 remainer
	while (currentChar_ == '.' && std::isdigit(peekChar())) {
		stringValue_ += '.';
		nextChar();

		while (std::isdigit(currentChar_)) {
			stringValue_ += static_cast<char>(currentChar_);
			nextChar();
		}
	}

	if (rv && ipValue_.set(stringValue_.c_str(), IPAddress::V6))
		return token_ = FlowToken::IP;
	else
		return token_ = FlowToken::Unknown;
}
Exemple #11
0
FlowToken FlowLexer::parseIdent()
{
	stringValue_.clear();
	stringValue_ += static_cast<char>(currentChar());
	bool isHex = isHexChar();

	nextChar();

	while (std::isalnum(currentChar()) || currentChar() == '_' || currentChar() == '.') {
		stringValue_ += static_cast<char>(currentChar());
		if (!isHexChar())
			isHex = false;

		nextChar();
	}

	// ipv6HexDigit4 *(':' ipv6HexDigit4) ['::' [ipv6HexSeq]]
	if (stringValue_.size() <= 4 && isHex && currentChar() == ':')
		return continueParseIPv6(true);

	if (stringValue_.size() < 4 && isHex && isHexChar())
		return continueParseIPv6(false);

	static struct {
		const char *symbol;
		FlowToken token;
	} keywords[] = {
		{ "in", FlowToken::In },
		{ "var", FlowToken::Var },
		{ "on", FlowToken::On },
		{ "do", FlowToken::Do },
		{ "if", FlowToken::If },
		{ "then", FlowToken::Then },
		{ "else", FlowToken::Else },
		{ "unless", FlowToken::Unless },
		{ "import", FlowToken::Import },
		{ "from", FlowToken::From },
		{ "handler", FlowToken::Handler },
		{ "and", FlowToken::And },
		{ "or", FlowToken::Or },
		{ "xor", FlowToken::Xor },
		{ "not", FlowToken::Not },

		{ "bool", FlowToken::BoolType },
		{ "int", FlowToken::IntType },
		{ "string", FlowToken::StringType },

		{ 0, FlowToken::Unknown }
	};

	for (auto i = keywords; i->symbol; ++i)
		if (strcmp(i->symbol, stringValue_.c_str()) == 0)
			return token_ = i->token;

	if (stringValue_ == "true" || stringValue_ == "yes") {
		numberValue_ = 1;
		return token_ = FlowToken::Boolean;
	}

	if (stringValue_ == "false" || stringValue_ == "no") {
		numberValue_ = 0;
		return token_ = FlowToken::Boolean;
	}

	return token_ = FlowToken::Ident;
}
Exemple #12
0
Fichier : lexer.c Projet : 8l/ark-c
void recognizeNumberToken(Lexer *self) {
	consumeCharacter(self);

	if (self->currentChar == '_') { // ignore digit underscores
		consumeCharacter(self);
	}

	if (self->currentChar == '.') {
		consumeCharacter(self); // consume dot

		while (isDigit(self->currentChar)) {
			consumeCharacter(self);
		}

		if (self->currentChar == 'f' || self->currentChar == 'd') {
			consumeCharacter(self);
		}

		pushToken(self, TOKEN_NUMBER);
	}
	else if (self->currentChar == 'x' || self->currentChar == 'X') {
		consumeCharacter(self);

		while (isHexChar(self->currentChar)) {
			consumeCharacter(self);
		}

		pushToken(self, TOKEN_NUMBER);
	}
	else if (self->currentChar == 'b') {
		consumeCharacter(self);

		while (isBinChar(self->currentChar)) {
			consumeCharacter(self);
		}

		pushToken(self, TOKEN_NUMBER);
	}
	else if (self->currentChar == 'o') {
		consumeCharacter(self);

		while (isOctChar(self->currentChar)) {
			consumeCharacter(self);
		}

		pushToken(self, TOKEN_NUMBER);
	}
	else {
		// it'll do
		while (isDigit(self->currentChar)) {
			if (peekAhead(self, 1) == '.') {
				consumeCharacter(self);
				while (isDigit(self->currentChar)) {
					consumeCharacter(self);
				}

				if (self->currentChar == 'f' || self->currentChar == 'd') {
					consumeCharacter(self);
				}
			}
			else if (peekAhead(self, 1) == '_') { // ignore digit underscores
				consumeCharacter(self);
			}
			consumeCharacter(self);
		}
		pushToken(self, TOKEN_NUMBER);
	}
}
Exemple #13
0
static bool nmea_parse_sentence_character(nmeaPARSER *parser, const char * c) {
  assert(parser);

  /* always reset when we encounter a start-of-sentence character */
  if (*c == '$') {
    reset_sentence_parser(parser, READ_SENTENCE);
    parser->buffer.buffer[parser->buffer.length++] = *c;
    return false;
  }

  /* just return when we haven't encountered a start-of-sentence character yet */
  if (parser->sentence_parser.state == SKIP_UNTIL_START) {
    return false;
  }

  /* this character belongs to the sentence */

  /* check whether the sentence still fits in the buffer */
  if (parser->buffer.length >= SENTENCE_SIZE) {
    reset_sentence_parser(parser, SKIP_UNTIL_START);
    return false;
  }

  parser->buffer.buffer[parser->buffer.length++] = *c;

  switch (parser->sentence_parser.state) {
    case READ_SENTENCE:
      if (*c == '*') {
        parser->sentence_parser.state = READ_CHECKSUM;
        parser->sentence_parser.sentence_checksum_chars_count = 0;
      } else if (*c == first_eol_char) {
        parser->sentence_parser.state = READ_EOL;
        parser->sentence_parser.sentence_eol_chars_count = 1;
      } else if (isInvalidNMEACharacter(c)) {
        reset_sentence_parser(parser, SKIP_UNTIL_START);
      } else {
        parser->sentence_parser.calculated_checksum ^= (int) *c;
      }
      break;

    case READ_CHECKSUM:
      if (!isHexChar(*c)) {
        reset_sentence_parser(parser, SKIP_UNTIL_START);
      } else {
        switch (parser->sentence_parser.sentence_checksum_chars_count) {
          case 0:
            parser->sentence_parser.sentence_checksum_chars[0] = *c;
            parser->sentence_parser.sentence_checksum_chars[1] = 0;
            parser->sentence_parser.sentence_checksum_chars_count = 1;
            break;

          case 1:
            parser->sentence_parser.sentence_checksum_chars[1] = *c;
            parser->sentence_parser.sentence_checksum_chars_count = 2;
            parser->sentence_parser.sentence_checksum = nmea_atoi(parser->sentence_parser.sentence_checksum_chars, 2, 16);
            parser->sentence_parser.has_checksum = true;
            parser->sentence_parser.state = READ_EOL;
            break;

          default:
            reset_sentence_parser(parser, SKIP_UNTIL_START);
            break;
          }
      }
      break;


    case READ_EOL:
      switch (parser->sentence_parser.sentence_eol_chars_count) {
        case 0:
          if (*c != first_eol_char) {
            reset_sentence_parser(parser, SKIP_UNTIL_START);
          } else {
            parser->sentence_parser.sentence_eol_chars_count = 1;
          }
          break;

        case 1:
          if (*c != second_eol_char) {
            reset_sentence_parser(parser, SKIP_UNTIL_START);
          } else {
            parser->sentence_parser.state = SKIP_UNTIL_START;
            return (!parser->sentence_parser.sentence_checksum_chars_count
                || (parser->sentence_parser.sentence_checksum_chars_count
                    && (parser->sentence_parser.sentence_checksum == parser->sentence_parser.calculated_checksum)));
          }
          break;

        default:
          reset_sentence_parser(parser, SKIP_UNTIL_START);
          break;
      }
      break;

      /* can't occur, but keep compiler happy */
      case SKIP_UNTIL_START:
      default:
        break;

  }

  return false;
}