/** * Parses string expression and returns indices. * * @param expression string representation of indices * @return integer indices * @throws IllegalArgumentException if string does not represent correct indices object. */ public static SimpleIndices parseSimple(String expression) { return IndicesFactory.createSimple(null, parse(expression)); }
@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); }
throw new ParserException(expression); a = parser.parse(split[0]); aIndices = ParserIndices.parseSimple(split[1]);
else if (c == '_' && level == 0) { if (endIndex != 0) parse(expression.substring(beginIndex + 1, endIndex), indices, state); state = 0; beginIndex = endIndex; throw new BracketsError(); if (endIndex != 0) parse(expression.substring(beginIndex + 1, endIndex), indices, state); state = 0x80000000; beginIndex = endIndex; throw new BracketsError(); if (beginIndex != endIndex) parse(expression.substring(beginIndex + 1, endIndex), indices, state); return indices.toArray();
/** * Parses string expression and returns indices allowing repeated indices with same states (like T_ii): appropriate * raising or lowering will be performed automatically. * * @param expression string representation of indices * @return integer indices * @throws IllegalArgumentException if string does not represent correct indices object. */ public static SimpleIndices parseSimpleIgnoringVariance(String expression) { int[] indices = parse(expression); out: for (int i = 0; i < indices.length - 1; ++i) for (int j = i + 1; j < indices.length; ++j) if (indices[i] == indices[j]) { indices[i] = IndicesUtils.inverseIndexState(indices[i]); continue out; } return IndicesFactory.createSimple(null, indices); }