/parsing/d/forstmtunit.d

http://github.com/wilkie/djehuty · D · 81 lines · 54 code · 14 blank · 13 comment · 15 complexity · a62ede43abe02d65f0c86bddcb15d265 MD5 · raw file

  1. /*
  2. * expressionunit.d
  3. *
  4. * This module parses expressions.
  5. *
  6. */
  7. module parsing.d.forstmtunit;
  8. import parsing.parseunit;
  9. import parsing.token;
  10. import parsing.d.tokens;
  11. import parsing.d.nodes;
  12. import parsing.d.statementunit;
  13. import parsing.d.scopedstmtunit;
  14. import parsing.d.expressionunit;
  15. import io.console;
  16. import djehuty;
  17. class ForStmtUnit : ParseUnit {
  18. override bool tokenFound(Token current) {
  19. switch (current.type) {
  20. case DToken.LeftParen:
  21. Console.putln("For: ");
  22. auto tree = expand!(StatementUnit)();
  23. this.state = 1;
  24. break;
  25. case DToken.RightParen:
  26. if (this.state < 3 || this.state > 4) {
  27. }
  28. // Found end of for loop expressions
  29. this.state = 5;
  30. auto tree = expand!(ScopedStmtUnit)();
  31. break;
  32. case DToken.Semicolon:
  33. if (this.state == 0) {
  34. }
  35. if (this.state == 1) {
  36. // No expression.
  37. this.state = 3;
  38. }
  39. else if (this.state == 2) {
  40. // Had expression, looking for end
  41. // or loop expression
  42. this.state = 3;
  43. }
  44. break;
  45. // We have an expression here.
  46. default:
  47. if (this.state == 1) {
  48. // Invariant Expression
  49. lexer.push(current);
  50. auto tree = expand!(ExpressionUnit)();
  51. this.state = 2;
  52. }
  53. else if (this.state == 3) {
  54. // Loop expression
  55. lexer.push(current);
  56. auto tree = expand!(ExpressionUnit)();
  57. this.state = 4;
  58. }
  59. break;
  60. }
  61. return true;
  62. }
  63. protected:
  64. string cur_string = "";
  65. static const string _common_error_msg = "";
  66. static const string[] _common_error_usages = null;
  67. }