/parsing/d/staticifunit.d

http://github.com/wilkie/djehuty · D · 117 lines · 62 code · 19 blank · 36 comment · 29 complexity · be07b5a878c78b486d1e21377deab7bf MD5 · raw file

  1. /*
  2. * expressionunit.d
  3. *
  4. * This module parses expressions.
  5. *
  6. */
  7. module parsing.d.staticifunit;
  8. import parsing.parseunit;
  9. import parsing.token;
  10. import parsing.d.tokens;
  11. import parsing.d.nodes;
  12. import parsing.d.assignexprunit;
  13. import parsing.d.declarationunit;
  14. import io.console;
  15. import djehuty;
  16. class StaticIfUnit : ParseUnit {
  17. override bool tokenFound(Token current) {
  18. if (this.state == 3) {
  19. // We are looking for declarations
  20. if (current.type == DToken.RightCurly) {
  21. // Done.
  22. return false;
  23. }
  24. else {
  25. lexer.push(current);
  26. auto tree = expand!(DeclarationUnit)();
  27. }
  28. return true;
  29. }
  30. // Else, we are looking for the condition
  31. switch (current.type) {
  32. // Look for a left paren first. It must exist.
  33. case DToken.LeftParen:
  34. if (this.state == 1) {
  35. // Error: Too many left parentheses.
  36. // TODO:
  37. }
  38. else if (this.state == 2) {
  39. // Error: We already found a right paren... Expected colon or brace
  40. // TODO:
  41. }
  42. this.state = 1;
  43. // The conditional part
  44. auto tree = expand!(AssignExprUnit)();
  45. break;
  46. case DToken.RightParen:
  47. if (this.state == 0) {
  48. // Error: Do not have a left paren.
  49. // TODO: Probably forgot a left parenthesis.
  50. }
  51. else if (this.state == 2) {
  52. // Error: Too many right parens
  53. // TODO:
  54. }
  55. // Now we can look for a : or a curly brace for a declaration block
  56. this.state = 2;
  57. break;
  58. // For declaring the rest of the file under this conditional block
  59. // static if (foo):
  60. case DToken.Colon:
  61. if (this.state == 0) {
  62. // Error: Do not have a condition!
  63. // TODO:
  64. }
  65. else if (this.state == 1) {
  66. // Error: Do not have a right paren.
  67. // TODO:
  68. }
  69. else if (this.state == 3) {
  70. // Error: After a left curly brace. We are within the block.
  71. // TODO:
  72. }
  73. // Done.
  74. return false;
  75. // For specifying a declaration block for this condition
  76. case DToken.LeftCurly:
  77. if (this.state == 0) {
  78. // Error: Do not have a condition!
  79. // TODO:
  80. }
  81. else if (this.state == 1) {
  82. // Error: Do not have a right paren.
  83. // TODO:
  84. }
  85. // Now we look for declarations.
  86. this.state = 3;
  87. break;
  88. // Errors for any unknown tokens.
  89. default:
  90. break;
  91. }
  92. return true;
  93. }
  94. protected:
  95. string cur_string = "";
  96. static const string _common_error_msg = "";
  97. static const string[] _common_error_usages = null;
  98. }