/parsing/d/typedeclarationunit.d

http://github.com/wilkie/djehuty · D · 109 lines · 72 code · 16 blank · 21 comment · 1 complexity · 8e15656827145bf5d6a751ddbc6d6e74 MD5 · raw file

  1. /*
  2. * typedeclarationunit.d
  3. *
  4. */
  5. module parsing.d.typedeclarationunit;
  6. import parsing.parseunit;
  7. import parsing.token;
  8. import parsing.d.tokens;
  9. import parsing.d.nodes;
  10. import parsing.d.staticunit;
  11. import parsing.d.declaratorunit;
  12. import djehuty;
  13. import io.console;
  14. class TypeDeclarationUnit : ParseUnit {
  15. override bool tokenFound(Token current) {
  16. switch(this.state) {
  17. // Looking for a basic type or identifier
  18. case 0:
  19. switch (current.type) {
  20. case DToken.Bool:
  21. case DToken.Byte:
  22. case DToken.Ubyte:
  23. case DToken.Short:
  24. case DToken.Ushort:
  25. case DToken.Int:
  26. case DToken.Uint:
  27. case DToken.Long:
  28. case DToken.Ulong:
  29. case DToken.Char:
  30. case DToken.Wchar:
  31. case DToken.Dchar:
  32. case DToken.Float:
  33. case DToken.Double:
  34. case DToken.Real:
  35. case DToken.Ifloat:
  36. case DToken.Idouble:
  37. case DToken.Ireal:
  38. case DToken.Cfloat:
  39. case DToken.Cdouble:
  40. case DToken.Creal:
  41. case DToken.Void:
  42. // We have a basic type... look for Declarator
  43. Console.putln("TypeDecl: basic type");
  44. auto tree = expand!(DeclaratorUnit)();
  45. this.state = 1;
  46. break;
  47. case DToken.Identifier:
  48. // Named Type
  49. break;
  50. case DToken.Typeof:
  51. // TypeOfExpression
  52. // TODO: this
  53. break;
  54. // Invalid token for this state
  55. case DToken.Assign:
  56. break;
  57. // Invalid token for this state
  58. case DToken.Semicolon:
  59. break;
  60. default:
  61. // We will pass this off to a Declarator
  62. auto tree = expand!(DeclaratorUnit)();
  63. this.state = 1;
  64. break;
  65. }
  66. // We have found a basic type and are looking for either an initializer
  67. // or another type declaration. We could also have a function body
  68. // for function literals.
  69. case 1:
  70. switch(current.type) {
  71. case DToken.Semicolon:
  72. // Done
  73. return false;
  74. case DToken.Comma:
  75. // XXX: Dunno
  76. return false;
  77. case DToken.Assign:
  78. // Initializer
  79. // auto tree = expand!(InitializerUnit)();
  80. this.state = 4;
  81. break;
  82. default:
  83. // It could be a function body
  84. // auto tree = expand!(FunctionBodyUnit)();
  85. return false;
  86. }
  87. break;
  88. default:
  89. break;
  90. }
  91. return true;
  92. }
  93. }