Пример #1
0
void TFunctionScanner::SkipString(const TChar*& text)
{
	TChar	terminator = *text;
	ASSERT(terminator == '\'' || terminator == '\"');
	NextChar(text);
	
	TChar previous = 0;
	TChar previous2 = 0;
	
	while (1)
	{
		TChar ch = *text;
		
		if (ch == terminator && (previous != '\\' || previous2 == '\\'))
		{
			NextChar(text);
			break;
		}
	
		previous2 = previous;
		previous = ch;
		NextChar(text);
	}
}
Пример #2
0
bool wxTextInputStream::EatEOL(const wxChar &c)
{
    if (c == wxT('\n')) return true; // eat on UNIX

    if (c == wxT('\r')) // eat on both Mac and DOS
    {
        wxChar c2 = NextChar();
        if(c2 == wxEOT) return true; // end of stream reached, had enough :-)

        if (c2 != wxT('\n')) UngetLast(); // Don't eat on Mac
        return true;
    }

    return false;
}
Пример #3
0
// Read string up to terminating quote, ignoring embedded double quotes
void Lexer::ScanString(int stringStart)
{
	char ch;
	do
	{
		ch = NextChar();
		if (!ch)
		{
			CompileError(TEXTRANGE(stringStart, CharPosition()), LErrStringNotClosed);
		}
		else
		{
			if (ch == STRINGDELIM)
			{
				// Possible termination or double quotes
				if (PeekAtChar() == STRINGDELIM)
					ch = NextChar();
				else
					break;
			}
			*tp++ = ch;
		}
	} while (ch);
}
Пример #4
0
bool FarXMLScanner::ParseAttribute (FarXMLNode *node)
{
    FarString attrName = NextName();
  if (attrName.IsEmpty())
    return false;
    SkipWhitespace();
  if (!NextExpectedChar ('='))
    return false;
  SkipWhitespace();

  char valueDelimiter = NextChar();
  if (valueDelimiter != '\'' && valueDelimiter != '\"')
  {
    ReportError ("\" or \'");
    return false;
  }

  FarString attrValue;
  while (1)
  {
    char c = NextChar();
    if (c == valueDelimiter)
      break;
    else if (c == '&')
    {
      int entityValue = ParseEntity();
      if (entityValue == -1)
        return false;
      attrValue += (char) entityValue;
    }
    else
            attrValue += c;
  }
  node->AddAttr (attrName, attrValue);
  return true;
}
Пример #5
0
// creates a new pathame string that is a dup of the input pathname, with the
// extension (if any) replaced by the given extension.
CHAR * NEAR CloneNameAddExt
(
    CHAR * szInputFile,
    CHAR * szExt
)
{
    CHAR * szFile;
    CHAR * pExt;
    CHAR * pch;

    // CONSIDER:
    // assumes the extension is no more than 3 bytes incl '.' (ie non-DBCS)
    // (This is true for the moment - can it ever change???)

    // alloc string with enough space for ".", extension, and null
    szFile = malloc(strlen(szInputFile)+1+3+1);
    strcpy(szFile, szInputFile); 	// start with input file name

    // find "." (if present) that occurs after last \ or /.
    pExt = NULL;
    for (pch = szFile; *pch; NextChar(pch))
	{
	    switch (*pch)
		{
#ifdef	MAC
		case ':':
		case ' ':       // start search over at a space
#else	//MAC
		case '\\':
		case '/':
#endif	//MAC
		    pExt = NULL;
		    break;
		case '.':
		    pExt = pch;
		    break;
		default:
		    ;
		}
	}
    if (pExt == NULL)	// if no extension after last '\', then
	pExt = pch;	// append an extension to the name.

    strcpy (pExt, szExt);	// replace extension (if present) with
				// desired extension

    return szFile;
}
Пример #6
0
 bool NextExpectedChar (char expected)
 {
   char c = NextChar();
   if (c != expected)
   {
     if (fErrorSink != NULL)
     {
       char buf [2];
       buf [0] = expected;
       buf [1] = '\0';
       fErrorSink->ReportError (fCurLine, GetCurColumn(), buf);
     }
     return false;
   }
   return true;
 }
