Mercurial > projects > dang
view lexer/Token.d @ 36:ce17bea8e9bd new_gen
Switch statements support
Can only switch on IntegerLit's but multiple values per case and the
default are supported.
An error is emitted if a value is used multiple times or if theres is more
than one default block
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 22:39:07 +0200 |
parents | 69464d465284 |
children | 858b9805843d |
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, Colon, Dot, /* 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, Switch, Case, Default, 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.Dot:"Dot", 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.Switch:"Switch", Tok.Case:"Case", Tok.Default:"Default", Tok.Comma:"Comma", Tok.Return:"Return", Tok.Struct:"Struct", Tok.Colon:"Colon", Tok.Seperator:"Seperator" ]; }