01: package persistence.antlr;
02:
03: /**
04: * ANTLR Translator Generator
05: * Project led by Terence Parr at http://www.jGuru.com
06: * Software rights: http://www.antlr.org/license.html
07: *
08: * Container for a C++ namespace specification. Namespaces can be
09: * nested, so this contains a vector of all the nested names.
10: *
11: * @author David Wagner (JPL/Caltech) 8-12-00
12: *
13: */
14:
15: import java.util.Vector;
16: import java.util.Enumeration;
17: import java.io.PrintWriter;
18: import java.util.StringTokenizer;
19:
20: public class NameSpace {
21: private Vector names = new Vector();
22: private String _name;
23:
24: public NameSpace(String name) {
25: _name = new String(name);
26: parse(name);
27: }
28:
29: public String getName() {
30: return _name;
31: }
32:
33: /**
34: * Parse a C++ namespace declaration into seperate names
35: * splitting on :: We could easily parameterize this to make
36: * the delimiter a language-specific parameter, or use subclasses
37: * to support C++ namespaces versus java packages. -DAW
38: */
39: protected void parse(String name) {
40: StringTokenizer tok = new StringTokenizer(name, "::");
41: while (tok.hasMoreTokens())
42: names.addElement(tok.nextToken());
43: }
44:
45: /**
46: * Method to generate the required C++ namespace declarations
47: */
48: void emitDeclarations(PrintWriter out) {
49: for (Enumeration n = names.elements(); n.hasMoreElements();) {
50: String s = (String) n.nextElement();
51: out.println("ANTLR_BEGIN_NAMESPACE(" + s + ")");
52: }
53: }
54:
55: /**
56: * Method to generate the required C++ namespace closures
57: */
58: void emitClosures(PrintWriter out) {
59: for (int i = 0; i < names.size(); ++i)
60: out.println("ANTLR_END_NAMESPACE");
61: }
62: }
|