Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 129   Methods: 5
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AsciiMathParser.java 92,9% 95,7% 100% 94,9%
coverage coverage
 1    /* $Id: AsciiMathParser.java,v 1.5 2008/01/26 12:39:09 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.parser;
 19   
 20    import java.util.ArrayList;
 21    import java.util.List;
 22   
 23    import org.qedeq.kernel.trace.Trace;
 24    import org.qedeq.kernel.utility.TextInput;
 25   
 26    /*
 27    * TODO refactor
 28    *
 29    */
 30   
 31    /**
 32    * Parse term or formula data into {@link org.qedeq.kernel.parser.Term}s.
 33    * This parser uses simple ascii text operators.
 34    *
 35    * @version $Revision: 1.5 $
 36    * @author Michael Meyling
 37    */
 38    public final class AsciiMathParser extends MathParser {
 39   
 40    /** This class. */
 41    private static final Class CLASS = AsciiMathParser.class;
 42   
 43    /** Separators for tokens. */
 44    private static final String SEPARATORS = "()[],{}";
 45   
 46    /**
 47    * Constructor.
 48    *
 49    * @param input Parse this input.
 50    * @param operators Operator definitions.
 51    */
 52  51 public AsciiMathParser(final TextInput input, final List operators) {
 53  51 super(new MementoTextInput(input), operators);
 54    }
 55   
 56  6989 protected final String readToken() {
 57  6989 final String method = "readToken()";
 58  6989 int lines = 0;
 59  6989 while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
 60  2811 if ('\n' == (char) getChar()) {
 61  333 lines++;
 62    }
 63  2811 readChar();
 64    }
 65  6989 if (lines > 1) {
 66  4 return "";
 67    }
 68  6985 if (eof()) {
 69  232 return null;
 70    }
 71  6753 if (SEPARATORS.indexOf(getChar()) >= 0) {
 72  2485 Trace.param(CLASS, this, method, "Read token", "" + (char) getChar());
 73  2485 return "" + (char) readChar();
 74    }
 75  4268 final StringBuffer token = new StringBuffer();
 76  4268 String operator = null;
 77  4268 markPosition();
 78  4268 while (!eof() && !Character.isWhitespace((char) getChar())
 79    && SEPARATORS.indexOf(getChar()) < 0) {
 80  5263 token.append((char) readChar());
 81  5263 if (null != getOperator(token.toString())) {
 82  1137 operator = token.toString();
 83  1137 clearMark();
 84  1137 markPosition();
 85    }
 86    }
 87  4268 if (operator != null) {
 88  1135 rewindPosition();
 89  1135 token.setLength(0);
 90  1135 token.append(operator);
 91    } else {
 92  3133 clearMark();
 93    }
 94  4268 Trace.param(CLASS, this, method, "Read token", token);
 95  4268 return token.toString();
 96    }
 97   
 98  6833 protected final Operator getOperator(final String token) {
 99  6833 Operator result = null;
 100  6833 if (token == null) {
 101  0 return result;
 102    }
 103  6833 for (int i = 0; i < getOperators().size(); i++) {
 104  92258 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 105  1814 result = (Operator) getOperators().get(i);
 106  1814 break;
 107    }
 108    }
 109  6833 return result;
 110    }
 111   
 112  1268 protected final List getOperators(final String token) {
 113  1268 final List result = new ArrayList();
 114  1268 if (token == null) {
 115  0 return result;
 116    }
 117  1268 for (int i = 0; i < getOperators().size(); i++) {
 118  20288 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 119  310 result.add(getOperators().get(i));
 120    }
 121    }
 122  1268 return result;
 123    }
 124   
 125  1371 protected boolean eot(final String token) {
 126  1371 return token == null || token.trim().length() == 0;
 127    }
 128   
 129    }