01: /*=============================================================================
02: * Copyright Texas Instruments 2000-2003. All Rights Reserved.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package oscript.compiler;
20:
21: import oscript.syntaxtree.Node;
22:
23: /**
24: * A front end for the compiler, making it match the {@link NodeEvaluatorFactory}
25: * interface
26: *
27: * @author Rob Clark (rob@ti.com)
28: */
29: public class CompiledNodeEvaluatorFactory implements
30: oscript.NodeEvaluatorFactory {
31: /**
32: * Given a <code>Node</code>, generate a <code>NodeEvaluator</code>.
33: *
34: * @param name name of node to process, for debugging
35: * @param node the node
36: * @return the node-evaluator
37: */
38: public oscript.NodeEvaluator createNodeEvaluator(String name,
39: Node node) {
40: return CompilerContext.compileNode(nodeNameToClassName(name),
41: node);
42: }
43:
44: private static final char[] illegalChars = { ' ', '\"', '\\', '.' };
45:
46: private static final String nodeNameToClassName(String name) {
47: for (int i = 0; i < illegalChars.length; i++)
48: name = name.replace(illegalChars[i], '_');
49:
50: // handle "/" specially, to split namespace into packages based on directory name:
51: if (name.charAt(0) == '/')
52: name = "root." + name.substring(1);
53: name = name.replace('/', '.');
54:
55: return name;
56: }
57: }
58:
59: /*
60: * Local Variables:
61: * tab-width: 2
62: * indent-tabs-mode: nil
63: * mode: java
64: * c-indentation-style: java
65: * c-basic-offset: 2
66: * eval: (c-set-offset 'substatement-open '0)
67: * eval: (c-set-offset 'case-label '+)
68: * eval: (c-set-offset 'inclass '+)
69: * eval: (c-set-offset 'inline-open '0)
70: * End:
71: */
|