PageRenderTime 29ms CodeModel.GetById 19ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

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