Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 126   Methods: 5
NCLOC: 80   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.4 2007/04/12 23:50:10 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.4 $
 36    * @author Michael Meyling
 37    */
 38    public final class AsciiMathParser extends MathParser {
 39   
 40    /** Separators for tokens. */
 41    private static final String SEPARATORS = "()[],{}";
 42   
 43    /**
 44    * Constructor.
 45    *
 46    * @param input Parse this input.
 47    * @param operators Operator definitions.
 48    */
 49  51 public AsciiMathParser(final TextInput input, final List operators) {
 50  51 super(new MementoTextInput(input), operators);
 51    }
 52   
 53  5989 protected final String readToken() {
 54  5989 final String method = "readToken()";
 55  5989 int lines = 0;
 56  5989 while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
 57  2444 if ('\n' == (char) getChar()) {
 58  309 lines++;
 59    }
 60  2444 readChar();
 61    }
 62  5989 if (lines > 1) {
 63  4 return "";
 64    }
 65  5985 if (eof()) {
 66  232 return null;
 67    }
 68  5753 if (SEPARATORS.indexOf(getChar()) >= 0) {
 69  2179 Trace.param(this, method, "Read token", "" + (char) getChar());
 70  2179 return "" + (char) readChar();
 71    }
 72  3574 final StringBuffer token = new StringBuffer();
 73  3574 String operator = null;
 74  3574 markPosition();
 75  3574 while (!eof() && !Character.isWhitespace((char) getChar())
 76    && SEPARATORS.indexOf(getChar()) < 0) {
 77  4569 token.append((char) readChar());
 78  4569 if (null != getOperator(token.toString())) {
 79  1137 operator = token.toString();
 80  1137 clearMark();
 81  1137 markPosition();
 82    }
 83    }
 84  3574 if (operator != null) {
 85  1135 rewindPosition();
 86  1135 token.setLength(0);
 87  1135 token.append(operator);
 88    } else {
 89  2439 clearMark();
 90    }
 91  3574 Trace.param(this, method, "Read token", token);
 92  3574 return token.toString();
 93    }
 94   
 95  6139 protected final Operator getOperator(final String token) {
 96  6139 Operator result = null;
 97  6139 if (token == null) {
 98  0 return result;
 99    }
 100  6139 for (int i = 0; i < getOperators().size(); i++) {
 101  81154 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 102  1814 result = (Operator) getOperators().get(i);
 103  1814 break;
 104    }
 105    }
 106  6139 return result;
 107    }
 108   
 109  1268 protected final List getOperators(final String token) {
 110  1268 final List result = new ArrayList();
 111  1268 if (token == null) {
 112  0 return result;
 113    }
 114  1268 for (int i = 0; i < getOperators().size(); i++) {
 115  20288 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 116  310 result.add(getOperators().get(i));
 117    }
 118    }
 119  1268 return result;
 120    }
 121   
 122  1371 protected boolean eot(final String token) {
 123  1371 return token == null || token.trim().length() == 0;
 124    }
 125   
 126    }