VariableExpression: Restrict CharClass.Mixed to middle of identifiers
This commit is contained in:
@@ -334,6 +334,15 @@ namespace OpenRA.Support
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TokenType VariableOrKeyword(string expression, int start, ref int i)
|
||||||
|
{
|
||||||
|
if (CharClassOf(expression[i - 1]) == CharClass.Mixed)
|
||||||
|
throw new InvalidDataException("Invalid identifier end character at index {0} for `{1}`".F(
|
||||||
|
i - 1, expression.Substring(start, i - start)));
|
||||||
|
|
||||||
|
return VariableOrKeyword(expression, start, i - start);
|
||||||
|
}
|
||||||
|
|
||||||
static TokenType VariableOrKeyword(string expression, int start, int length)
|
static TokenType VariableOrKeyword(string expression, int start, int length)
|
||||||
{
|
{
|
||||||
var i = start;
|
var i = start;
|
||||||
@@ -464,10 +473,10 @@ namespace OpenRA.Support
|
|||||||
{
|
{
|
||||||
cc = CharClassOf(expression[i]);
|
cc = CharClassOf(expression[i]);
|
||||||
if (cc == CharClass.Whitespace || cc == CharClass.Operator)
|
if (cc == CharClass.Whitespace || cc == CharClass.Operator)
|
||||||
return VariableOrKeyword(expression, start, i - start);
|
return VariableOrKeyword(expression, start, ref i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return VariableOrKeyword(expression, start, i - start);
|
return VariableOrKeyword(expression, start, ref i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Token GetNext(string expression, ref int i, TokenType lastType = TokenType.Invalid)
|
public static Token GetNext(string expression, ref int i, TokenType lastType = TokenType.Invalid)
|
||||||
|
|||||||
@@ -351,13 +351,24 @@ namespace OpenRA.Test
|
|||||||
public void TestParseHyphenErrors()
|
public void TestParseHyphenErrors()
|
||||||
{
|
{
|
||||||
AssertParseFailure("-", "Missing value or sub-expression at end for `-` operator");
|
AssertParseFailure("-", "Missing value or sub-expression at end for `-` operator");
|
||||||
AssertParseFailure("t- 1", "Missing binary operation before `1` at index 3");
|
|
||||||
AssertParseFailure("t -1", "Missing binary operation before `-1` at index 2");
|
|
||||||
AssertParseFailure("-1-1", "Missing binary operation before `-1` at index 2");
|
AssertParseFailure("-1-1", "Missing binary operation before `-1` at index 2");
|
||||||
AssertParseFailure("5-1", "Missing binary operation before `-1` at index 1");
|
AssertParseFailure("5-1", "Missing binary operation before `-1` at index 1");
|
||||||
AssertParseFailure("6 -3", "Missing binary operation before `-3` at index 2");
|
AssertParseFailure("6 -3", "Missing binary operation before `-3` at index 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(TestName = "Test mixed charaters at end of identifier parser errors")]
|
||||||
|
public void TestParseMixedEndErrors()
|
||||||
|
{
|
||||||
|
AssertParseFailure("t- 1", "Invalid identifier end character at index 1 for `t-`");
|
||||||
|
AssertParseFailure("t-", "Invalid identifier end character at index 1 for `t-`");
|
||||||
|
AssertParseFailure("t. 1", "Invalid identifier end character at index 1 for `t.`");
|
||||||
|
AssertParseFailure("t.", "Invalid identifier end character at index 1 for `t.`");
|
||||||
|
AssertParseFailure("t@ 1", "Invalid identifier end character at index 1 for `t@`");
|
||||||
|
AssertParseFailure("t@", "Invalid identifier end character at index 1 for `t@`");
|
||||||
|
AssertParseFailure("t$ 1", "Invalid identifier end character at index 1 for `t$`");
|
||||||
|
AssertParseFailure("t$", "Invalid identifier end character at index 1 for `t$`");
|
||||||
|
}
|
||||||
|
|
||||||
[TestCase(TestName = "Undefined symbols are treated as `false` (0) values")]
|
[TestCase(TestName = "Undefined symbols are treated as `false` (0) values")]
|
||||||
public void TestUndefinedSymbols()
|
public void TestUndefinedSymbols()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user