/parsing/cfg.d

http://github.com/wilkie/djehuty · D · 58 lines · 32 code · 23 blank · 3 comment · 0 complexity · da15c8aa5dbc11411d8f3c8a1d992e36 MD5 · raw file

  1. module parsing.cfg;
  2. import core.string;
  3. import core.definitions;
  4. import io.console;
  5. class GrammarPhrase {
  6. this(string rule) {
  7. Console.putln(rule);
  8. _rule = rule;
  9. }
  10. protected:
  11. string _rule;
  12. }
  13. class GrammarRule {
  14. this(string rule) {
  15. Console.putln(rule);
  16. // parse the rule string
  17. // get the left hand side and right hand side
  18. // the string "->" delimits
  19. int divider = rule.find("->");
  20. _left = new GrammarPhrase(rule.substring(0, divider).trim());
  21. _right = new GrammarPhrase(rule.substring(divider+2).trim());
  22. }
  23. protected:
  24. GrammarPhrase _left;
  25. GrammarPhrase _right;
  26. }
  27. class Grammar {
  28. this() {
  29. }
  30. void addRule(string rule) {
  31. GrammarRule newRule = new GrammarRule(rule);
  32. _rules ~= newRule;
  33. }
  34. GrammarRule[] _rules;
  35. }