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: // This file is part of KeY - Integrated Deductive Software Design
10: // Copyright (C) 2001-2004 Universitaet Karlsruhe, Germany
11: // Universitaet Koblenz-Landau, Germany
12: // Chalmers University of Technology, Sweden
13: //
14: // The KeY system is protected by the GNU General Public License.
15: // See LICENSE.TXT for details.
16: package de.uka.ilkd.key.gui.assistant;
17:
18: import java.io.IOException;
19: import java.net.URL;
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import de.uka.ilkd.key.parser.dictionary.DictionaryLexer;
24: import de.uka.ilkd.key.parser.dictionary.DictionaryParser;
25: import de.uka.ilkd.key.util.Debug;
26: import de.uka.ilkd.key.util.KeYResourceManager;
27:
28: /**
29: * The dictionary of the proof assistant is encapsulated in this class
30: * together with a simple parser. The dictionary is divided up into
31: * sections which consists of key-value pairs. A new line means a new
32: * key-value pair.
33: */
34: class ProofAssistantDictionary {
35:
36: /**
37: * the dictionary
38: */
39: private Map dict = new HashMap(20);
40:
41: public ProofAssistantDictionary() {
42: parse(KeYResourceManager.getManager().getResourceFile(this ,
43: "assistantDictionary.dct"));
44: }
45:
46: /**
47: * parse the directory file
48: * @param dictFile the URL where the dictionary can be found
49: */
50: private void parse(URL dictFile) {
51: try {
52: DictionaryParser parser = new DictionaryParser(
53: new DictionaryLexer(dictFile.openStream()));
54: parser.start();
55: dict = parser.getDictionary();
56: } catch (IOException io) {
57: System.err
58: .println("Failing loading dictionary for proof assistant.");
59: System.err.println("Proof assistant will not work.");
60: Debug.out("Thrown exception:", io);
61: } catch (antlr.RecognitionException pe) {
62: System.err
63: .println("Failing loading dictionary for proof assistant.");
64: System.err.println("Dictionary is corrupt.");
65: Debug.out("Thrown exception:", pe);
66: } catch (antlr.TokenStreamException tse) {
67: System.err
68: .println("Failing loading dictionary for proof assistant.");
69: System.err.println("Dictionary is corrupt.");
70: Debug.out("Thrown exception:", tse);
71: }
72: }
73:
74: /**
75: * returns the stored text for the given key
76: */
77: public String get(String section, String key) {
78: return (String) dict.get(section + "." + key);
79: }
80:
81: }
|