/parsing/d/foreachstmtunit.d

http://github.com/wilkie/djehuty · D · 97 lines · 75 code · 12 blank · 10 comment · 24 complexity · f5297d133e3110a14b479dae09fec53b MD5 · raw file

  1. /*
  2. * expressionunit.d
  3. *
  4. * This module parses expressions.
  5. *
  6. */
  7. module parsing.d.foreachstmtunit;
  8. import parsing.parseunit;
  9. import parsing.token;
  10. import parsing.d.tokens;
  11. import parsing.d.nodes;
  12. import parsing.d.expressionunit;
  13. import parsing.d.scopedstmtunit;
  14. import parsing.d.typeunit;
  15. import io.console;
  16. import djehuty;
  17. class ForeachStmtUnit : ParseUnit {
  18. override bool tokenFound(Token current) {
  19. switch (current.type) {
  20. case DToken.LeftParen:
  21. if (this.state > 0) {
  22. // Error: Already found left parenthesis.
  23. // TODO:
  24. }
  25. this.state = 1;
  26. break;
  27. case DToken.RightParen:
  28. if (this.state != 5) {
  29. }
  30. auto tree = expand!(ScopedStmtUnit)();
  31. return false;
  32. case DToken.Ref:
  33. if (this.state == 0) {
  34. }
  35. else if (this.state >= 2) {
  36. }
  37. this.state = 2;
  38. break;
  39. case DToken.Identifier:
  40. if (this.state == 0) {
  41. }
  42. if (this.state > 3) {
  43. }
  44. if (this.state == 3) {
  45. this.state = 4;
  46. }
  47. else {
  48. // This needs lookahead to know it isn't a type
  49. Token foo = lexer.pop();
  50. lexer.push(foo);
  51. if (foo.type == DToken.Comma || foo.type == DToken.Semicolon) {
  52. this.state = 4;
  53. }
  54. else {
  55. lexer.push(current);
  56. // Getting type of identifier
  57. auto tree = expand!(TypeUnit)();
  58. this.state = 3;
  59. }
  60. }
  61. if (this.state == 4) {
  62. Console.putln("Foreach: identifier: ", current.value);
  63. }
  64. break;
  65. case DToken.Semicolon:
  66. if (this.state < 4) {
  67. }
  68. auto tree = expand!(ExpressionUnit)();
  69. this.state = 5;
  70. break;
  71. case DToken.Comma:
  72. if (this.state != 4) {
  73. }
  74. this.state = 1;
  75. break;
  76. default:
  77. break;
  78. }
  79. return true;
  80. }
  81. protected:
  82. string cur_string = "";
  83. static const string _common_error_msg = "";
  84. static const string[] _common_error_usages = null;
  85. }