Example #1
0
    OSReturn_t
    Parser::parseNumber(uint64_t& num)
    {
      uint64_t n;
      n = 0;

      uchar_t ch;
      ch = skipSpaces();

      for (; hasMoreContent(); advanceCurrent())
        {
          uchar_t ch;
          ch = getCurrentChar();

          if ('0' <= ch && ch <= '9')
            {
              n = n * 10 + (ch - '0');
            }
          else
            break;
        }
      num = n;

      return OSReturn::OS_OK;
    }
Example #2
0
    uchar_t
    Parser::skipSpaces(void)
    {
      for (; hasMoreContent(); advanceCurrent())
        {
          uchar_t ch;
          ch = getCurrentChar();
          if (ch != ' ' && ch != '\t')
            return ch;
        }

      return '\0';
    }
Example #3
0
	Scanner::Scanner(const char* sourceCode) :
        finished(false), sourceCodePointer(sourceCode), movementCounter(0)
	{
		currentChar = *sourceCodePointer;

		if (getCurrentChar() == '\0') {
			hasMore = false;
		}
		else {
			hasMore = true;
		}

		lineNumber = 1;
		columnNumber = 1;

		currentIndex = 0;
	}
Example #4
0
    OSReturn_t
    Parser::parseVariableName(uchar_t* pName, std::size_t siz)
    {
      OSReturn_t r;

      r = skipCharacter('"');
      if (r != OSReturn::OS_OK)
        return r;

      bool isTooLarge;
      isTooLarge = false;

      for (; hasMoreContent(); advanceCurrent())
        {
          uchar_t ch;
          ch = getCurrentChar();

          if (ch == '"')
            {
              // Skip over terminating "
              advanceCurrent();
              break;
            }

          if (siz > 1)
            {
              *pName++ = ch;
              *pName = '\0';
              --siz;
            }
          else
            {
              isTooLarge = true;
            }
        }

      r = skipCharacter(':');
      if (r != OSReturn::OS_OK)
        return r;

      if (isTooLarge)
        return OSReturn::OS_NOT_ENOUGH_SPACE;

      return OSReturn::OS_OK;
    }
Example #5
0
    OSReturn_t
    Parser::parseString(uchar_t* string, std::size_t siz)
    {
      OSReturn_t r;

      uchar_t ch;
      ch = skipSpaces();

      r = skipCharacter('"');
      if (r != OSReturn::OS_OK)
        return r;

      bool isTooLarge;
      isTooLarge = false;

      for (; hasMoreContent(); advanceCurrent())
        {
          ch = getCurrentChar();

          if (ch == '"')
            {
              // Skip over terminating "
              advanceCurrent();
              break;
            }

          if (siz > 1)
            {
              *string++ = ch;
              *string = '\0';
              --siz;
            }
          else
            {
              isTooLarge = true;
            }
        }

      if (isTooLarge)
        return OSReturn::OS_NOT_ENOUGH_SPACE;

      return OSReturn::OS_OK;
    }
Example #6
0
    OSReturn_t
    Parser::parseBoolean(bool& flag)
    {
      OSReturn_t ret;
      ret = OSReturn::OS_OK;

      uchar_t ch;
      ch = skipSpaces();

      uchar_t tmp[6];
      uint_t i;
      i = 0;

      for (; hasMoreContent(); advanceCurrent())
        {
          uchar_t ch;
          ch = getCurrentChar();

          if (!isalpha(ch))
            break;

          if (i < sizeof(tmp))
            {
              tmp[i++] = ch;
              tmp[i] = '\0';
            }
        }

      if (strcmp((const char*) tmp, "true") == 0)
        {
          flag = true;
        }
      else
        {
          if (strcmp((const char*) tmp, "false") != 0)
            ret = OSReturn::OS_BAD_PARAMETER;

          flag = false;
        }

      return ret;
    }
Example #7
0
    OSReturn_t
    Parser::parseNumber(int32_t& num)
    {
      int32_t n;
      n = 0;

      bool isNegative;
      isNegative = false;

      uchar_t ch;
      ch = skipSpaces();
      if (ch == '-')
        {
          isNegative = true;
          advanceCurrent();
        }

      for (; hasMoreContent(); advanceCurrent())
        {
          uchar_t ch;
          ch = getCurrentChar();

          if ('0' <= ch && ch <= '9')
            {
              n = n * 10 + (ch - '0');
            }
          else
            break;
        }

      if (isNegative)
        num = -n;
      else
        num = n;

      return OSReturn::OS_OK;
    }
