示例#1
0
/*
 * skip to the end of the current string and the beginning of the next one
 */
int
xpmNextString(xpmData *data)
{
    if (!data->type)
	data->cptr = (data->stream.data)[++data->line];
    else if (data->type == XPMBUFFER) {
	register char c;

	/* get to the end of the current string */
	if (data->Eos)
	    while ((c = *data->cptr++) && c != data->Eos);

	/*
	 * then get to the beginning of the next string looking for possible
	 * comment
	 */
	if (data->Bos) {
	    while ((c = *data->cptr++) && c != data->Bos)
		if (data->Bcmt && c == data->Bcmt[0])
		    ParseComment(data);
	} else if (data->Bcmt) {	/* XPM2 natural */
	    while ((c = *data->cptr++) == data->Bcmt[0])
		ParseComment(data);
	    data->cptr--;
	}
    } else {
	register int c;
	FILE *file = data->stream.file;

	/* get to the end of the current string */
	if (data->Eos)
	    while ((c = Getc(data, file)) != data->Eos && c != EOF);

	/*
	 * then get to the beginning of the next string looking for possible
	 * comment
	 */
	if (data->Bos) {
	    while ((c = Getc(data, file)) != data->Bos && c != EOF)
		if (data->Bcmt && c == data->Bcmt[0])
		    ParseComment(data);

	} else if (data->Bcmt) {	/* XPM2 natural */
	    while ((c = Getc(data, file)) == data->Bcmt[0])
		ParseComment(data);
	    Ungetc(data, c, file);
	}
    }
    return 0;
}
示例#2
0
文件: read.c 项目: CarbonOS/libsystem
/* IScanner */
static inline int ParseValue(struct IParse *parse, struct ISection *section)
{
	ParseComment(parse);
	ParseSkip(parse);

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

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

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

	/* Value Data */
	char data[MAX_VALUE];
	if (!ParseData(parse, data, MAX_VALUE)) {
		return 0;	
	}

	AddSectionString(section, name, data);
	return 1;
}
示例#3
0
文件: read.c 项目: CarbonOS/libsystem
/* 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;
}
示例#4
0
// Get a single char token
bool SqlParser::GetSingleCharToken(Token *token)
{
	if(token == NULL)
		return false;

	bool exists = false;

	while(_remain_size > 0)
	{
		const char *cur = _next_start;

		// Check for a comment, but do not return it as a token
		if(ParseComment() == true)
			continue;

		// Check for quoted identifier
		exists = GetQuotedIdentifier(token);

		if(exists == true)
			break;

		// Check for string literal
		exists = GetStringLiteral(token);

		if(exists == true)
			break;

		// Return if not a single char
		if(strchr(g_symbols, *cur) == NULL)
			break;

		_next_start++;
		_remain_size--;
	
		token->type = TOKEN_SYMBOL;
		token->chr = *cur;
		token->wchr = 0;
		token->str = NULL;
		token->wstr = NULL;
		token->len = 0;
		token->remain_size = _remain_size;
		token->next_start = _next_start;

		_tokens.Add(token);

		cur++;
		exists = true;

		break;
	}

	return exists;
}
示例#5
0
void DwRfc1521Tokenizer::ParseToken()
{
    // Assume the field body has already been extracted.  That is, we don't
    // have to watch for the end of the field body or folding.  We just
    // treat any CRs or LFs as white space.
    mTokenStart = mNextStart;
    mTokenLength = 0;
    mTkType = eTkNull;
    if (mTokenStart >= mString.length()) {
        return;
    }
    // Skip leading space.  Also, since control chars are not permitted
    // in atoms, skip these, too.
    while (1) {
        if (mTokenStart >= mString.length()) {
            return;
        }
        if (!isspace(mString[mTokenStart]) && !iscntrl(mString[mTokenStart]))
            break;
        ++mTokenStart;
    }
    char ch = mString[mTokenStart];
    // Quoted string
    if (ch == '"') {
        mTkType = eTkQuotedString;
        ParseQuotedString();
    }
    // Comment
    else if (ch == '(') {
        mTkType = eTkComment;
        ParseComment();
    }
    // Domain literal
    else if (ch == '[') {
        mTkType = eTkDomainLiteral;
        ParseDomainLiteral();
    }
    // Special
    else if (istspecial(ch)) {
        mTkType = eTkTspecial;
        mTokenLength = 1;
        mToken = mString.substr(mTokenStart, 1);
        mNextStart = mTokenStart + 1;
    }
    // Atom
    else {
        mTkType = eTkToken;
        ParseAtom();
    }
    if (mDebugOut) PrintToken(mDebugOut);
}
示例#6
0
void MIME::Headers::SetType (std::string const & type, std::string const & comment)
{
	unsigned curPos = 0;
	// type/subtype delimited by semicolon
	unsigned slashPos = type.find ('/', curPos);
	if (slashPos != std::string::npos)
	{
		_type = type.substr (curPos, slashPos - curPos);
		curPos = slashPos + 1;
		_subtype = type.substr (curPos);
	}
	else
	{
		_type = type.substr (curPos);
	}
	ParseComment (comment, _typeAttrib);
}
示例#7
0
void
XMLParser::ParseLevel()
{
  // MAIN PARSING LOOP
  while(*m_pointer)
  {
    // STEP 1: Skip whitespace
    SkipOuterWhiteSpace();

    // STEP 2: Check for end
    if(!*m_pointer)
    {
      return;
    }
    // STEP 3: Check for a node
    if(*m_pointer != '<')
    {
      SetError(XmlError::XE_NotAnXMLMessage,m_pointer);
      return;
    }
    // STEP 4: One of five node types
    if(strncmp((const char*)m_pointer,"<?xml",5) == 0)
    {
      ParseDeclaration();
    }
    else if(strncmp((const char*)m_pointer,"<!--",4) == 0)
    {
      ParseComment();
    }
    else if(strncmp((const char*)m_pointer,"<![CDATA[",9) == 0)
    {
      ParseCDATA();
      return;
    }
    else if(strncmp((const char*)m_pointer,"<!",2) == 0)
    {
      ParseDTD();
    }
    else if(ParseElement())
    {
      ParseAfterElement();
      return;
    }
  }
}
/**
   \fn int ParseFile (FILE* file, Comment* result)
   \brief parse a file and put the documentation comments to result
   \param file    the file for the parsing
   \param result    the table which contains the documentation comments
   \return the number of documentation comments find during the parsing
*/
int ParseFile (FILE* file, Comment** result){
         int count=0,test=0,bloc=0;
         char c,tmp;
         detail=0;
         while(!feof()){
                        c=fgetc(file);
                        if(test==0 && c=='/')
                                   test++;
                        else 
                             if(bloc==1){
                                         bloc==0;
                                         count++;
                                         }
                        
                        if(test==1 && (c=='/' || c=='*')){
                                   tmp=c;
                                   test++;
                                   }
                        else {
                             test=0;
                             if(bloc==1){
                                         bloc==0;
                                         count++;
                                         }
                             }
                        
                        if(test==2 && (c=='/' || c=='*') && c=tmp){
                                   ParseComment(file,tmp,result[count]);
                                   bloc=1;
                                   test=0;
                                   }
                        else{
                             test=0;
                             if(bloc==1){
                                         bloc==0;
                                         count++;
                                         }
                             }
         }
         return count;
}
示例#9
0
// Main recursive parsing function
bool wxSimpleHtmlParser::ParseHtml(wxSimpleHtmlTag* parent)
{
    while (!Eof())
    {
        EatWhitespace();
        if (IsComment())
        {
            ParseComment();
        }
        else if (IsDirective())
        {
            wxSimpleHtmlTag* tag = ParseDirective();
            if (tag)
                parent->AppendTag(tag);
        }
        else if (IsTagClose())
        {
            wxSimpleHtmlTag* tag = ParseTagClose();
            if (tag)
                parent->AppendTag(tag);
        }
        else if (IsTagStartBracket(GetChar(m_pos)))
        {
            wxSimpleHtmlTag* tag = ParseTagHeader();
            if (tag)
                parent->AppendTag(tag);
        }
        else
        {
            // Just a text string
            wxString text;
            ParseText(text);

            wxSimpleHtmlTag* tag = new wxSimpleHtmlTag(wxT("TEXT"), wxSimpleHtmlTag_Text);
            tag->SetText(text);
            parent->AppendTag(tag);
        }
    }
    return TRUE;
}
Anything GenericXMLParser::ParseCommentCdataOrDtd(bool withindtd)
{
	StartTrace(GenericXMLParser.ParseCommentCdataOrDtd);
	int c;
	c = Get();// read the '!'
	String key("!");
	Anything result;
	switch (Peek()) {
		case '-':
			return ParseComment();
		case '[':
			if (!withindtd) {
				return ParseCdata();    // ignore include or ignore for the moment
			} else {
				goto error;
			}
		case 'D':
			if (!withindtd) {
				return ParseDtd();    // DOCTYPE
			} else {
				goto error;
			}
		case 'E': // ELEMENT or ENTITY
		case 'A': // ATTLIST
		case 'N': // NOTATION
			if (withindtd) {
				key.Append(ParseName());
				break;
			}
		default://lint !e616
		error: {
				String msg("unexpected character in <! element: ");
				msg.Append(char(c));
				Error(msg);
			}
	}
	result[key] = SkipToClosingAngleBracket();
	return result;
}
示例#11
0
ModelData* ModelLoader::LoadModelFile(std::string filePath)
{
	ifstream file;
	file.open(filePath + ".obj");
        
	if (!file)
		return 0;
	string str;

	while (!file.eof())
	{
		file >> str;

		if (str == "#" || str == "s")	ParseComment(file);
		else if (str == "v")			ParsePosition(file);	//position
		else if (str == "vn")			ParseNormal(file);		//normal
		else if (str == "vt")			ParseTexCoord(file);	//texturkoordinat
		else if (str == "f")			ParseFace(file);		//face
		else if (str == "usemtl")		ParseMaterial(file);	//material
		else if (str == "g")			ParseGroup(file);		//group

		else if (str == "mtllib")								//materialfile
		{
			ParseMaterialFile(file, filePath);
		}
                str = "";
	}
	//ParseFace2(file);

	ModelData* model = new ModelData();
	for (auto it = m_groups.begin(); it != m_groups.end(); ++it)
		model->Groups.push_back(it->second);
        
        
	return model;
}
示例#12
0
void MIME::Headers::SetDisposition (std::string const & disposition, std::string const & comment)
{
	_disposition = disposition;
	ParseComment (comment, _dispositionAttrib);
}
示例#13
0
//------------------------------------------------------------------------------
Tokeniser::tokentype Tokeniser::GetNextToken ()
{
	tokentype TokenType = EMPTY;

	while ((TokenType == EMPTY) && !in.bad() && !atEOF)
	{
		curChar = GetNextChar ();

		if (IsWhiteSpace (curChar))
		{
		// skip white space
		}
		else
		{
			if (IsPunctuation (curChar))
			{
 				// classify punctuation token
				switch (curChar)
				{
					case '[': ParseComment (); break;
					case '\'':
						if (ParseString ())
							TokenType = STRING;
						else TokenType = BAD;
						break;
					case '(':
						TokenType = LPAR;
						break;
					case ')':
						TokenType = RPAR;
						break;
					case '{':
						TokenType = LPAR;
						break;
					case '}':
						TokenType = RPAR;
						break;
					case '!':
						TokenType = BANG;
						break;
					case '#':
						TokenType = HASH;
						break;
					case '=':
						TokenType = EQUALS;
						break;
					case ';':
						TokenType = SEMICOLON;
						break;
					case ',':
						TokenType = COMMA;
						break;
					case '*':
						TokenType = ASTERIX;
						break;
					case ':':
						TokenType = COLON;
						break;
					case '-':
						TokenType = MINUS;
						break;
					case '"':
						TokenType = DOUBLEQUOTE;
						break;
					case '/':
						TokenType = BACKSLASH;
						break;
					default:
						TokenType = OTHER;
						break;
				}
			}
			else
			{
            	// It's either a number, or a string
				if (isdigit (curChar))
				{
					TokenType = ParseNumber();
				}
				else
                {
					if (ParseToken ())
						TokenType = STRING;
					else TokenType = BAD;
				}
			}
		}
	}

	if ((TokenType != STRING) && (TokenType != NUMBER))
	{
		token = "";
		token += curChar;
	}
	return TokenType;
}
示例#14
0
int CVPParser::Parse(const char *str)
{
    int i,iline = 0;
    bool inProgram = false;
    std::stringstream input(str);
    struct nvfx_src none = nvfx_src(nvfx_reg(NVFXSR_NONE,0));

    while(!input.eof()) {
        char line[256];
        opcode *opc = NULL;
        struct nvfx_insn *insn = NULL;

        input.getline(line,255);
        iline++;

        for(i=0; i<256; i++) {
            char c = line[i];

            if(c=='\n' || c=='\r' || c==';')
                c = 0;
            if(c=='\t')
                c = ' ';

            line[i] = c;
            if(c==0) break;
        }

        if(line[0]=='#') {
            ParseComment(line);
            continue;
        }

        if(!inProgram) {
            if(strncmp(line,"!!VP2.0",7)==0)
                inProgram = true;
            else if(strncmp(line,"!!ARBvp1.0",10)==0)
                inProgram = true;

            continue;
        }

        char *label = NULL;
        char *col_ptr = NULL;
        char *opcode = NULL;
        char *ptr = line;

        if((col_ptr = strstr((char*)ptr,":"))!=NULL) {
            int j = 0;
            bool valid = true;

            while((ptr+j)<col_ptr) {
                if(j==0 && !(isLetter(ptr[j]) || ptr[j]=='_')) valid = false;
                if(!(isLetter(ptr[j]) || isDigit(ptr[j]) || ptr[j]=='_')) valid = false;
                j++;
            }

            if(valid) {
                label = strtok(ptr,":\x20");
                ptr = col_ptr + 1;
            }
        }

        opcode = strtok(ptr," ");

        if(label) {
            jmpdst d;

            strcpy(d.ident,label);
            d.location = m_nInstructions;
            m_lIdent.push_back(d);
        }

        if(opcode) {
            char *param_str = SkipSpaces(strtok(NULL,"\0"));
            if(strcasecmp(opcode,"OPTION")==0) {
                if(strncasecmp(param_str,"NV_vertex_program3",18)==0)
                    m_nOption |= NV_OPTION_VP3;
                continue;
            } else if(strcasecmp(opcode,"PARAM")==0)
                continue;
            else if(strcasecmp(opcode,"TEMP")==0)
                continue;
            else {
                opc = FindOpcode(opcode);

                insn = &m_pInstructions[m_nInstructions];

                if(!opc) continue;

                InitInstruction(insn,opc->opcode);
                if(opc->opcode==OPCODE_END) {
                    m_nInstructions++;
                    break;
                }

                char *opc_ext = opcode + strlen(opc->mnemonic);
                if(m_nOption&(NV_OPTION_VP2|NV_OPTION_VP3)) {
                    if(opc_ext[0]=='C') {
                        insn->cc_update = TRUE;

                        if(m_nOption&NV_OPTION_VP3 && (opc_ext[1]=='0' || opc_ext[1]=='1')) {
                            switch(opc_ext[1]) {
                            case '0':
                                insn->cc_update_reg = 0;
                                break;
                            case '1':
                                insn->cc_update_reg = 1;
                                break;
                            }
                            opc_ext++;
                        }
                        opc_ext++;
                    }
                }
                if(opc_ext[0]=='_') {
                    if(strncasecmp(opc_ext,"_sat",4)==0) insn->sat = TRUE;
                }
                ParseInstruction(insn,opc,param_str);
                m_nInstructions++;
            }
        }
    }

    for(std::list<jmpdst>::iterator r=m_lJmpDst.begin(); r!=m_lJmpDst.end(); r++) {
        bool found = false;

        for(std::list<jmpdst>::iterator i=m_lIdent.begin(); i!=m_lIdent.end(); i++) {
            if(strcmp(r->ident,i->ident)==0) {
                found = true;
                m_pInstructions[r->location].dst = nvfx_reg(NVFXSR_RELOCATED,i->location);
                break;
            }
        }

        if(found==false) {
            fprintf(stderr,"Identifier \'%s\' not found.\n",r->ident);
            exit(EXIT_FAILURE);
        }
    }

    return 0;
}
示例#15
0
int CFPParser::Parse(const char *str)
{
	int i,iline = 0;
	bool inProgram = false;
	std::stringstream input(str);

	while(!input.eof()) {
		char line[256];
		struct nvfx_insn *insn = NULL;

		input.getline(line,255);
		iline++;
			
		for(i=0;i<256;i++) {
			char c = line[i];

			if(c=='\n' || c=='\r' || c==';')
				c = 0;
			if(c=='\t')
				c = ' ';

			line[i] = c;
			if(c==0) break;
		}

		if(line[0]=='#') {
			ParseComment(line);
			continue;
		}

		if(!inProgram) {
			if(strncmp(line,"!!FP2.0",7)==0)
				inProgram = true;
			else if(strncmp(line,"!!ARBfp1.0",10)==0)
				inProgram = true;

			continue;
		}

		char *label = NULL;
		char *col_ptr = NULL;
		char *opcode = NULL;
		char *ptr = line;
		
		if((col_ptr = strstr((char*)ptr,":"))!=NULL) {
			int j = 0;
			bool valid = true;
			
			while((ptr+j)<col_ptr) {
				if(j==0 && !(isLetter(ptr[j]) || ptr[j]=='_')) valid = false;
				if(!(isLetter(ptr[j]) || isDigit(ptr[j]) || ptr[j]=='_')) valid = false;
				j++;
			}

			if(valid) {
				label = strtok(ptr,":\x20");
				ptr = col_ptr + 1;
			}
		}

		opcode = strtok(ptr," ");

		if(opcode) {
			char *param_str = SkipSpaces(strtok(NULL,"\0"));
			if(strcasecmp(opcode,"OPTION")==0) {
				if(strncasecmp(param_str,"NV_fragment_program2",20)==0)
					m_nOption |= NV_OPTION_FP2;
				continue;
			} else if(strcasecmp(opcode,"PARAM")==0)
				continue;
			else if(strcasecmp(opcode,"TEMP")==0)
				continue;
			else if(strcasecmp(opcode,"OUTPUT")==0) {
				ParseOutput(param_str);
				continue;
			} else {
				struct _opcode opc = FindOpcode(opcode);
				insn = &m_pInstructions[m_nInstructions];

				if(opc.opcode>=MAX_OPCODE) continue;

				InitInstruction(insn,opc.opcode);
				if(opc.opcode==OPCODE_END) {
					m_nInstructions++;
					break;
				}

				ParseInstruction(insn,&opc,param_str);
				m_nInstructions++;
			}
		}
	}
	return 0;
}
示例#16
0
// Get a word token
bool SqlParser::GetWordToken(Token *token)
{
	if(token == NULL)
		return false;

	int len = 0;

	const char *cur = _next_start;

	// Check for a sign for numbers in the first position (sign can go before variable name -num i.e)
	if(_remain_size > 1 && (*cur == '+' || *cur == '-') /*&& cur[1] >= '0' && cur[1] <= '9'*/ &&
		// Skip comment --
		cur[1] != '-') 
	{
		char sign = *cur;

		_remain_size--;
		len++;
		cur++;

		// Allow spaces follow the sign
		while(sign == '-' && _remain_size > 1 && *cur == ' ')
		{
			_remain_size--;
			len++;
			cur++;
		}
	}

	// Identifiers starts as a word but then there is quoted part SCHEMA."TABLE".COL i.e.
	bool partially_quoted_identifier = false;

	// Calculate the length
	while(_remain_size > 0)
	{
		// Check for a comment
		if(len == 0 && ParseComment() == true)
		{
			cur = _next_start;
			continue;
		}

		// Check whether we meet a special character allowed in identifiers
		if(strchr(g_symbols, *cur) != NULL)
		{
			// @variable in SQL Server and MySQL, :new in Oracle trigger, #temp table name in SQL Server
			// * meaning all columns, - in COBOL identifier, label : label name in DB2
			if(*cur != '_' && *cur != '.' && *cur != '@' && *cur != ':' && *cur != '#' && *cur != '*' && 
					*cur != '-' && *cur != '"' && *cur != '[' && *cur != ' ' && *cur != '&')
				break;

			// Spaces are allowed between identifier parts: table . name 
			if(*cur == ' ')
			{
				int ident_len = 0;

				for(int i = 0; i < _remain_size - 1; i++)
				{
					if(cur[i] == ' ' || cur[i] == '\t' || cur[i] == '\n' || cur[i] == '\r')
						continue;

					if(cur[i] == '.')
						ident_len = i;

					break;
				}

				// Not a multi-part identifier
				if(len == 0 || ident_len == 0)
					break;

				_remain_size -= ident_len;
				cur += ident_len;
				len += ident_len;

				continue;
			}

			// * must be after . to not confuse with multiplication operator
			if(*cur == '*' && (len == 0 || (len > 0 && cur > _start && cur[-1] != '.')))
				break;

			// Check for partially quoted identifier that starts as a word then quoted part follows
			if(*cur == '"' || *cur == '[')
			{
				if(len > 0 && cur > _start && cur[-1] == '.')
					partially_quoted_identifier = true;
				
				break;
			}

			if(*cur == ':')
			{
				// But := also means assigment in Oracle (space is not allowed between : and =)
				if((_remain_size > 1 && cur[1] == '=') ||
				  // In DB2, Teradata, MySQL : used in label, and label:BEGIN (without spaces) or 
				  // label :BEGIN is correct, but :param can be also used in scripts
				  (Source(SQL_DB2, SQL_TERADATA, SQL_MYSQL) == true && 
						IsScope(SQL_SCOPE_SELECT_STMT) == false) ||
				  // In Informix, PostgreSQL :: is data type cast operator
				  (_remain_size > 1 && cur[1] == ':') || (cur > _start && cur[-1] == ':'))
				break;
			}

			// : can follow after label in DB2
			//if(*cur == ':' && len == 0 && _remain_size > 1 && Str::IsSpace(cur[1]) == true)
			//	break;

			// & used as parameter marker in scripts i.e. SQL*Plus, must be at the first position
			if(*cur == '&' && len != 0)
				break;

			// Allow - in COBOL only
			if(*cur == '-' && _source_app != APP_COBOL && _level != LEVEL_APP)
				break;

			bool right = true;

			// @ must not be followed by a blank or delimiter
			if(*cur == '@')
			{
				// Remain size not decremented yet
				if(_remain_size == 1 || 
					(_remain_size > 1 && (cur[1] == ' ' || cur[1] == '\r' || cur[1] == '\n' || cur[1] == '\t')))
					right = false;
			}
			else
			// . is the statement delimiter in COBOL
			if(_source_app == APP_COBOL && _level == LEVEL_APP && *cur == '.')
				right = false;

			if(right == false)
				break;
		}

		_remain_size--;
		cur++;
		len++;
	}

	if(partially_quoted_identifier == true)
	{
		_remain_size += len;

		GetQuotedIdentifier(token, true);
	}
	else			
	if(len > 0)
	{
		// If a single special character was selected in the right position, but no more characters followed
		// do not return as word
		if(len == 1 && (strchr(g_symbols, *_next_start) != NULL ||
			// Also skip N'literal' in SQL Server
			(*_next_start == 'N' && _remain_size > 1 && *cur == '\'')))
		{
			_remain_size++;
			return false;
		}

		token->type = TOKEN_WORD;
		token->chr = 0;
		token->wchr = 0;
		token->str = _next_start;
		token->wstr = 0;
		token->len = len;
		token->remain_size = _remain_size;
		token->next_start = _next_start + len;

		_tokens.Add(token);

		_next_start = cur;
	}

	return (len > 0) ? true : false;
}
示例#17
0
void DwRfc1521Tokenizer::ParseToken()
{
    // Assume the field body has already been extracted.  That is, we don't
    // have to watch for the end of the field body or folding.  We just
    // treat any CRs or LFs as white space.
    mTokenStart = mNextStart;
    mTokenLength = 0;
    mTkType = eTkNull;
    // Skip leading space.  Also, since control chars are not permitted
    // in atoms, skip these, too.
    while(1)
    {
        if(mTokenStart >= mString.length())
        {
            return;
        }
        if(isnotspaceorcntrl(mString[mTokenStart]))
            break;
        ++mTokenStart;
    }
    char ch = mString[mTokenStart];
    switch(ch)
    {
    // Quoted string
    case '"':
        mTkType = eTkQuotedString;
        ParseQuotedString();
        break;
    // Comment
    case '(':
        mTkType = eTkComment;
        ParseComment();
        break;
    // Domain literal
    case '[':
        mTkType = eTkDomainLiteral;
        ParseDomainLiteral();
        break;
    // Special
    case ')':
    case '<':
    case '>':
    case '@':
    case ',':
    case ';':
    case ':':
    case '\\':
    case '/':
    case ']':
    case '?':
    case '=':
        mTkType = eTkTspecial;
        mTokenLength = 1;
        mToken = mString.substr(mTokenStart, 1);
        mNextStart = mTokenStart + 1;
        break;
    default:
        mTkType = eTkToken;
        ParseAtom();
        break;
    }
    if(mDebugOut) PrintToken(mDebugOut);
}
示例#18
0
	bool Parser::GetToken(token& out)
	{
		// trim leading whitespace first:
		for (; text.str < text.end; ++text.str)
		{
			char ch = *text.str;
			if (ch == ' ' || ch == '\t')  continue;
			if (ch == '\r' || ch == '\n') SkipNewLine(ch);
			else break; // not ' ' or '\t', so finish trim
		}

		out.end = out.str = text.str; // mark down start and default end
		column  = GetColumn();

		for ( ; text.str < text.end; ++text.str)
		{
			char ch = *text.str;
			if (ch == '\r' || ch == '\n') {
				SkipNewLine(ch);
				continue;
			}

			if (ch == '/') { // possible comment start?
				char c2 = text.str[1];
				if (c2 == '/' || c2 == '*') // line comment '//' or block comment '/*'
					return ParseComment(out, c2 == '*'); // parse the comment
			}
			else if (ch == '"')
				return ParseStringLiteral(out); // skip the literal
			else if (ch == '\'')
				return ParseCharLiteral(out);

			if (BreakerIndex[ch] == 1) // token starts with a breaker char
			{
				line    = cur_line;
				column  = GetColumn();

				char c2 = *++text.str;
				char c3 = text.str[1];

				if (c3 == '=' && (
					(ch == '<' && c2 == '<')|| // <<=
					(ch == '>' && c2 == '>'))) // >>=
				{
					text.str += 2; // 3 char token parsed
				}
				else if ((c2 == '=' && (
					 ch == '<' || // <=
					 ch == '>' || // >=
					 ch == '=' || // ==
					 ch == '!' || // !=
					 ch == '+' || // +=
					 ch == '-' || // -=
					 ch == '*' || // *=
					 ch == '/' || // /=
					 ch == '%' || // %=
					 ch == '&' || // &=
					 ch == '|' || // |=
					 ch == '^'    // ^=
					)) || 
					(ch == '+' && c2 == '+') || // ++
					(ch == '-' && c2 == '-') || // --
					(ch == '-' && c2 == '>') || // ->
					(ch == '?' && c2 == '?') || // ??
					(ch == '&' && c2 == '&') || // &&
					(ch == '|' && c2 == '|') || // ||
					(ch == '<' && c2 == '<') || // <<
					(ch == '>' && c2 == '>') || // >>
					(ch == ':' && c2 == ':'))   // ::
				{
					++text.str;  // 2 char token parsed
				}
				out.end = text.str;
				return true; // 1 char token parsed
			}

			// so this is a literal or a statement?
			return ParseStatement(out);
		}
		return false; // end of buffer
	}
