📄 token.cs
字号:
currentToken += c;
parseState = ParseState.Parse_State_Quote;
}
catch (Exception err)
{
lastErrorMessage = "Error in GetTokens() in Operand Quote Handling: " + err.Message;
return;
}
#endregion
}
else if (c == ' ')
{
#region Space Handling
try
{
// we are looking for an operand and we found a space. We are not currently looking for a closing quote.
// Assume that the space indicates that the operand is completed and we now need to look for an operator
tokenCreated = CreateTokenItem(currentToken, false, false, out tempParseState, out isError, out lastErrorMessage);
if (isError) return;
if (tokenCreated == true)
{
// set the next parse state
parseState = tempParseState;
// reset the token
currentToken = "";
}
}
catch (Exception err)
{
lastErrorMessage = "Error in GetTokens() in Operand Space Handling: " + err.Message;
return;
}
#endregion
}
else if (c == '(')
{
#region Parenthesis Handling
// increment the parenthesis count
parenthesisMatch++;
// create the token
tokenCreated = CreateTokenItem(currentToken, false, false, out tempParseState, out isError, out lastErrorMessage);
if (isError == true) return;
// add the open parenthesis
tokenItems.Add(new TokenItem("(", TokenType.Token_Open_Parenthesis, false));
// clear the current token
currentToken = "";
// after a parenthesis we need an operand
parseState = ParseState.Parse_State_Operand;
#endregion
}
else if (c == ')')
{
#region Parenthesis Handling
// decrement the parenthesis count
parenthesisMatch--;
// create the token
tokenCreated = CreateTokenItem(currentToken, false, false, out tempParseState, out isError, out lastErrorMessage);
if (isError == true) return;
// add the close parenthesis
tokenItems.Add(new TokenItem(")", TokenType.Token_Close_Parenthesis, false));
// clear the current token
currentToken = "";
// after a parenthesis we need an operator
parseState = ParseState.Parse_State_Operator;
#endregion
}
else if (c == '[')
{
#region Operand Function Handling
// Check that an operand function is starting
// increment the square parenthesis count
squareMatch++;
// clean the token
currentToken = currentToken.Trim();
if (Support.DataTypeCheck.IsOperandFunction(currentToken) == true)
{
// we found the start of an operand function
// it's possible that we have operand functions within operand functions
operandFunctionDepth++;
// add the token item
currentToken += c;
tokenItems.Add(new TokenItem(currentToken, TokenType.Token_Operand_Function_Start, false));
// Indicate that we are now in a operand function
parseState = ParseState.Parse_State_OperandFunction;
// within the operand function, we are looking for an operand
opFuncParseState = ParseState.Parse_State_Operand;
// reset the token
currentToken = "";
}
else
{
// we found a square bracket but we don't have an operand function
lastErrorMessage = "Error in Rule Syntax: Found an open square parenthesis without an operand function";
return;
}
#endregion
}
else if (c == ']')
{
#region Operand Function Handling
// we should never be looking for an operand and find a ]
squareMatch--;
lastErrorMessage = "Error in Rule Syntax: Found an ] while looking for an operand.";
return;
#endregion
}
else if (c == ',')
{
#region Command Handling
// we should never be looking for an operand and find a ,
lastErrorMessage = "Error in Rule Syntax: Found a , (comma) while looking for an operand.";
return;
#endregion
}
else if (c == '-')
{
#region Negative Operands
if (String.IsNullOrEmpty(currentToken.Trim()) == true)
{
// we found a negative sign
currentToken += c;
}
else
{
// try and create the new token
currentToken += c;
tokenCreated = CreateTokenItem(currentToken, true, false, out tempParseState, out isError, out lastErrorMessage);
if (isError == true) return;
if (tokenCreated == true)
{
// the new tokens were created
// reset the current token
currentToken = "";
// set the next parse state
parseState = tempParseState;
}
}
#endregion
}
else
{
#region Other Handling
// try and create the new token
currentToken += c;
tokenCreated = CreateTokenItem(currentToken, true, false, out tempParseState, out isError, out lastErrorMessage);
if (isError == true) return;
if (tokenCreated == true)
{
// the new tokens were created
// reset the current token
currentToken = "";
// set the next parse state
parseState = tempParseState;
}
#endregion
}
#endregion
break;
case ParseState.Parse_State_OperandFunction:
#region Parse_State_OperandFunction
switch (opFuncParseState)
{
case ParseState.Parse_State_Operand:
#region Parse_State_OperandFunction, Parse_State_Operand
if (c == '"')
{
#region Quote Handling
// we have a quote in the operand function...This is probably the start of a string operand
quoteMatch++;
currentToken += c;
opFuncParseState = ParseState.Parse_State_Quote;
#endregion
}
else if (c == ' ')
{
#region Space Handling
// we are looking for an operand and we found a space. We are not currently looking for a closing quote.
// Assume that the space indicates that the operand is completed and we now need to look for an operator
tokenCreated = CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
if (tokenCreated == true)
{
// set the next parse state
opFuncParseState = tempParseState;
// reset the token
currentToken = "";
}
#endregion
}
else if (c == '(')
{
#region Parenthesis Handling
// increment the parenthesis count
parenthesisMatch++;
// create the token
CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
if (isError == true) return;
// add the open parenthesis
tokenItems.Add(new TokenItem("(", TokenType.Token_Open_Parenthesis, true));
// clear the current token
currentToken = "";
// after a parenthesis we need an operand
opFuncParseState = ParseState.Parse_State_Operand;
#endregion
}
else if (c == ')')
{
#region Parenthesis Handling
// decrement the parenthesis count
parenthesisMatch--;
// create the token
CreateTokenItem(currentToken, false, true, out tempParseState, out isError, out lastErrorMessage);
if (isError == true) return;
// add the close parenthesis
tokenItems.Add(new TokenItem(")", TokenType.Token_Close_Parenthesis, true));
// clear the current token
currentToken = "";
// after a parenthesis we need an operator
opFuncParseState = ParseState.Parse_State_Operator;
#endregion
}
else if (c == '[')
{
#region Operand Function Handling
// Check that an operand function is starting
// increment the square parenthesis count
squareMatch++;
// clean the token
currentToken = currentToken.Trim();
if (Support.DataTypeCheck.IsOperandFunction(currentToken) == true)
{
// we found the start of an operand function
// it's possible that we have operand functions within operand functions
operandFunctionDepth++;
// add the token item
currentToken += c;
tokenItems.Add(new TokenItem(currentToken, TokenType.Token_Operand_Function_Start, true));
// within the operand function, we are looking for an operand
opFuncParseState = ParseState.Parse_State_Operand;
// reset the token
currentToken = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -