Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
38   129   23   7,6
30   71   0,61   5
5     4,6  
1    
 
  SimpleMathParser       Line # 32 38 23 93,2% 0.9315069
 
  (30)
 
1    /* $Id: SimpleMathParser.java,v 1.1 2008/07/26 07:58:30 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.bo.parser;
19   
20    import java.util.ArrayList;
21    import java.util.List;
22   
23    import org.qedeq.base.io.TextInput;
24   
25    /**
26    * Parse term or formula data into {@link org.qedeq.kernel.bo.parser.Term}s.
27    * This parser uses simple ASCII text operators.
28    *
29    * @version $Revision: 1.1 $
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 toggle 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 toggle protected final String readToken() {
65  1537 int lines = 0;
66  2575 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  2172 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 toggle protected final Operator getOperator(final String token) {
99  1840 Operator result = null;
100  1840 if (token == null) {
101  0 return result;
102    }
103  22964 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 toggle 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  3840 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 toggle protected boolean eot(final String token) {
126  320 return token == null || token.trim().length() == 0;
127    }
128   
129    }