blob: 6468767858285a9d1ec1e5bbda532f543387e973 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package wcps.server.cli;
import grammar.*;
import grammar.wcpsParser.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.apache.commons.io.FileUtils;
/** Test the WCPS grammar parser (generated by ANTLR).
* Input the path that contains an Abstract Syntax query.
* Outputs the corresponding XML tree.
*
* @author Andrei Aiordachioaie
*/
public class f_grammar {
private static String query;
private static String path;
public static void main(String[] args) throws RecognitionException, IOException
{
if (args.length != 1)
{
System.err.println("AbstractGrammarGen: no parameter to specify input file !");
path = "test/test-tmp/29.test";
query = FileUtils.readFileToString(new File(path));
}
else
{
path = args[0];
query = FileUtils.readFileToString(new File(path));
}
System.out.println("Running with the following query: " + query);
String xmlString = runQuery(query);
System.out.println("Output XML: \n****************\n" + xmlString);
System.exit(0);
}
public static String runQuery(String query) throws IOException, RecognitionException
{
InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1
ANTLRInputStream inputStream = new ANTLRInputStream(stream);
// wcpsLexer lexer = new wcpsLexer( inputStream );
wcpsLexer lexer = new wcpsLexer( inputStream );
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
// wcpsParser parser = new wcpsParser(tokenStream);
wcpsParser parser = new wcpsParser(tokenStream);
wcpsRequest_return rrequest = parser.wcpsRequest();
WCPSRequest request = rrequest.value;
String result = request.toXML();
return result;
}
}
|