01: package antlr;
02:
03: /**
04: * ANTLR Translator Generator
05: * Project led by Terence Parr at http://www.cs.usfca.edu
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: import java.util.Vector;
15: import java.util.Enumeration;
16: import java.io.PrintWriter;
17: import java.util.StringTokenizer;
18:
19: public class NameSpace {
20: private Vector names = new Vector();
21: private String _name;
22:
23: public NameSpace(String name) {
24: _name = new String(name);
25: parse(name);
26: }
27:
28: public String getName() {
29: return _name;
30: }
31:
32: /**
33: * Parse a C++ namespace declaration into seperate names
34: * splitting on :: We could easily parameterize this to make
35: * the delimiter a language-specific parameter, or use subclasses
36: * to support C++ namespaces versus java packages. -DAW
37: */
38: protected void parse(String name) {
39: StringTokenizer tok = new StringTokenizer(name, "::");
40: while (tok.hasMoreTokens())
41: names.addElement(tok.nextToken());
42: }
43:
44: /**
45: * Method to generate the required C++ namespace declarations
46: */
47: void emitDeclarations(PrintWriter out) {
48: for (Enumeration n = names.elements(); n.hasMoreElements();) {
49: String s = (String) n.nextElement();
50: out.println("ANTLR_BEGIN_NAMESPACE(" + s + ")");
51: }
52: }
53:
54: /**
55: * Method to generate the required C++ namespace closures
56: */
57: void emitClosures(PrintWriter out) {
58: for (int i = 0; i < names.size(); ++i)
59: out.println("ANTLR_END_NAMESPACE");
60: }
61: }
|