PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/parsing/cfg.d

http://github.com/wilkie/djehuty
D | 58 lines | 32 code | 23 blank | 3 comment | 0 complexity | da15c8aa5dbc11411d8f3c8a1d992e36 MD5 | raw file
 1module parsing.cfg;
 2
 3import core.string;
 4import core.definitions;
 5
 6import io.console;
 7
 8class GrammarPhrase {
 9	this(string rule) {
10		Console.putln(rule);
11
12		_rule = rule;
13	}
14
15protected:
16
17	string _rule;
18}
19
20
21
22
23class GrammarRule {
24	this(string rule) {
25		Console.putln(rule);
26
27		// parse the rule string
28		// get the left hand side and right hand side
29		// the string "->" delimits
30
31		int divider = rule.find("->");
32
33		_left = new GrammarPhrase(rule.substring(0, divider).trim());
34		_right = new GrammarPhrase(rule.substring(divider+2).trim());
35	}
36
37protected:
38
39	GrammarPhrase _left;
40	GrammarPhrase _right;
41}
42
43
44
45
46
47class Grammar {
48	this() {
49	}
50
51	void addRule(string rule) {
52		GrammarRule newRule = new GrammarRule(rule);
53
54		_rules ~= newRule;
55	}
56
57	GrammarRule[] _rules;
58}