/parsing/d/enumdeclunit.d

http://github.com/wilkie/djehuty · D · 73 lines · 46 code · 9 blank · 18 comment · 5 complexity · fc11bfc94da7fc72f00180d4c61aaf9b MD5 · raw file

  1. /*
  2. * expressionunit.d
  3. *
  4. * This module parses expressions.
  5. *
  6. */
  7. module parsing.d.enumdeclunit;
  8. import parsing.parseunit;
  9. import parsing.token;
  10. import parsing.d.tokens;
  11. import parsing.d.nodes;
  12. import parsing.d.typeunit;
  13. import parsing.d.enumbodyunit;
  14. import io.console;
  15. import djehuty;
  16. class EnumDeclUnit : ParseUnit {
  17. override bool tokenFound(Token current) {
  18. // Looking for a name, or a colon for a type, or a curly
  19. // braces for the enum body
  20. switch (current.type) {
  21. case DToken.Identifier:
  22. // The name of the enum
  23. if (this.state >= 1) {
  24. // We are already passed the name stage.
  25. // XXX: error
  26. }
  27. this.state = 1;
  28. cur_string = current.value.toString();
  29. Console.putln("Enum: ", current.value);
  30. break;
  31. case DToken.Colon:
  32. // The type of the enum
  33. if (this.state >= 2) {
  34. // Already passed the type stage.
  35. // XXX: error
  36. }
  37. this.state = 2;
  38. auto tree = expand!(TypeUnit)();
  39. break;
  40. case DToken.Semicolon:
  41. if (this.state == 0) {
  42. // Need some kind of information about the enum.
  43. error(_common_error_msg,
  44. "Without a name, the linker will not know what it should be linking to.",
  45. ["enum FooBar;", "enum FooBar : uint;"]);
  46. return false;
  47. }
  48. // Done.
  49. return false;
  50. case DToken.LeftCurly:
  51. // We are going into the body of the enum
  52. auto tree = expand!(EnumBodyUnit)();
  53. // Done.
  54. return false;
  55. default:
  56. break;
  57. }
  58. return true;
  59. }
  60. protected:
  61. string cur_string = "";
  62. static const string _common_error_msg = "Enum declaration is invalid.";
  63. static const string[] _common_error_usages = null;
  64. }