/** * Returns whether repeated indices of the same variance are allowed to be parsed * * @return whether repeated indices of the same variance are allowed to be parsed */ public boolean getParserAllowsSameVariance() { return parseManager.getParser().isAllowSameVariance(); }
@Override public final ParseTokenSimpleTensor parseToken(String expression, Parser parser) { expression = expression.replaceAll("\\{[\\s]*\\}", ""); int indicesBegin = expression.indexOf('_'), i = expression.indexOf('^'); if (indicesBegin < 0 && i >= 0) indicesBegin = i; if (indicesBegin >= 0 && i >= 0) indicesBegin = Math.min(indicesBegin, i); if (indicesBegin < 0) indicesBegin = expression.length(); String name = expression.substring(0, indicesBegin); if (name.isEmpty()) throw new ParserException("Simple tensor with empty name."); SimpleIndices indices; if (parser.isAllowSameVariance()) indices = ParserIndices.parseSimpleIgnoringVariance(expression.substring(indicesBegin)); else indices = ParserIndices.parseSimple(expression.substring(indicesBegin)); return new ParseTokenSimpleTensor(indices, name); }
@Override public ParseToken parseToken(String expression, Parser parser) { ParseToken node = super.parseToken(expression, parser); if (node == null || !parser.isAllowSameVariance()) return node; TIntHashSet indices = new TIntHashSet(); for (ParseToken c : node.content) { Indices free = c.getIndices().getFree(); for (int i = 0; i < free.size(); i++) { int ind = free.get(i); if (indices.contains(ind)) revertIndex(c, ind); else indices.add(ind); } } return node; }