Пример #1
0
/// <summary>Reads a unary expression, sub-expression, or literal</summary>
/// <param name="pos">Position of first token of expression</param>
/// <returns>Expression tree</returns>
/// <exception cref="Logic::AlgorithmException">Attempted to read incorrect type of Token</exception>
/// <exception cref="Logic::ExpressionParserException">Syntax error</exception>
/// <remarks>Advances the iterator to beyond the end of the expression</remarks>
ExpressionParser::ExpressionTree  ExpressionParser::ReadUnaryExpression(TokenIterator& pos)
{
    // Rule: Unary = (! / - / ~)? Value

    // Match: Operator
    if (MatchOperator(pos, MAX_PRECEDENCE))
    {
        // Read: operator  (may throw)
        const ScriptToken& op = ReadOperator(pos);

        // Manually convert binary-substract to unary-minus
        ScriptToken unary = (op.Text != L"-" ? op : ScriptToken(TokenType::UnaryOp, op.Start, op.End, op.Text));

        // Read: Value  (may throw)
        return ExpressionTree(new UnaryExpression(unary, ReadValue(pos)));
    }

    // Read: Value  (may throw)
    return ReadValue(pos);
}
Пример #2
0
void CScriptDlg::OnModify()
{
	CScintillaWnd* pSelected = GetSelectedScintilla();

	long pos = pSelected->GetCurrentPosition()-1;
	if(pos < 0)
		pos = 0;

	CString text = pSelected->GetText();

	// Okay our goal is to work out what the user is typing. 
	// for example:
	// myobject.function

	// so we need to get all the stuff on the left and right

	int start = 0;

	m_BeforeDotText = "";
	m_AfterDotText = "";
	m_OperatorText = "";
	m_Dot = false;
/*
	CString selected = pSelected->GetSelectedText();
	if(selected != "")
	{
		selected.Replace(".","");
		m_BeforeDotText = selected;
		UpdateList();
		return;
	}
*/
	// First case: we have typed something like mykeyword.whatever.
	if(ScriptToken(text.GetAt(pos)))
	{
		for(int c = pos; c >= 0; c--) // loop backwards
		{
			if(!ScriptToken(text.GetAt(c)))
			{
				start = c+1;
				c = -1;
			}
		}
		int length = text.GetLength();
		int end = length;
		for(int c = pos+1; c < length; c++) // loop forwards
		{
			if(!ScriptToken(text.GetAt(c)) || text.GetAt(c) == '.')
			{
				end = c;
				c = length;
			}
		}	

		CString token = text.Mid(start, end-start);
		int dot = token.Find('.');
		CString First = token;
		CString Second = "";

		if(dot != -1)
		{
			Second = First.Mid(dot+1, length - dot-1);
			First = First.Left(dot);
			m_Dot = true;
		}

		m_BeforeDotText = First;
		m_AfterDotText = Second;
	}
	else if(KeywordToken(text.GetAt(pos)))// we have typed something else, such as a symbol like ==
	{
		for(int c = pos-1; c >= 0; c--) // loop backwards
		{
			if(!KeywordToken(text.GetAt(c)))
			{
				start = c+1;
				c = -1;
			}
		}
		int length = text.GetLength();
		int end = length;
		for(int c = pos; c < length; c++) // loop forwards
		{
			if(!KeywordToken(text.GetAt(c)))
			{
				end = c-1;
				c = length;
			}
		}	
		m_OperatorText = text.Mid(start, end-start);
	}

	UpdateList();

}