Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
46   127   22   9.2
28   81   0.48   5
5     4.4  
1    
 
  AsciiMathParser       Line # 36 46 22 94.9% 0.9493671
 
  (51)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, 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    import org.qedeq.base.io.TextInput;
22    import org.qedeq.base.trace.Trace;
23   
24    /*
25    * LATER mime 20080131: refactor
26    *
27    */
28   
29    /**
30    * Parse term or formula data into {@link org.qedeq.kernel.bo.parser.Term}s.
31    * This parser uses simple ASCII text operators.
32    *
33    * @version $Revision: 1.1 $
34    * @author Michael Meyling
35    */
 
36    public final class AsciiMathParser extends MathParser {
37   
38    /** This class. */
39    private static final Class CLASS = AsciiMathParser.class;
40   
41    /** Separators for tokens. */
42    private static final String SEPARATORS = "()[],{}";
43   
44    /**
45    * Constructor.
46    *
47    * @param input Parse this input.
48    * @param operators Operator definitions.
49    */
 
50  51 toggle public AsciiMathParser(final TextInput input, final List operators) {
51  51 super(new MementoTextInput(input), operators);
52    }
53   
 
54  6989 toggle protected final String readToken() {
55  6989 final String method = "readToken()";
56  6989 int lines = 0;
57  9800 while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
58  2811 if ('\n' == (char) getChar()) {
59  333 lines++;
60    }
61  2811 readChar();
62    }
63  6989 if (lines > 1) {
64  4 return "";
65    }
66  6985 if (eof()) {
67  232 return null;
68    }
69  6753 if (SEPARATORS.indexOf(getChar()) >= 0) {
70  2485 Trace.param(CLASS, this, method, "Read token", "" + (char) getChar());
71  2485 return "" + (char) readChar();
72    }
73  4268 final StringBuffer token = new StringBuffer();
74  4268 String operator = null;
75  4268 markPosition();
76  9531 while (!eof() && !Character.isWhitespace((char) getChar())
77    && SEPARATORS.indexOf(getChar()) < 0) {
78  5263 token.append((char) readChar());
79  5263 if (null != getOperator(token.toString())) {
80  1137 operator = token.toString();
81  1137 clearMark();
82  1137 markPosition();
83    }
84    }
85  4268 if (operator != null) {
86  1135 rewindPosition();
87  1135 token.setLength(0);
88  1135 token.append(operator);
89    } else {
90  3133 clearMark();
91    }
92  4268 Trace.param(CLASS, this, method, "Read token", token);
93  4268 return token.toString();
94    }
95   
 
96  6833 toggle protected final Operator getOperator(final String token) {
97  6833 Operator result = null;
98  6833 if (token == null) {
99  0 return result;
100    }
101  97277 for (int i = 0; i < getOperators().size(); i++) {
102  92258 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
103  1814 result = (Operator) getOperators().get(i);
104  1814 break;
105    }
106    }
107  6833 return result;
108    }
109   
 
110  1268 toggle protected final List getOperators(final String token) {
111  1268 final List result = new ArrayList();
112  1268 if (token == null) {
113  0 return result;
114    }
115  21556 for (int i = 0; i < getOperators().size(); i++) {
116  20288 if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
117  310 result.add(getOperators().get(i));
118    }
119    }
120  1268 return result;
121    }
122   
 
123  1371 toggle protected boolean eot(final String token) {
124  1371 return token == null || token.trim().length() == 0;
125    }
126   
127    }