Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mrz 27 2008 21:46:26 CET
file stats: LOC: 129   Methods: 5
NCLOC: 71   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SimpleMathParser.java 90% 94,7% 100% 93,2%
coverage coverage
 1    /* $Id: SimpleMathParser.java,v 1.4 2008/03/27 05:16:27 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2008, 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.utility.TextInput;
 24   
 25    /**
 26    * Parse term or formula data into {@link org.qedeq.kernel.parser.Term}s.
 27    * This parser uses simple ASCII text operators.
 28    *
 29    * @version $Revision: 1.4 $
 30    * @author Michael Meyling
 31    */
 32    public class SimpleMathParser extends MathParser {
 33   
 34    /** Characters that are always tokens itself. */
 35    private static final String SEPARATORS = "()[],{}";
 36   
 37    /**
 38    * Constructor.
 39    *
 40    * @param input Parse this input.
 41    * @param operators List of operators.
 42    */
 43  30 public SimpleMathParser(final TextInput input, final List operators) {
 44  30 super(new MementoTextInput(input), operators);
 45    /*
 46    operators.add(new Operator("~", "NOT", 110, 1, 1, 1));
 47    operators.add(new Operator("-", "NOT", 110, 1, 1, 1));
 48    operators.add(new Operator("&", "AND", 100, 0, 2));
 49    operators.add(new Operator("|", "OR", 90, 0, 2));
 50    // operators.put("v", new Operator("v", "OR", 90, 0, 2));
 51    operators.add(new Operator("->", "IMPL", 80, 0, 2, 2));
 52    operators.add(new Operator("=>", "IMPL", 80, 0, 2, 2));
 53    operators.add(new Operator("<->", "EQUI", 80, 0, 2));
 54    operators.add(new Operator("<=>", "EQUI", 80, 0, 2));
 55    operators.add(new Operator("all", "ALL", 40, 1, 2, 3));
 56    operators.add(new Operator("exists", "EXISTS", 40, 1, 2, 3));
 57    operators.add(new Operator("in", "IN", 200, 0, 2, 2));
 58    operators.add(new Operator("=", "EQUAL", 200, 0, 2));
 59    operators.add(new Operator("{", ",", "}", "SET", 200, 0));
 60    operators.add(new Operator("{", ":", "}", "SETPROP", 200, 2, 2));
 61    */
 62    }
 63   
 64  1537 protected final String readToken() {
 65  1537 int lines = 0;
 66  1537 while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
 67  1038 if ('\n' == (char) getChar()) {
 68  218 lines++;
 69    }
 70  1038 readChar();
 71    }
 72  1537 if (lines > 1) {
 73  13 return "";
 74    }
 75  1524 if (eof()) {
 76  132 return null;
 77    }
 78  1392 if (SEPARATORS.indexOf(getChar()) >= 0) {
 79  265 return "" + (char) readChar();
 80    }
 81  1127 final StringBuffer token = new StringBuffer();
 82  1127 while (!eof() && !Character.isWhitespace((char) getChar())
 83    && SEPARATORS.indexOf(getChar()) < 0) {
 84  1267 token.append((char) readChar());
 85  1267 if (null != getOperator(token.toString())) {
 86  252 if (getChar() >= 0) {
 87  252 final char c = (char) getChar();
 88  252 if (null != getOperator(token.toString() + c)) {
 89  30 continue;
 90    }
 91    }
 92  222 break;
 93    }
 94    }
 95  1127 return token.toString();
 96    }
 97   
 98  1840 protected final Operator getOperator(final String token) {
 99  1840 Operator result = null;
 100  1840 if (token == null) {
 101  0 return result;
 102    }
 103  1840 for (int i = 0; i < getOperators().size(); i++) {
 104  21596 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 105  472 result = (Operator) getOperators().get(i);
 106  472 break;
 107    }
 108    }
 109  1840 return result;
 110    }
 111   
 112  256 protected final List getOperators(final String token) {
 113  256 final List result = new ArrayList();
 114  256 if (token == null) {
 115  0 return result;
 116    }
 117  256 for (int i = 0; i < getOperators().size(); i++) {
 118  3584 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 119  32 result.add(getOperators().get(i));
 120    }
 121    }
 122  256 return result;
 123    }
 124   
 125  320 protected boolean eot(final String token) {
 126  320 return token == null || token.trim().length() == 0;
 127    }
 128   
 129    }