Archived
1

Invalid Numbers Are Now a Syntax Error

Syntax Errors Now Include a Range
Syntax Errors Are Now Displayed in a Selectable List
This commit is contained in:
Kim Wittenburg
2014-11-29 00:19:52 +01:00
parent 4bc2fdead1
commit b6973dc24a
6 changed files with 62 additions and 43 deletions

View File

@@ -49,14 +49,15 @@
NSString *regexStringFormat = @"\\A(?:"
@"([\\*∙⋅])|"
@"([+-](?:\\s*[+-])*)|"
@"((?:\\d+(?:%@\\d+)?)|(?:%@\\d+))|"
@"((?:\\d+%@(?!\\d+))|(?:(?:\\d*%@){2,}\\d*)|%@)|" // Substitute with decimal separator 3 times
@"((?:\\d+(?:%@\\d+)?)|(?:%@\\d+))|" // Substitute with decimal separator 2 times
@"(sin|cos|tan|asin|acos|atan)|"
@"([A-Za-z])|"
@"(!)|"
@"(=)|"
@"(\\s+)"
@")";
NSString *regexString = [NSString stringWithFormat:regexStringFormat, decimalSeparator, decimalSeparator];
NSString *regexString = [NSString stringWithFormat:regexStringFormat, decimalSeparator, decimalSeparator, decimalSeparator, decimalSeparator, decimalSeparator];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString
options:0
error:NULL];
@@ -69,12 +70,13 @@
if (match) {
NSRange multiplicationSymbolRange = [match rangeAtIndex:1];
NSRange operatorRange = [match rangeAtIndex:2];
NSRange numberRange = [match rangeAtIndex:3];
NSRange elementaryFunctionRange = [match rangeAtIndex:4];
NSRange variableRange = [match rangeAtIndex:5];
NSRange factorialRange = [match rangeAtIndex:6];
NSRange equalsRange = [match rangeAtIndex:7];
NSRange whitespaceRange = [match rangeAtIndex:8];
NSRange deformedNumberRange = [match rangeAtIndex:3];
NSRange numberRange = [match rangeAtIndex:4];
NSRange elementaryFunctionRange = [match rangeAtIndex:5];
NSRange variableRange = [match rangeAtIndex:6];
NSRange factorialRange = [match rangeAtIndex:7];
NSRange equalsRange = [match rangeAtIndex:8];
NSRange whitespaceRange = [match rangeAtIndex:9];
if (MPRangeExists(multiplicationSymbolRange)) {
range = multiplicationSymbolRange;
@@ -82,6 +84,9 @@
} else if (MPRangeExists(operatorRange)) {
range = operatorRange;
tokenType = MPOperatorListToken;
} else if (MPRangeExists(deformedNumberRange)) {
range = deformedNumberRange;
tokenType = MPDeformedNumberToken;
} else if (MPRangeExists(numberRange)) {
range = numberRange;
tokenType = MPNumberToken;