PageRenderTime 16ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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