parseTensorIndicesGroup static method
Parses a tensor indices list from a braced token stream.
Implementation
static List<(bool, LatexNode)> parseTensorIndicesGroup(
LatexParserContext ctx,
LatexTokenStream stream,
) {
if (stream.peek() is! LeftBraceToken) {
return [];
}
stream.advance(); // consume '{'
final indices = <(bool, LatexNode)>[];
while (!stream.isEOF() && stream.peek() is! RightBraceToken) {
final token = stream.peek();
if (token is SuperscriptToken) {
stream.advance();
final content = ctx.parseFactor();
if (content != null) {
indices.add((true, content));
}
} else if (token is SubscriptToken) {
stream.advance();
final content = ctx.parseFactor();
if (content != null) {
indices.add((false, content));
}
} else if (token is WhitespaceToken) {
stream.advance();
} else {
stream.advance();
}
}
if (!stream.isEOF()) {
stream.advance(); // consume '}'
}
return indices;
}