/parsing/d/versionunit.d

http://github.com/wilkie/djehuty · D · 207 lines · 109 code · 24 blank · 74 comment · 75 complexity · ca4259f6790b5e1306b86d9625a81108 MD5 · raw file

  1. /*
  2. * expressionunit.d
  3. *
  4. * This module parses expressions.
  5. *
  6. */
  7. module parsing.d.versionunit;
  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 VersionUnit : ParseUnit {
  17. override bool tokenFound(Token current) {
  18. if (this.state == 4) {
  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. // We could be declaring a version
  33. // version = Release; etc
  34. case DToken.Assign:
  35. if (this.state == 1) {
  36. // Error: Already started to use an identifier
  37. // TODO:
  38. }
  39. else if (this.state == 2) {
  40. // Error: Already named an identifier.
  41. // TODO:
  42. }
  43. else if (this.state == 3) {
  44. // Error: Found right paren.
  45. // TODO:
  46. }
  47. // We need to find the identifier or integer to enable.
  48. this.state = 5;
  49. break;
  50. // Look for a left paren first. It must exist.
  51. case DToken.LeftParen:
  52. if (this.state == 1) {
  53. // Error: Too many left parentheses.
  54. // TODO:
  55. }
  56. else if (this.state == 2) {
  57. // Error: Found an identifier.
  58. // TODO: Probably mistook left for right parenthesis.
  59. }
  60. else if (this.state == 3) {
  61. // Error: We already found a right paren... Expected colon or brace
  62. // TODO:
  63. }
  64. this.state = 1;
  65. break;
  66. // For version assignment, we are looking for a semicolon to end it.
  67. case DToken.Semicolon:
  68. if (this.state == 5) {
  69. // Error: No identifier given.
  70. // TODO:
  71. }
  72. else if (this.state == 0) {
  73. // Error: Need '=' first.
  74. // TODO:
  75. }
  76. else if (this.state == 1) {
  77. // Error: Have left paren.
  78. // TODO:
  79. }
  80. else if (this.state == 2) {
  81. // Error: Have Identifier for normal foo.
  82. // TODO:
  83. }
  84. else if (this.state == 3) {
  85. // Error: Have right paren.
  86. // TODO:
  87. }
  88. // else this.state == 6
  89. // Done.
  90. return false;
  91. // Looking for some literal or identifier to use as the version
  92. case DToken.Identifier:
  93. case DToken.IntegerLiteral:
  94. if (this.state == 5) {
  95. // We are assigning a version
  96. cur_string = current.value.toString();
  97. Console.putln("Version enabled: ", current.value);
  98. this.state = 6;
  99. }
  100. else if (this.state == 6) {
  101. // Error: Too many identifiers in a row on a version assign.
  102. // TODO:
  103. }
  104. else if (this.state == 0) {
  105. // Error: No left parenthesis.
  106. // TODO: Probably forgot it!
  107. }
  108. else if (this.state == 2) {
  109. // Error: Too many identifiers in a row!
  110. // TODO: Probably put a space or something in.
  111. }
  112. else if (this.state == 3) {
  113. // Error: Found right parenthesis.
  114. // TODO: Probably forgot a curly brace.
  115. }
  116. else {
  117. Console.putln("Version: ", current.value);
  118. cur_string = current.value.toString();
  119. this.state = 2;
  120. }
  121. break;
  122. case DToken.RightParen:
  123. if (this.state == 0) {
  124. // Error: Do not have a left paren.
  125. // TODO: Probably forgot a left parenthesis.
  126. }
  127. else if (this.state == 3) {
  128. // Error: Too many right parens
  129. // TODO:
  130. }
  131. // Now we can look for a : or a curly brace for a declaration block
  132. this.state = 3;
  133. break;
  134. // For declaring the rest of the file under this conditional block
  135. // static if (foo):
  136. case DToken.Colon:
  137. if (this.state == 0) {
  138. // Error: Do not have a condition!
  139. // TODO:
  140. }
  141. else if (this.state == 1) {
  142. // Error: Do not have an identifier.
  143. // TODO:
  144. }
  145. else if (this.state == 2) {
  146. // Error: Do not have a right paren.
  147. // TODO:
  148. }
  149. else if (this.state == 4) {
  150. // Error: After a left curly brace. We are within the block.
  151. // TODO:
  152. }
  153. // Done.
  154. return false;
  155. // For specifying a declaration block for this condition
  156. case DToken.LeftCurly:
  157. if (this.state == 0) {
  158. // Error: Do not have a condition!
  159. // TODO:
  160. }
  161. else if (this.state == 1) {
  162. // Error: Do not have an identifier.
  163. // TODO:
  164. }
  165. else if (this.state == 2) {
  166. // Error: Do not have a right paren.
  167. // TODO:
  168. }
  169. // Now we look for declarations.
  170. this.state = 4;
  171. break;
  172. // Errors for any unknown tokens.
  173. default:
  174. // TODO:
  175. break;
  176. }
  177. return true;
  178. }
  179. protected:
  180. string cur_string = "";
  181. static const string _common_error_msg = "";
  182. static const string[] _common_error_usages = null;
  183. }