Example #8
0
//===------------------------------===//
// Get the next terminal state
// Handle error input
//===------------------------------===//
int Scanner::getNextTerminalState()
{
    int current_state = 0;
    char current_char;
    
    do
    {
        current_char    = getCurrentChar();
		
		// Only add to lexeme one double quote that
		// immediately follows a double quote
		if ( current_char != '"' || current_state == 10 )
			current_lexeme  = current_lexeme + current_char;
        
        
        // Check whether we found a comment
        string bracket_comment  = current_lexeme.substr( 0, 1 );
        string slash_comment    = current_lexeme.substr( 0, 2 );
		
        if ( ( bracket_comment == "{" && current_char == '}' ) || ( slash_comment == "//" && current_char == '\n' ) )
            current_lexeme = "";
        
	
        // Erase all whitespaces if the whitespace
        // is the only thing in current lexeme
        if ( isspace( current_char ) )
            if ( current_lexeme.length() == 1 )
                current_lexeme.erase( current_lexeme.length() - 1, 1 );
        
        
        // Mark beginning line and column of lexeme
        if ( current_lexeme.length() == 1 )
        {
            token_line      = line_number;
            token_column    = column_number;
        }
		
        
        // Get the next state
        current_state = getNextState( current_state, current_char );
		
        
        // Advance to the next character
        // for use in the subsequent loop
        advance();
        
        
        switch ( current_state )
        {
            case IDENT_T:           return current_state;
            case SINGLE0_T:         return current_state;
            case INTEGER_T:         return current_state;
            case SETEQUAL_T:        return current_state;
			case ISEQUAL_ST:		return current_state;
			case NOTEQUAL_ST:		return current_state;
			case LESSER_ST:			return current_state;
			case LESSEQUAL_ST:		return current_state;
			case GREATER_ST:		return current_state;
			case GREQUAL_ST:		return current_state;
            case ADDITION_ST:       return current_state;
            case SUBTRACT_ST:       return current_state;
            case ASTERISK_ST:       return current_state;
			case COLON_T:			return current_state;
            case SEMICOLON_T:       return current_state;
			case COMMA_T:			return current_state;
            case PERIOD_T:          return current_state;
			case STRINGCONST_T:		return current_state;
			case CRERRORCONST_T:	return current_state;
			case EOFERRORCONST_T:	return current_state;
			case LEFTPARENTH_T:		return current_state;
			case RIGHTPARENTH_T:	return current_state;
            case SLASHERROR_T:      return current_state;
            case BRACKETERROR_T:    return current_state;
			case EOF_T:             return current_state;
            case OTHERERROR:        return current_state;
        }
        
    } while ( 1 );
    // Keep getting the next state until
    // found terminal state of the current lexeme
    
}
Example #9
0
void CodeEditor::update(RenderWindow *window) {
	mTopbar.setSize(window->getWidth() - 8, mTopbar.getSize().y);
	if (mLineHighlightType != LineHighlightType::LineNumberArea) {
		mLineHighlightRect.setSize(window->getWidth() - 8, mLineHighlightRect.getSize().y);
	} else {
		mLineHighlightRect.setSize(mLineNumberAreaWidth, mLineHighlightRect.getSize().y);
	}

	//TODO: move the cursor when the text is scrolled.
	//TODO: make the above optional
	//TODO: make it so that when the cursor is moved outside the view, the view is back on the cursor.

	uint32 cursorY = mText[mCurrentLine].getPosition().y + 2;

	//Check to see if we scrolled to far in either direction.
	if (mText.size() > 1) {
		if (mText[0].getPosition().y > mPos.y) {
			uint32 deltaY = (mText[0].getPosition().y - mPos.y);
			for (uint32 i = 0; i < mText.size(); ++i) {
				mText[i].setPosition(mText[i].getPosition().x, mText[i].getPosition().y - deltaY);
				mLineNumbers[i].setPosition(mLineNumbers[i].getPosition().x, mLineNumbers[i].getPosition().y - deltaY);
			}
		}

		uint32 max = mText.size() - 1;
		if (mText[max].getPosition().y < mPos.y) {
			uint32 deltaY = (mPos.y - mText[max].getPosition().y);
			for (uint32 i = 0; i < mText.size(); ++i) {
				mText[i].setPosition(mText[i].getPosition().x, mText[i].getPosition().y + deltaY);
				mLineNumbers[i].setPosition(mLineNumbers[i].getPosition().x, mLineNumbers[i].getPosition().y + deltaY);
			}
		}

		cursorY = mText[mCurrentLine].getPosition().y + 2;

		if (mText[mCurrentLine].getPosition().y < mPos.y) {
			for (uint32 i = mCurrentLine; i < mText.size(); ++i) {
				if (mText[i].getPosition().y >(mPos.y - mFontSize)) {
					mCurrentLine = i;
					cursorY = mText[i].getPosition().y + 2;
					break;
				}
			}
		} else if (mText[mCurrentLine].getPosition().y > (mPos.y + mSize.y - (mFontSize * 2))) {
			for (int32 i = mCurrentLine; i >= 0; --i) {
				if (mText[i].getPosition().y < (mPos.y + mSize.y - (mFontSize * 2))) {
					mCurrentLine = i;
					cursorY = mText[i].getPosition().y + 2;
					break;
				}
			}
		}
	}

	if (mCursorType == CursorType::Underscore) {
		cursorY += Preferences::instance()->getFont()->getLineSpacing(mFontSize) - 2;
	}

	uint32 cursorX = 0;
	mUpperBound = 0;
	if (mLineIndex >= getLineLength(mCurrentLine)) {
		mUpperBound = getLineLength(mCurrentLine);
	} else {
		mUpperBound = mLineIndex;
	}

	for (int i = 0; i < mUpperBound; ++i) {
		uint32 c = getLine(mCurrentLine)[i];

		if (c == '\t') {
			cursorX += (getCharWidth(L'') * mTabWidth);
		} else {
			cursorX += getCharWidth(c);
		}
	}

	uint32 markX = 0;
	for (int i = 0; i < mMarkIndex; ++i) {
		uint32 c = getLine(mMarkLine)[i];

		if (c == '\t') {
			markX += (getCharWidth(L'') * mTabWidth);
		} else {
			markX += getCharWidth(c);
		}
	}

	uint32 markY = mText[mMarkLine].getPosition().y + 2;

	mCursorRect.setPosition(mPos.x + mLineNumberAreaWidth + cursorX /*offset*/, cursorY);
	mCurrentChar.setPosition(mCursorRect.getPosition().x, mCursorRect.getPosition().y - 2);
	mMarkRect.setPosition(mPos.x + mLineNumberAreaWidth + markX /*offset*/, markY);
	if (mLineHighlightType != LineHighlightType::CodeArea) {
		mLineHighlightRect.setPosition(mPos.x, cursorY);
	} else {
		mLineHighlightRect.setPosition(mPos.x + mLineNumberAreaWidth, cursorY);
	}

	if (mCursorType != CursorType::CursorLine) {
		mCursorRect.setWidth(getCharWidth(getCurrentChar()));
	}

	mMarkRect.setWidth(getCharWidth(getMarkChar()));

	if (!mFirstMarkSet) {
		setMark();
		mFirstMarkSet = true;
	}

	mCurrentChar.setString(getCurrentChar());

	bool useMilitaryTime = Preferences::instance()->useMilitaryTime();

	Clock clock(useMilitaryTime);

	int32 hour = clock.getCurrentHour();
	int32 minute = clock.getCurrentMinute();
	int32 second = clock.getCurrentSecond();

	String ampm = clock.isPm() ? "PM" : "AM";
	ampm = useMilitaryTime ? "" : ampm;

	String hourStr = String::number(hour);
	String minuteStr = String::number(minute);
	String secondStr = String::number(second);

	if (minuteStr.getLength() == 1) {
		minuteStr.prepend("0");
	}

	if (secondStr.getLength() == 1) {
		secondStr.prepend("0");
	}

	Date date = Date::currentDate();

	String time = Preferences::instance()->showClock() ? hourStr + ":" + minuteStr + ":" + secondStr + " " + ampm : "";
	String dateStr = date.getDayName() + " " + date.getMonthName() + " " + String::number(date.dayOfMonth()) + " " + String::number(date.getYear()) + " week of the year: " + String::number(date.weekNumber());

	if (mClock.getCurrentTimeInMilliseconds() >= (timeNow + 1000)) {
		timeNow = mClock.getCurrentTimeInMilliseconds();
		frameRate = frames;
		frames = 0;
	}
	
	uint32 p = (staticCastf(mCurrentLine + 1) / staticCastf(getLineCount())) * 100;
	mTopBarText.setString(mFilename + "\t" + String::number(p) + "% " + String::number(mCurrentLine + 1) + ":u" + String::number(mUpperBound) +
		", i" + String::number(mLineIndex) + "\t" + dateStr + " " + time + "\tfps: " + String::number(frameRate));

	//Draw/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	if (mShowLineNumbers) {
		window->draw(mLineNumberArea);
	}

	if (mShowLineHighlight) {
		window->draw(mLineHighlightRect);
	}

	for (uint32 i = 0; i < mText.size(); ++i) {
		if ((mText[i].getPosition().y < (mPos.y - mFontSize)) || (mText[i].getPosition().y >= mPos.y + mSize.y)) {
			continue;
		}

		if (mShowLineHighlight && mLineHighlightType != LineHighlightType::LineNumberArea) {
			if (i == mCurrentLine) {
				mText[i].setColor(mLineHighlightTextColor);
			}

			if (i != mCurrentLine && mText[i].getColor() != mTextColor) {
				mText[i].setColor(mTextColor);
			}
		}

		if (mShowLineNumbers) {
			window->draw(mLineNumbers[i]);
		}

		window->draw(mText[i]);
	}
	
	if (mClock.getCurrentTimeInMilliseconds() >= (mLastBlinkTime + 500)) {
		mLastBlinkTime = mClock.getCurrentTimeInMilliseconds();
		mShowCursor = !mShowCursor;
	}

	if (!mBlinkCursor) {
		mShowCursor = true;
	}

	if (mShowCursor) {
		window->draw(mCursorRect);
	}

	if (mShowMark) {
		window->draw(mMarkRect);
	}

	String str = mCurrentChar.getString();
	if (mShowCursor && mCursorType == CursorType::Block && !str.isEmpty() && str != "\r") {
		window->draw(mCurrentChar);
	}

	mTopbar.setFillColor(Preferences::instance()->getTheme().barColor);
	window->draw(mTopbar);
	window->draw(mTopBarText);

	++frames;
}