Пример #7
0
bool Parser::ParseKeyword(Statement* statement)
{
	// ["?"]
	if (GetCurrentChar() == '?') {
		NextChar();
		statement->SetType(Statement::kQuery);
	}
	// Keyword
	BString* keyword = fScanner.ScanIdent();
	if (keyword == NULL) {
		Error("Identifier expected");
		return false;
	}
	statement->SetKeyword(keyword);
	return true;
}
Пример #8
0
void SymName (char* S)
/* Read a symbol from the input stream. The first character must have been
** checked before calling this function. The buffer is expected to be at
** least of size MAX_IDENTLEN+1.
*/
{
    unsigned Len = 0;
    do {
        if (Len < MAX_IDENTLEN) {
            ++Len;
            *S++ = CurC;
        }
        NextChar ();
    } while (IsIdent (CurC) || IsDigit (CurC));
    *S = '\0';
}
Пример #9
0
Json* Json::Parser::ParsePrimary(){
	NextChar();
	Kind kind = KindPreview(ch);
	Json* json = NULL;
	switch(kind){
	case kString: { json = ParseString(); break;}
	case kNumber: { json = ParseNumber(); break;}
	case kFalse: { json = ParseFalse(); break; }
	case kTrue: { json = ParseTrue(); break; }
	case kArray: { json = ParseArray(); break; }
	case kObject: { json = ParseObject(); break; }
	case kNull: break;
	default: break;
	};
	return json;
}
Пример #10
0
/***********************************************************************
Function  : main

Returns   : zero for successful execution
	    3    if an error is encountered

The main routine allocates buffers for the input and output buffer.
Characters are then read from the input buffer building the line buffer
that will be sent to the filter processor.  Lines are read and filtered
until the end of input is reached.
***********************************************************************/
int main( void )
{
   char c;
   unsigned long core;

   setmode(1,O_BINARY);               /* set output stream to binary mode */
   core = farcoreleft();
   if (core > 64000U)
      BufSize = 64000U;
   else BufSize = (unsigned)core;     /* get available memory */
                                      /* stay under 64K */
   if ((CurInPtr = malloc(BufSize)) == NULL) /* allocate buffer space */
      exit(3);
#if 0
   processor = NULL;                  /* set current processor to none */
#endif

   InBuffer = CurInPtr;               /* input buffer is first half of space */
   BufSize = BufSize/2;               /* output buffer is 2nd half */
   OutBuffer = InBuffer + BufSize;
   CurOutPtr = OutBuffer;             /* set buffer pointers */
   LinePtr = Line;
   CurBufLen = 0;
   Put(PipeId,PipeIdLen);             /* send ID string to message window */
   while ((c = NextChar()) != 0)      /* read characters */
   {
      if ((c == 13) || (c == 10))     /* build until line end */
      {
         *LinePtr = 0;
         ProcessLine(Line);           /* filter the line */
         LinePtr = Line;
      }
      /* characters are added to buffer up to 132 characters max */
      else if ((FP_OFF(LinePtr) - FP_OFF(&Line)) < 132)
      {
         *LinePtr = c;                /* add to line buffer */
         LinePtr++;
      }
   }
   *LinePtr = 0;
   ProcessLine(Line);                 /* filter last line */
   EndMark = MsgEoFile;
   Put(&EndMark,1);                   /* indicate end of input to
                                         the message window */
   flushOut((unsigned)(CurOutPtr-OutBuffer));     /* flush the buffer */
   return 0;                          /* return OK */
}
Пример #11
0
/*************************************************************************
Function  : NextChar
Parameters: none
Returns   : next character in input buffer or 0 on end of file

Input from the standard input stream is buffered in a global buffer InBuffer
which is allocated in function main.  The function will return
the next character in the buffer, reading from the input stream when the
buffer becomes empty.
**************************************************************************/
char NextChar(void)
{
  if (CurInPtr < InBuffer+CurBufLen)  /* if buffer is not empty */
  {
    return *(CurInPtr++);             /* return next character */
  }
  else
  {
    CurInPtr = InBuffer;              /* reset pointer to front of buffer */
    lseek(0,InOff,0);                 /* seek to the next section for read */
    InOff += BufSize;                 /* increment pointer to next block */
    if ((CurBufLen = read(0,InBuffer,BufSize)) !=0)
      return NextChar();              /* recursive call merely returns
                                         first character in buffer after read */
    return 0;                         /* return 0 on end of file */
  }
}
Пример #12
0
// expect we are not in a C-string.
bool Tokenizer::SkipToOneOfChars(const wxChar* chars, bool supportNesting, bool skipPreprocessor, bool skipAngleBrace)
{
    while (NotEOF() && !CharInString(CurrentChar(), chars))
    {
        MoveToNextChar();

        while (SkipString() || SkipComment())
            ;

        // use 'while' here to cater for consecutive blocks to skip (e.g. sometemplate<foo>(bar)
        // must skip <foo> and immediately after (bar))
        // because if we don't, the next block won't be skipped ((bar) in the example) leading to weird
        // parsing results
        bool done = false;
        while (supportNesting && !done)
        {
            switch (CurrentChar())
            {
                case '#':
                    if (skipPreprocessor)
                        SkipToEOL(true);
                    else
                        done = true;
                    break;
                case '{': SkipBlock('{'); break;
                case '(': SkipBlock('('); break;
                case '[': SkipBlock('['); break;
                case '<': // don't skip if << operator
                    if (skipAngleBrace)
                    {
                        if (NextChar() == '<')
                            MoveToNextChar(2); // skip it and also the next '<' or the next '<' leads to a SkipBlock('<');
                        else
                            SkipBlock('<');
                        break;
                    }

                default: done = true; break;
            }
        }

    }

    return NotEOF();
}
Пример #13
0
wxString wxTextInputStream::ReadLine()
{
    wxString line;

    while ( !m_input.Eof() )
    {
        wxChar c = NextChar();
        if(c == wxEOT)
            break;

        if (EatEOL(c))
            break;

        line += c;
    }

    return line;
}
Пример #14
0
void OptError( char *err )
{
    char        *curr;
    char        buff[CMD_LEN];
    char        token[CMD_LEN];

    curr = token;
    while( isalnum( CurrChar ) ) {
        *curr++ = CurrChar;
        NextChar();
    }
    if( curr == token ) {
        if( CurrChar == ARG_TERMINATE ) CurrChar = ' ';
        *curr++ = CurrChar;
    }
    *curr = NULLCHAR;
    Format( buff, err, token );
    StartupErr( buff );
}
Пример #15
0
static void CError( void )
{
    size_t      len;
    bool        save;

    len = 0;
    while( CurrChar != '\n' && CurrChar != '\r' && CurrChar != EOF_CHAR ) {
        if( len != 0 || CurrChar != ' ' ) {
            Buffer[len++] = CurrChar;
        }
        NextChar();
    }
    Buffer[len] = '\0';
    /* Force #error output to be reported, even with preprocessor */
    save = CompFlags.cpp_output;
    CompFlags.cpp_output = FALSE;
    CErr2p( ERR_USER_ERROR_MSG, Buffer );
    CompFlags.cpp_output = save;
}
Пример #16
0
static void ReadIdent (void)
/* Read an identifier from the current input position into Ident. Filling SVal
** starts at the current position with the next character in C. It is assumed
** that any characters already filled in are ok, and the character in C is
** checked.
*/
{
    /* Read the identifier */
    do {
        SB_AppendChar (&CurTok.SVal, C);
        NextChar ();
    } while (IsIdChar (C));
    SB_Terminate (&CurTok.SVal);

    /* If we should ignore case, convert the identifier to upper case */
    if (IgnoreCase) {
        UpcaseSVal ();
    }
}
Пример #17
0
static int SkipWhite (void)
/* Skip white space in the input stream, reading and preprocessing new lines
** if necessary. Return 0 if end of file is reached, return 1 otherwise.
*/
{
    while (1) {
        while (CurC == '\0') {
            if (NextLine () == 0) {
                return 0;
            }
            Preprocess ();
        }
        if (IsSpace (CurC)) {
            NextChar ();
        } else {
            return 1;
        }
    }
}
Пример #18
0
local void CError( void )
{
    int i;
    int save;

    i = 0;
    while( CurrChar != '\n' && CurrChar != '\r' && CurrChar != EOF_CHAR ) {
        if( i != 0 || CurrChar != ' ' ) {
            Buffer[ i ] = CurrChar;
            ++i;
        }
        NextChar();
    }
    Buffer[ i ] = '\0';
    /* Force #error output to be reported, even with preprocessor */
    save = CompFlags.cpp_output;
    CompFlags.cpp_output = 0;
    CErr2p( ERR_USER_ERROR_MSG, Buffer );
    CompFlags.cpp_output = save;
}
Пример #19
0
        // The folowing function was copied verbatim from wxTextStream::ReadLine()
        // The only change, is the addition of m_input.CanRead() in the while()
        wxString ReadLine()
        {
            wxString line;

            while ( m_input.CanRead() && !m_input.Eof() )
            {
                wxChar c = NextChar();
                if(m_input.LastRead() <= 0)
                    break;

                if ( !m_input )
                    break;

                if (EatEOL(c))
                    break;

                line += c;
            }
            return line;
        }
