Mercurial > projects > dang
changeset 6:606a57c90a0b
Now lexing == as Equals
author | johnsen@johnsen-desktop |
---|---|
date | Fri, 18 Apr 2008 12:24:14 +0200 |
parents | 2c5a8f4c254a |
children | 2ce5209f1954 2e1069ee21af |
files | lexer/Lexer.d lexer/Token.d misc/Error.d misc/Location.d test.td |
diffstat | 5 files changed, 25 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/lexer/Lexer.d Fri Apr 18 11:46:00 2008 +0200 +++ b/lexer/Lexer.d Fri Apr 18 12:24:14 2008 +0200 @@ -84,6 +84,8 @@ case ',': return Token(Tok.Comma, Location(position - 1, this.source), 1); case '=': + if(source.data[position] == '=') + return Token(Tok.Equals, Location(position++ - 1, this.source), 2); return Token(Tok.Assign, Location(position - 1, this.source), 1); case '+': return Token(Tok.Add, Location(position - 1, this.source), 1); @@ -204,6 +206,8 @@ case '/': return CharType.Symbol; + default: + throw new Error("Read invalid symbol: '" ~ current ~ "'", Location(position, source)); } }
--- a/lexer/Token.d Fri Apr 18 11:46:00 2008 +0200 +++ b/lexer/Token.d Fri Apr 18 12:24:14 2008 +0200 @@ -59,6 +59,9 @@ CloseBrace, Seperator, + /* Boolean operators */ + Equals, NotEquals, + /* Keywords */ Byte, Ubyte, Short, Ushort, @@ -87,6 +90,8 @@ Tok.Int:"Int", Tok.Long:"Long", Tok.Bool:"Bool", + Tok.Equals:"Equals", + Tok.NotEquals:"NotEquals", Tok.OpenParentheses:"OpenParentheses", Tok.CloseParentheses:"CloseParentheses", Tok.OpenBrace:"OpenBrace",
--- a/misc/Error.d Fri Apr 18 11:46:00 2008 +0200 +++ b/misc/Error.d Fri Apr 18 12:24:14 2008 +0200 @@ -2,8 +2,17 @@ import misc.Location; -struct Error +import tango.core.Exception; + +class Error : Exception { - char[] messeage; + char[] message; Location errorLocation; + + this(char[] message, Location errorLocation) + { + super(message ~ " at line " ~ errorLocation.toString); + this.message = message; + this.errorLocation = errorLocation; + } }
--- a/misc/Location.d Fri Apr 18 11:46:00 2008 +0200 +++ b/misc/Location.d Fri Apr 18 12:24:14 2008 +0200 @@ -2,7 +2,8 @@ import misc.DataSource; -import Integer = tango.text.convert.Integer; +import Integer = tango.text.convert.Integer, + tango.text.Util; struct Location { @@ -11,7 +12,8 @@ char[] toString () { - return Integer.toString (position) ~" in "~source.name; + int lineNumber = split(source.get(0, position), "\n").length; + return Integer.toString(lineNumber) ~" in "~source.name; } char[] get(uint length)