01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.parser;
12:
13: import antlr.CharScanner;
14: import antlr.Token;
15: import antlr.TokenStream;
16: import antlr.TokenStreamSelector;
17:
18: public class DeclPicker implements TokenStream {
19:
20: protected CharScanner input;
21: private String text = null;
22: private int lastMark = 0;
23:
24: /** Stream to read tokens from */
25: public DeclPicker(CharScanner in) {
26: input = in;
27: }
28:
29: public Token nextToken() throws antlr.TokenStreamException {
30: return getSelector().nextToken();
31: }
32:
33: public TokenStreamSelector getSelector() {
34: return ((KeYLexer) input).getSelector();
35: }
36:
37: public void commit() {
38: input.commit();
39: }
40:
41: public int mark() {
42: lastMark = input.mark();
43: return lastMark;
44: }
45:
46: public void capture() {
47: text = input.getInputBuffer().getMarkedChars();
48: //workaround for using antlr with multiple marks
49: text = text.substring(lastMark);
50: }
51:
52: public String getText() {
53: return text;
54: }
55:
56: /** This makes us a stream
57: public Token nextToken() throws antlr.TokenStreamException {
58: t = input.nextToken();
59: if (finished) return t;
60:
61: if (t.getType() == KeYLexerTokenTypes.SORTS ||
62: t.getType() == KeYLexerTokenTypes.FUNCTIONS ||
63: t.getType() == KeYLexerTokenTypes.PREDICATES ||
64: t.getType() == KeYLexerTokenTypes.SCHEMA ||
65: t.getType() == KeYLexerTokenTypes.RULES ||
66: t.getType() == KeYLexerTokenTypes.HEURISTICS) {
67: // System.out.println("\n");
68: copyState = true;
69: input.mark();
70: }
71:
72: if (t.getType() == KeYLexerTokenTypes.PROBLEM) {
73: copyState = false;
74: finished = true;
75: System.err.println( input.getInputBuffer().getMarkedChars());
76: }
77:
78:
79: // if (copyState) {
80: // System.out.print(t.getText());
81: // if (t.getType() == KeYLexerTokenTypes.SEMI)
82: // System.out.println();
83: // else
84: // System.out.print(" ");
85: // }
86:
87: return t;
88: }
89: */
90:
91: }
|