01: /*
02: * xtc - The eXTensible Compiler
03: * Copyright (C) 2005-2006 New York University
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * version 2 as published by the Free Software Foundation.
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
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17: * USA.
18: */
19: package xtc.xform;
20:
21: import java.io.Reader;
22: import java.io.StringReader;
23: import java.io.IOException;
24:
25: import xtc.tree.GNode;
26: import xtc.tree.Node;
27:
28: import xtc.parser.Result;
29: import xtc.parser.SemanticValue;
30:
31: /**
32: * This class represents XForm AST queries.
33: *
34: * @author Joe Pamer
35: * @version $Revision: 1.11 $
36: */
37: public class Query {
38:
39: /** The query's AST */
40: GNode ast = null;
41:
42: /**
43: * Create a new Query.
44: *
45: * @param in A reader containing the query's source code.
46: * @throws IllegalArgumentException
47: * Signals a malformed query.
48: */
49: public Query(Reader in) throws IllegalArgumentException {
50: Result r;
51:
52: try {
53: XFormParser xform_parser = new XFormParser(in, "dummy");
54: r = xform_parser.pXForm(0);
55: } catch (IOException x) {
56: throw new AssertionError("Unexpected I/O condition");
57: }
58:
59: if (r.hasValue()) {
60: ast = (GNode) ((Node) ((SemanticValue) r).value).strip();
61: } else {
62: throw new IllegalArgumentException("Malformed query.");
63: }
64: }
65:
66: /**
67: * Create a new query.
68: *
69: * @param query The query as a string.
70: * @throws IllegalArgumentException
71: * Signals a malformed query.
72: */
73: public Query(String query) throws IllegalArgumentException {
74: this (new StringReader(query));
75: }
76:
77: } // end class Query
|