parseArgSize method
Implementation
Measurement? parseArgSize({required bool optional}) {
currArgParsingContext.newArgument(optional: optional);
final i = currArgParsingContext.currArgNum;
final consumeSpaces =
(i > 0 && !optional) || (i == 0 && !optional && this.mode == Mode.math);
if (consumeSpaces) {
this.consumeSpaces();
}
// final res = this.parseSizeGroup(optional: optional);
Token? res;
if (!optional && this.fetch().text != '{') {
res = _parseRegexGroup(_parseSizeRegex, 'size');
} else {
res = _parseStringGroup('size', optional: optional);
}
if (res == null) {
_assertOptionalBeforeReturn(null, optional: optional);
return null;
}
if (!optional && res.text.isEmpty) {
// res.text = '0pt';
// This means default width for genfrac, and 0pt for above
return null;
}
final match = _parseMeasurementRegex.firstMatch(res.text);
if (match == null) {
throw ParseException("Invalid size: '${res.text}'", res);
}
final unit = match[3]!.parseUnit();
if (unit == null) {
throw ParseException("Invalid unit: '${match[3]}'", res);
}
final size =
Measurement(value: double.parse(match[1]! + match[2]!), unit: unit);
return size;
}