示例#19
0
void CASEFile::Parse()
{
	if (m_file == NULL)
	{
		return;
	}
	CAlertErrHandler errhandler;
	CTokenizer* tokenizer = CTokenizer::Create(TKF_USES_EOL | TKF_NUMERICIDENTIFIERSTART);
	tokenizer->SetErrHandler(&errhandler);
	tokenizer->SetKeywords(s_keywords);
	tokenizer->SetSymbols(s_symbols);
	tokenizer->AddParseFile(m_file, 16 * 1024);
	int tokType = TK_UNDEFINED;
	while(tokType != TK_EOF)
	{
		CToken* curToken = tokenizer->GetToken();
		if (curToken->GetType() == TK_EOF)
		{
			curToken->Delete();
			tokType = TK_EOF;
			break;
		}
		if (curToken->GetType() == TK_EOL)
		{
			curToken->Delete();
			continue;
		}
		if (curToken->GetType() != TK_ASE_ASTERISK)
		{
			tokenizer->Error(TKERR_UNEXPECTED_TOKEN);
			curToken->Delete();
			tokenizer->GetToEndOfLine()->Delete();
			continue;
		}
		curToken->Delete();
		curToken = tokenizer->GetToken();
		tokType = curToken->GetType();
		curToken->Delete();
		switch(tokType)
		{
		case TK_EOF:
			break;
		case TK_GEOMOBJECT:
			ParseGeomObject(tokenizer);
			break;
		case TK_SCENE:
			ParseScene(tokenizer);
			break;
		case TK_MATERIAL_LIST:
			ParseMaterialList(tokenizer);
			break;
		case TK_ASE_COMMENT:
			ParseComment(tokenizer);
			break;
		case TK_3DSMAX_ASCIIEXPORT:
			ParseAsciiExport(tokenizer);
			break;
		default:
			tokenizer->Error(TKERR_UNEXPECTED_TOKEN);
			tokenizer->GetToEndOfLine()->Delete();
			break;
		}
	}
}