1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.parser; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.qedeq.base.trace.Trace; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
@link |
30 |
|
|
31 |
|
|
32 |
|
@author |
33 |
|
|
|
|
| 94.9% |
Uncovered Elements: 4 (79) |
Complexity: 22 |
Complexity Density: 0.48 |
|
34 |
|
public final class AsciiMathParser extends MathParser { |
35 |
|
|
36 |
|
|
37 |
|
private static final Class CLASS = AsciiMathParser.class; |
38 |
|
|
39 |
|
|
40 |
|
private static final String SEPARATORS = "()[],{}"; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
58
|
public AsciiMathParser() {... |
46 |
58
|
super(); |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (45) |
Complexity: 12 |
Complexity Density: 0.41 |
|
49 |
7113
|
protected final String readToken() {... |
50 |
7113
|
final String method = "readToken()"; |
51 |
7113
|
int lines = 0; |
52 |
9968
|
while (getChar() != -1 && Character.isWhitespace((char) getChar())) { |
53 |
2855
|
if ('\n' == (char) getChar()) { |
54 |
333
|
lines++; |
55 |
|
} |
56 |
2855
|
readChar(); |
57 |
|
} |
58 |
7113
|
if (lines > 1) { |
59 |
4
|
return ""; |
60 |
|
} |
61 |
7109
|
if (eof()) { |
62 |
237
|
return null; |
63 |
|
} |
64 |
6872
|
if (SEPARATORS.indexOf(getChar()) >= 0) { |
65 |
2518
|
Trace.param(CLASS, this, method, "Read token", "" + (char) getChar()); |
66 |
2518
|
return "" + (char) readChar(); |
67 |
|
} |
68 |
4354
|
final StringBuffer token = new StringBuffer(); |
69 |
4354
|
String operator = null; |
70 |
4354
|
markPosition(); |
71 |
9738
|
while (!eof() && !Character.isWhitespace((char) getChar()) |
72 |
|
&& SEPARATORS.indexOf(getChar()) < 0) { |
73 |
5384
|
token.append((char) readChar()); |
74 |
5384
|
if (null != getOperator(token.toString())) { |
75 |
1147
|
operator = token.toString(); |
76 |
1147
|
clearMark(); |
77 |
1147
|
markPosition(); |
78 |
|
} |
79 |
|
} |
80 |
4354
|
if (operator != null) { |
81 |
1145
|
rewindPosition(); |
82 |
1145
|
token.setLength(0); |
83 |
1145
|
token.append(operator); |
84 |
|
} else { |
85 |
3209
|
clearMark(); |
86 |
|
} |
87 |
4354
|
Trace.param(CLASS, this, method, "Read token", token); |
88 |
4354
|
return token.toString(); |
89 |
|
} |
90 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
91 |
6967
|
protected final Operator getOperator(final String token) {... |
92 |
6967
|
Operator result = null; |
93 |
6967
|
if (token == null) { |
94 |
0
|
return result; |
95 |
|
} |
96 |
104616
|
for (int i = 0; i < getOperators().size(); i++) { |
97 |
99475
|
if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) { |
98 |
1826
|
result = (Operator) getOperators().get(i); |
99 |
1826
|
break; |
100 |
|
} |
101 |
|
} |
102 |
6967
|
return result; |
103 |
|
} |
104 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
105 |
1291
|
protected final List getOperators(final String token) {... |
106 |
1291
|
final List result = new ArrayList(); |
107 |
1291
|
if (token == null) { |
108 |
0
|
return result; |
109 |
|
} |
110 |
23238
|
for (int i = 0; i < getOperators().size(); i++) { |
111 |
21947
|
if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) { |
112 |
318
|
result.add(getOperators().get(i)); |
113 |
|
} |
114 |
|
} |
115 |
1291
|
return result; |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
1394
|
protected boolean eot(final String token) {... |
119 |
1394
|
return token == null || token.trim().length() == 0; |
120 |
|
} |
121 |
|
|
122 |
|
} |