/parsing/d/parameterlistunit.d

http://github.com/wilkie/djehuty · D · 77 lines · 44 code · 15 blank · 18 comment · 11 complexity · 34678b28221ffec24a1eb70458e09d50 MD5 · raw file

  1. /*
  2. * expressionunit.d
  3. *
  4. * This module parses expressions.
  5. *
  6. */
  7. module parsing.d.parameterlistunit;
  8. import parsing.parseunit;
  9. import parsing.token;
  10. import parsing.d.tokens;
  11. import parsing.d.nodes;
  12. import parsing.d.parameterunit;
  13. import parsing.d.functionbodyunit;
  14. import parsing.d.declaratorunit;
  15. import io.console;
  16. import djehuty;
  17. class ParameterListUnit : ParseUnit {
  18. override bool tokenFound(Token current) {
  19. switch (current.type) {
  20. case DToken.RightParen:
  21. // Done.
  22. return false;
  23. case DToken.Variadic:
  24. if (this.state == 2) {
  25. // Error: Have two variadics?!
  26. // TODO: One too many variadics.
  27. }
  28. // We have a variadic!
  29. this.state = 2;
  30. break;
  31. case DToken.Comma:
  32. if (this.state == 0) {
  33. // Error: Expected a parameter!
  34. // TODO: Probably accidently removed a parameter without removing the comma.
  35. }
  36. // Get Parameter
  37. this.state = 0;
  38. break;
  39. default:
  40. if (this.state == 0) {
  41. // Look for a parameter
  42. lexer.push(current);
  43. auto tree = expand!(ParameterUnit)();
  44. this.state = 1;
  45. }
  46. else if (this.state == 2) {
  47. // Error: Parameter after variadic?
  48. // TODO: Forgot comma.
  49. }
  50. else {
  51. // Error: otherwise
  52. // TODO:
  53. }
  54. break;
  55. }
  56. return true;
  57. }
  58. protected:
  59. string cur_string = "";
  60. static const string _common_error_msg = "";
  61. static const string[] _common_error_usages = null;
  62. }