comparison src/plparser/PropertyListParser.java @ 4:29c0866e3a84

text
author one
date Sun, 29 Aug 2010 18:28:38 +0900
parents 1f46c9d09c1e
children 29b5497fc942
comparison
equal deleted inserted replaced
3:1f46c9d09c1e 4:29c0866e3a84
8 public class PropertyListParser<Node extends Property> { 8 public class PropertyListParser<Node extends Property> {
9 PropertyListNodeFactory<Node> lf; 9 PropertyListNodeFactory<Node> lf;
10 Token<Node> nextToken; 10 Token<Node> nextToken;
11 public PropertyListScanner<Node> scanner; 11 public PropertyListScanner<Node> scanner;
12 private Dictionary<Node> dict; 12 private Dictionary<Node> dict;
13 // scope is necessary if you have to parse nested name scope
13 // private PropertyListScope<Node> scope; 14 // private PropertyListScope<Node> scope;
14 15
15 public PropertyListParser(String string, 16 public PropertyListParser(String string,
16 PropertyListNodeFactory<Node> lf) { 17 PropertyListNodeFactory<Node> lf) {
17 this.lf = lf; 18 this.lf = lf;
18 initialize(); 19 initialize();
19 scanner.set(string); 20 scanner.set(string);
21 }
22
23 public PropertyListParser(PropertyListNodeFactory<Node> lf) {
24 this.lf = lf;
25 initialize();
20 } 26 }
21 27
22 28
23 public void initReservedWord() { 29 public void initReservedWord() {
24 dict.reserve("=",TokenID.Assign); 30 dict.reserve("=",TokenID.Assign);
38 initReservedWord(); 44 initReservedWord();
39 scanner = new PropertyListScanner<Node>(dict); 45 scanner = new PropertyListScanner<Node>(dict);
40 } 46 }
41 47
42 public Node parse() { 48 public Node parse() {
43 if (scanner==null) return null; 49 if (scanner==null) return null; // internal error
50 if (scanner.cb==null) return null; // nothing to do
44 nextToken(); 51 nextToken();
45 return term(); 52 return term();
46 } 53 }
47 54
48 public Node parse(String exp) { 55 public Node parse(String exp) {
53 nextToken = scanner.nextToken; 60 nextToken = scanner.nextToken;
54 return n; 61 return n;
55 62
56 } 63 }
57 64
58 public void parseFile(String file) { 65 public Node parseFile(String file) {
59 try { 66 try {
60 scanner = scanner.pushScannerFile(file); 67 scanner = scanner.pushScannerFile(file);
61 } catch (FileNotFoundException e) { 68 } catch (FileNotFoundException e) {
62 error("Can't open "+file); 69 error("Can't open "+file);
63 return; 70 return null;
64 } 71 }
65 doParse(); 72 return doParse();
66 } 73 }
67 74
68 public void parse(InputStream file) { 75 public Node parse(InputStream file) {
69 scanner = scanner.pushScannerFile(file,null); 76 scanner = scanner.pushScannerFile(file,null);
70 doParse(); 77 return doParse();
71 } 78 }
72 79
73 public void parse(InputStream in, String prompt) { 80 public Node parse(InputStream in, String prompt) {
74 scanner = scanner.pushScannerFile(in,prompt); 81 scanner = scanner.pushScannerFile(in,prompt);
75 doParse(); 82 return doParse();
76 } 83 }
77 84
78 public Node doParse() { 85 public Node doParse() {
79 Node n; 86 Node n;
80 do { 87 do {