Пример #20
0
Json* Json::Parser::ParseNumber(){
	std::string snum = "";
	bool isDouble = false;
	while(isdigit(ch) || ch == '.'){
		if(ch == '.') {
			if(isDouble) JSON_ASSERT("unexpected char \".\" came out again");
			isDouble = true;
		}else
			snum += ch;
		NextChar();
	}
	BackCharIndex();	
	if(isDouble){
		double num = atof(snum.c_str());
		return new Json(num);
	}else{
		int num = atoi(snum.c_str());
		return new Json(num);
	}
}
Пример #21
0
bool Scanner::ScanHexadecimalSubstring(BString* literal)
{
	int digit = 0;
	int value = 0;
	while(true) {
		NextChar();
		int ch = GetCurrentChar();
		
		if (ch == '>') {
			// end of hexadecimal substring reached
			return digit == 0;
		}
		
		if (ch == -1) {
			Error("Unexpected EOF in hexadecimal substring!");
			return false;
		}
		
		if (IsWhitespace(ch)) {
			// ignore white spaces
			continue;
		}
		
		int d = getHexadecimalDigit(ch);
		if (d == -1) {
			Error("Character is not a hexadecimal digit!");
			return false;
		}
		
		if (d == 0) {
			// first digit
			value = d << 8;
			d = 1;
		} else {
			// second digit
			value |= d;
			literal->Append((unsigned char)value, 1);
			d = 0;
		}
	}
}
Пример #22
0
static void MacroCall (StrBuf* Target, Macro* M)
/* Process a function like macro */
{
    MacroExp    E;

    /* Eat the left paren */
    NextChar ();

    /* Initialize our MacroExp structure */
    InitMacroExp (&E, M);

    /* Read the actual macro arguments */
    ReadMacroArgs (&E);

    /* Compare formal and actual argument count */
    if (CollCount (&E.ActualArgs) != (unsigned) M->ArgCount) {

        StrBuf Arg = STATIC_STRBUF_INITIALIZER;

        /* Argument count mismatch */
        PPError ("Macro argument count mismatch");

        /* Be sure to make enough empty arguments available */
        while (CollCount (&E.ActualArgs) < (unsigned) M->ArgCount) {
            ME_AppendActual (&E, &Arg);
        }
    }

    /* Replace macro arguments handling the # and ## operators */
    MacroArgSubst (&E);

    /* Do macro replacement on the macro that already has the parameters
     * substituted.
     */
    M->Expanding = 1;
    MacroReplacement (&E.Replacement, Target);
    M->Expanding = 0;

    /* Free memory allocated for the macro expansion structure */
    DoneMacroExp (&E);
}
Пример #23
0
//*****************************************************************************
// Lex::RemTermination - Terminates remarks.
// Returns : -1 if <NextLexem> must returns something, 0 otherwise.
//*****************************************************************************
int TXML_Lex::RemTermination( Lexem& /*ret*/ )
//       ~~~~~~~~~~~~~~
{
	static QString startRem = _T("<!--");
	static QString endRem   = _T("-->");
	while( isLA( startRem ) )
	{
		Inc( startRem.length() );
		while( !::_iseof( SoleChar() ) && !isLA( endRem ) )
			NextChar();
		if( ::_iseof( SoleChar() ) )
		{
			lex_err = Lex::UnterminatedComment;
			return -1;
		}
		else
			Inc( endRem.length() );
                while( IsSpaceNextChar() ) ;
	}
	return 0;
}
Пример #24
0
static int GetEncodedChar (char* Buf, unsigned* IPtr, unsigned Size)
{
    char Decoded = 0;
    int Count;

    if (C == EOF) {
        return -1;
    } else if (C != '\\') {
        Decoded = C;
        NextChar ();
        goto Store;
    }
    NextChar (); /* consume '\\' */
    if (C == EOF) {
        return -1;
    } else if (IsODigit (C)) {
        Count = 3;
        do {
            Decoded = Decoded * 8 + DigitVal (C);
            NextChar ();
            --Count;
        } while (Count > 0 && C != EOF && IsODigit (C));
    } else if (C == 'x') {
        NextChar (); /* consume 'x' */
        Count = 2;
        while (Count > 0 && C != EOF && IsXDigit (C)) {
            Decoded = Decoded * 16 + DigitVal (C);
            NextChar ();
            --Count;
        }
    } else {
        switch (C) {
            case '"': case '\'': case '\\':
                        Decoded = C;        break;
            case 't':   Decoded = '\t';     break;
            case 'r':   Decoded = '\r';     break;
            case 'n':   Decoded = '\n';     break;
            default:    return -1;
        }
        NextChar ();
    }
Store:
    if (*IPtr < Size - 1) {
        Buf [(*IPtr)++] = Decoded;
    }
    Buf [*IPtr] = 0;
    return 0;
}
Пример #25
0
static void DoGetItem( char *buff, bool stop_on_first )
{
    for( ;; ) {
        if( CurrChar == ' ' )
            break;
        if( CurrChar == '\t' )
            break;
        if( CurrChar == ARG_TERMINATE )
            break;
        if( CurrChar == TRAP_PARM_SEPARATOR )
            break;
        if( CurrChar == '{' )
            break;
        if( OptDelim( CurrChar ) && stop_on_first )
            break;
        *buff++ = CurrChar;
        NextChar();
        stop_on_first = true;
    }
    *buff = NULLCHAR;
}
Пример #26
0
// !quotedValue means Translation String
BString* Scanner::ScanLiteral(bool quotedValue, int separator)
{
	BString* literal = new BString();
	
	while (true) {
		int ch = GetCurrentChar();
		if (ch == '<') {
			if (!ScanHexadecimalSubstring(literal)) {
				delete literal;
				return NULL;
			}
		} else if (quotedValue && (ch == kLf || ch == kCr)) {
			// nothing to do
		} else if (!quotedValue && ch == '"') {
			// translation string allows '"'
		} else if (!IsChar(ch) || ch == separator) {
			return literal;
		}
		literal->Append(ch, 1);
		NextChar();
	}
}
Пример #27
0
CToken* CTokenizer::HandleFloat(bool thesign, long value)
{
	float lower = 1.0;
	float newValue = (float)value;
	byte theByte;
	while(NextChar(theByte))
	{
		if ((theByte >= '0') && (theByte <= '9'))
		{
			lower = lower / 10;
			newValue = newValue + ((theByte - '0') * lower);
			continue;
		}
		PutBackChar(theByte);
		break;
	}
	if (thesign)
	{
		newValue = -newValue;
	}
	return CFloatToken::Create(newValue);
}
Пример #28
0
CToken* CTokenizer::HandleString()
{
	char theString[MAX_STRING_LENGTH];
	for (int i = 0; i < MAX_STRING_LENGTH; i++)
	{
		if (!NextChar((byte&)theString[i]))
		{
			return NULL;
		}
		if (theString[i] == '"')
		{
			theString[i] = '\0';
			return CStringToken::Create(theString);
		}
		if (theString[i] == '\\')
		{
			theString[i] = Escapement();
		}
	}
	Error(TKERR_STRINGLENGTHEXCEEDED);
	return NULL;
}
Пример #29
0
void Tokenizer::SkipToNextConditionPreprocessor()
{
    do
    {
        wxChar ch = CurrentChar();
        if (ch == _T('\'') || ch == _T('"') || ch == _T('/') || ch <= _T(' '))
        {
            while (SkipWhiteSpace() || SkipString() || SkipComment())
                ;
            ch = CurrentChar();
        }

        if (ch == _T('#'))
        {
            const unsigned int undoIndex = m_TokenIndex;
            const unsigned int undoLine = m_LineNumber;

            MoveToNextChar();
            while (SkipWhiteSpace() || SkipComment())
                ;

            const wxChar current = CurrentChar();
            const wxChar next = NextChar();

            // #if
            if (current == _T('i') && next == _T('f'))
                SkipToEndConditionPreprocessor();

            // #else #elif #elifdef #elifndef #endif
            else if (current == _T('e') && (next == _T('l') || next == _T('n')))
            {
                m_TokenIndex = undoIndex;
                m_LineNumber = undoLine;
                break;
            }
        }
    }
    while (MoveToNextChar());
}
Пример #30
0
int CubeLexer::SortText(char *SourceText)
{
	unsigned long Offset=0;
	if (m_Sources)
	{
		free(m_Sources);
		m_SourceOffset=0;
		m_SortStatus=SORT_STATUS_NORMAL;
	}
	if ((m_Sources=(char *)malloc(strlen(SourceText)+1))==NULL)
	{
		return FALSE;
	}

	m_SortStatus=SORT_STATUS_NEWLINE;

	while(*SourceText)
	{
		if (NextChar(*SourceText))
		{
			if(IsNewLine(*SourceText)&&IsSpacer(m_Sources[Offset-1]))
				Offset--;
			if(IsCommentStart(*SourceText)&&IsSpacer(m_Sources[Offset-1]))
				Offset--;
			if(IsDelimiter(*SourceText)&&IsSpacer(m_Sources[Offset-1]))
				Offset--;
			if(IsSpacer(*SourceText)&&IsDelimiter(m_Sources[Offset-1]))
			{
				SourceText++;
				continue;
			}

			m_Sources[Offset++]=*(SourceText);
		}
		SourceText++;
	}
	m_Sources[Offset]='\0';
	return TRUE;
}