Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 131   Methods: 5
NCLOC: 73   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SimpleMathParser.java 90% 95% 100% 93,3%
coverage coverage
 1    /* $Id: SimpleMathParser.java,v 1.3 2007/05/10 00:37:51 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.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.3 $
 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  1305 protected final String readToken() {
 65  1305 int lines = 0;
 66  1305 while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
 67  872 if ('\n' == (char) getChar()) {
 68  198 lines++;
 69    }
 70  872 readChar();
 71    }
 72  1305 if (lines > 1) {
 73  13 return "";
 74    }
 75  1292 if (eof()) {
 76  132 return null;
 77    }
 78  1160 if (SEPARATORS.indexOf(getChar()) >= 0) {
 79  237 System.out.println("Read token: " + (char) getChar());
 80  237 return "" + (char) readChar();
 81    }
 82  923 final StringBuffer token = new StringBuffer();
 83  923 while (!eof() && !Character.isWhitespace((char) getChar())
 84    && SEPARATORS.indexOf(getChar()) < 0) {
 85  1059 token.append((char) readChar());
 86  1059 if (null != getOperator(token.toString())) {
 87  252 if (getChar() >= 0) {
 88  252 final char c = (char) getChar();
 89  252 if (null != getOperator(token.toString() + c)) {
 90  30 continue;
 91    }
 92    }
 93  222 break;
 94    }
 95    }
 96  923 System.out.println("Read token: " + token.toString());
 97  923 return token.toString();
 98    }
 99   
 100  1632 protected final Operator getOperator(final String token) {
 101  1632 Operator result = null;
 102  1632 if (token == null) {
 103  0 return result;
 104    }
 105  1632 for (int i = 0; i < getOperators().size(); i++) {
 106  18684 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 107  472 result = (Operator) getOperators().get(i);
 108  472 break;
 109    }
 110    }
 111  1632 return result;
 112    }
 113   
 114  256 protected final List getOperators(final String token) {
 115  256 final List result = new ArrayList();
 116  256 if (token == null) {
 117  0 return result;
 118    }
 119  256 for (int i = 0; i < getOperators().size(); i++) {
 120  3584 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
 121  32 result.add(getOperators().get(i));
 122    }
 123    }
 124  256 return result;
 125    }
 126   
 127  320 protected boolean eot(final String token) {
 128  320 return token == null || token.trim().length() == 0;
 129    }
 130   
 131    }