1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.gridsystems.beanfilter;
18
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
21
22
23
24
25
26
27
28 public final class Parser {
29
30
31
32
33 private Parser() { }
34
35
36
37
38
39
40
41
42
43 public static EvalNode parse(String s, Class<?> c) throws EvalException {
44 FilterParser parser = new FilterParser(s, c);
45 try {
46 return parser.compile();
47 } catch (ParseException e) {
48
49 Object[] eparams = {
50 e.currentToken.next.beginLine,
51 e.currentToken.next.beginColumn,
52 null
53 };
54 String code = "FTR000";
55 if (e.specialConstructor && e.tokenImage == null) {
56
57 code = "FTR005";
58 eparams[1] = e.currentToken.image;
59 }
60 throw new EvalException(e, code, eparams);
61 } catch (TokenMgrError e) {
62 String msg = e.getMessage();
63 int pos = msg.indexOf('.');
64 if (pos != -1) {
65 final String pattern = "Lexical error at line ([0-9]+), column ([0-9]+)";
66 Pattern p = Pattern.compile(pattern);
67 Matcher m = p.matcher(msg.substring(0, pos));
68 if (m.matches()) {
69 Object[] eparams = { new Integer(m.group(1)), new Integer(m.group(2)) };
70 throw new EvalException(e, "FTR000", eparams);
71 }
72 }
73 throw new EvalException(e, "FTR000", 0, 0);
74 }
75 }
76 }