Mercurial > projects > dang
view lexer/Token.d @ 22:e331e4e816e4
now handling structs to some extend
author | johnsen@johnsen-laptop |
---|---|
date | Fri, 18 Apr 2008 23:45:45 +0200 |
parents | 0fb2d13dce37 |
children | 69464d465284 |
line wrap: on
line source
module lexer.Token; public import misc.Location; import Integer = tango.text.convert.Integer; struct Token { Tok type; Location location; uint length; static Token opCall (Tok type, Location location, uint length) { Token t; t.type = type; t.location = location; t.length = length; return t; } char[] getType () { return typeToString[this.type]; } char[] toString () { return this.getType()~": Len: "~Integer.toString(this.length) ~", Loc: "~location.toString; } char[] get () { return location.get(length); } } enum Tok : ushort { /* Non-code related tokens */ EOF, /* Basic types */ Identifier, Integer, /* Basic operators */ Assign, Add, Sub, Mul, Div, Comma, /* Symbols */ OpenParentheses, CloseParentheses, OpenBrace, CloseBrace, Seperator, /* Comparator operators */ Eq, Ne, Lt, Gt, Le, Ge, Not, /* Keywords */ Byte, Ubyte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Bool, Struct, If, Else, While, Return, } public char[][Tok] typeToString; static this() { typeToString = [ Tok.EOF:"EOF"[], Tok.Identifier:"Identifier", Tok.Byte:"Byte", Tok.Short:"Short", Tok.Int:"Int", Tok.Long:"Long", Tok.Bool:"Bool", Tok.Eq:"Eq", Tok.Ne:"Ne", Tok.Lt:"Lt", Tok.Le:"Le", Tok.Gt:"Gt", Tok.Ge:"Ge", Tok.OpenParentheses:"OpenParentheses", Tok.CloseParentheses:"CloseParentheses", Tok.OpenBrace:"OpenBrace", Tok.CloseBrace:"CloseBrace", Tok.Assign:"Assign", Tok.Add:"Add", Tok.Sub:"Sub", Tok.Mul:"Mul", Tok.Div:"Div", Tok.Integer:"Integer", Tok.If:"If", Tok.While:"While", Tok.Comma:"Comma", Tok.Return:"Return", Tok.Struct:"Struct", Tok.Seperator:"Seperator" ]; }