EMMA Coverage Report (generated Fri Feb 14 08:28:31 UTC 2014)
[all classes][org.qedeq.kernel.bo.parser]

COVERAGE SUMMARY FOR SOURCE FILE [AsciiMathParser.java]

nameclass, %method, %block, %line, %
AsciiMathParser.java100% (1/1)100% (6/6)98%  (215/220)96%  (45.9/48)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AsciiMathParser100% (1/1)100% (6/6)98%  (215/220)96%  (45.9/48)
<static initializer> 100% (1/1)90%  (9/10)90%  (0.9/1)
getOperator (String): Operator 100% (1/1)94%  (31/33)88%  (7/8)
getOperators (String): List 100% (1/1)94%  (33/35)86%  (6/7)
AsciiMathParser (): void 100% (1/1)100% (3/3)100% (2/2)
eot (String): boolean 100% (1/1)100% (10/10)100% (1/1)
readToken (): String 100% (1/1)100% (129/129)100% (29/29)

1/* This file is part of the project "Hilbert II" - http://www.qedeq.org
2 *
3 * Copyright 2000-2014,  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 
16package org.qedeq.kernel.bo.parser;
17 
18import java.util.ArrayList;
19import java.util.List;
20 
21import org.qedeq.base.trace.Trace;
22 
23/*
24 * LATER mime 20080131: refactor
25 *
26 */
27 
28/**
29 * Parse term or formula data into {@link org.qedeq.kernel.bo.parser.Term}s.
30 * This parser uses simple ASCII text operators.
31 *
32 * @author  Michael Meyling
33 */
34public final class AsciiMathParser extends MathParser {
35 
36    /** This class. */
37    private static final Class CLASS = AsciiMathParser.class;
38 
39    /** Separators for tokens. */
40    private static final String SEPARATORS = "()[],{}";
41 
42    /**
43     * Constructor.
44     */
45    public AsciiMathParser() {
46        super();
47    }
48 
49    protected final String readToken() {
50        final String method = "readToken()";
51        int lines = 0;
52        while (getChar() != -1 && Character.isWhitespace((char) getChar())) {
53            if ('\n' == (char) getChar()) {
54                lines++;
55            }
56            readChar();
57        }
58        if (lines > 1) {
59            return "";
60        }
61        if (eof()) {
62            return null;
63        }
64        if (SEPARATORS.indexOf(getChar()) >= 0) {
65            Trace.param(CLASS, this, method, "Read token", "" + (char) getChar());
66            return "" + (char) readChar();
67        }
68        final StringBuffer token = new StringBuffer();
69        String operator = null;
70        markPosition();
71        while (!eof() && !Character.isWhitespace((char) getChar())
72                && SEPARATORS.indexOf(getChar()) < 0) {
73            token.append((char) readChar());
74            if (null != getOperator(token.toString())) {
75                operator = token.toString();
76                clearMark();
77                markPosition();
78            }
79        }
80        if (operator != null) {
81            rewindPosition();
82            token.setLength(0);
83            token.append(operator);
84        } else {
85            clearMark();
86        }
87        Trace.param(CLASS, this, method, "Read token", token);
88        return token.toString();
89    }
90 
91    protected final Operator getOperator(final String token) {
92        Operator result = null;
93        if (token == null) {
94            return result;
95        }
96        for (int i = 0; i < getOperators().size(); i++) {
97            if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
98                result = (Operator) getOperators().get(i);
99                break;
100            }
101        }
102        return result;
103    }
104 
105    protected final List getOperators(final String token) {
106        final List result = new ArrayList();
107        if (token == null) {
108            return result;
109        }
110        for (int i = 0; i < getOperators().size(); i++) {
111            if (token.equals(((Operator) getOperators().get(i)).getStartSymbol())) {
112                result.add(getOperators().get(i));
113            }
114        }
115        return result;
116    }
117 
118    protected boolean eot(final String token) {
119        return token == null || token.trim().length() == 0;
120    }
121 
122}

[all classes][org.qedeq.kernel.bo.parser]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov