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