Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
38   122   23   7.6
30   70   0.61   5
5     4.6  
1    
 
  SimpleMathParser       Line # 28 38 23 93.2% 0.9315069
 
No Tests
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.parser;
17   
18    import java.util.ArrayList;
19    import java.util.List;
20   
21    /**
22    * Parse term or formula data into {@link org.qedeq.kernel.bo.parser.Term}s.
23    * This parser uses simple ASCII text operators.
24    *
25    * @version $Revision: 1.1 $
26    * @author Michael Meyling
27    */
 
28    public class SimpleMathParser extends MathParser {
29   
30    /** Characters that are always tokens itself. */
31    private static final String SEPARATORS = "()[],{}";
32   
33    /**
34    * Constructor.
35    */
 
36  30 toggle public SimpleMathParser() {
37  30 super();
38    /*
39    operators.add(new Operator("~", "NOT", 110, 1, 1, 1));
40    operators.add(new Operator("-", "NOT", 110, 1, 1, 1));
41    operators.add(new Operator("&", "AND", 100, 0, 2));
42    operators.add(new Operator("|", "OR", 90, 0, 2));
43    // operators.put("v", new Operator("v", "OR", 90, 0, 2));
44    operators.add(new Operator("->", "IMPL", 80, 0, 2, 2));
45    operators.add(new Operator("=>", "IMPL", 80, 0, 2, 2));
46    operators.add(new Operator("<->", "EQUI", 80, 0, 2));
47    operators.add(new Operator("<=>", "EQUI", 80, 0, 2));
48    operators.add(new Operator("all", "ALL", 40, 1, 2, 3));
49    operators.add(new Operator("exists", "EXISTS", 40, 1, 2, 3));
50    operators.add(new Operator("in", "IN", 200, 0, 2, 2));
51    operators.add(new Operator("=", "EQUAL", 200, 0, 2));
52    operators.add(new Operator("{", ",", "}", "SET", 200, 0));
53    operators.add(new Operator("{", ":", "}", "SETPROP", 200, 2, 2));
54    */
55    }
56   
 
57  1537 toggle protected final String readToken() {
58  1537 int lines = 0;
59  2575 while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
60  1038 if ('\n' == (char) getChar()) {
61  218 lines++;
62    }
63  1038 readChar();
64    }
65  1537 if (lines > 1) {
66  13 return "";
67    }
68  1524 if (eof()) {
69  132 return null;
70    }
71  1392 if (SEPARATORS.indexOf(getChar()) >= 0) {
72  265 return "" + (char) readChar();
73    }
74  1127 final StringBuffer token = new StringBuffer();
75  2172 while (!eof() && !Character.isWhitespace((char) getChar())
76    && SEPARATORS.indexOf(getChar()) < 0) {
77  1267 token.append((char) readChar());
78  1267 if (null != getOperator(token.toString())) {
79  252 if (getChar() >= 0) {
80  252 final char c = (char) getChar();
81  252 if (null != getOperator(token.toString() + c)) {
82  30 continue;
83    }
84    }
85  222 break;
86    }
87    }
88  1127 return token.toString();
89    }
90   
 
91  1840 toggle protected final Operator getOperator(final String token) {
92  1840 Operator result = null;
93  1840 if (token == null) {
94  0 return result;
95    }
96  22964 for (int i = 0; i < getOperators().size(); i++) {
97  21596 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
98  472 result = (Operator) getOperators().get(i);
99  472 break;
100    }
101    }
102  1840 return result;
103    }
104   
 
105  256 toggle protected final List getOperators(final String token) {
106  256 final List result = new ArrayList();
107  256 if (token == null) {
108  0 return result;
109    }
110  3840 for (int i = 0; i < getOperators().size(); i++) {
111  3584 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
112  32 result.add(getOperators().get(i));
113    }
114    }
115  256 return result;
116    }
117   
 
118  320 toggle protected boolean eot(final String token) {
119  320 return token == null || token.trim().length() == 0;
120    }
121   
122    }