|
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 |
| package koala.dynamicjava.parser.wrapper; |
|
30 |
| |
|
31 |
| import java.io.*; |
|
32 |
| import java.util.*; |
|
33 |
| |
|
34 |
| import edu.rice.cs.dynamicjava.Options; |
|
35 |
| |
|
36 |
| import koala.dynamicjava.parser.impl.*; |
|
37 |
| import koala.dynamicjava.tree.*; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public class JavaCCParser implements SourceCodeParser { |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| private final Parser _parser; |
|
52 |
| private final File _f; |
|
53 |
| |
|
54 |
0
| public JavaCCParser(InputStream is, File f, Options opt) {
|
|
55 |
0
| _parser = new Parser(is);
|
|
56 |
0
| _parser.setFile(f);
|
|
57 |
0
| _parser.setOptions(opt);
|
|
58 |
0
| _f = f;
|
|
59 |
| } |
|
60 |
| |
|
61 |
0
| public JavaCCParser(InputStream is, Options opt) {
|
|
62 |
0
| _parser = new Parser(is);
|
|
63 |
0
| _parser.setOptions(opt);
|
|
64 |
0
| _f = null;
|
|
65 |
| } |
|
66 |
| |
|
67 |
0
| public JavaCCParser(Reader r, File f, Options opt) {
|
|
68 |
0
| _parser = new Parser(r);
|
|
69 |
0
| _parser.setFile(f);
|
|
70 |
0
| _parser.setOptions(opt);
|
|
71 |
0
| _f = f;
|
|
72 |
| } |
|
73 |
| |
|
74 |
732
| public JavaCCParser(Reader r, Options opt) {
|
|
75 |
732
| _parser = new Parser(r);
|
|
76 |
732
| _parser.setOptions(opt);
|
|
77 |
732
| _f = null;
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
732
| public List<Node> parseStream() {
|
|
86 |
732
| try {
|
|
87 |
732
| return _parser.parseStream();
|
|
88 |
| } |
|
89 |
| catch (ParseException e) { |
|
90 |
0
| throw new ParseError(e, _f);
|
|
91 |
| } |
|
92 |
| catch (TokenMgrError e) { |
|
93 |
0
| throw new ParseError(e, SourceInfo.point(_f, 0, 0));
|
|
94 |
| } |
|
95 |
| catch (Error e) { |
|
96 |
| |
|
97 |
0
| String msg = e.getMessage();
|
|
98 |
0
| if (msg != null && msg.startsWith("Invalid escape character")) {
|
|
99 |
0
| throw new ParseError(e, SourceInfo.point(_f, 0, 0));
|
|
100 |
| } |
|
101 |
0
| else { throw e; }
|
|
102 |
| } |
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
0
| public CompilationUnit parseCompilationUnit() {
|
|
110 |
0
| try {
|
|
111 |
0
| return _parser.parseCompilationUnit();
|
|
112 |
| } |
|
113 |
| catch (ParseException e) { |
|
114 |
0
| throw new ParseError(e, _f);
|
|
115 |
| } |
|
116 |
| catch (TokenMgrError e) { |
|
117 |
0
| throw new ParseError(e, SourceInfo.point(_f, 0, 0));
|
|
118 |
| } |
|
119 |
| catch (Error e) { |
|
120 |
| |
|
121 |
0
| String msg = e.getMessage();
|
|
122 |
0
| if (msg != null && msg.startsWith("Invalid escape character")) {
|
|
123 |
0
| throw new ParseError(e, SourceInfo.point(_f, 0, 0));
|
|
124 |
| } |
|
125 |
0
| else { throw e; }
|
|
126 |
| } |
|
127 |
| } |
|
128 |
| } |