# HG changeset patch # User johnsen@johnsen-desktop # Date 1208514254 -7200 # Node ID 606a57c90a0b81c529ab185f4f5c8510bf468339 # Parent 2c5a8f4c254a866fc58dd8cb54530a40f4fdc8f0 Now lexing == as Equals diff -r 2c5a8f4c254a -r 606a57c90a0b lexer/Lexer.d --- 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)); } } diff -r 2c5a8f4c254a -r 606a57c90a0b lexer/Token.d --- 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", diff -r 2c5a8f4c254a -r 606a57c90a0b misc/Error.d --- 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; + } } diff -r 2c5a8f4c254a -r 606a57c90a0b misc/Location.d --- 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) diff -r 2c5a8f4c254a -r 606a57c90a0b test.td --- a/test.td Fri Apr 18 11:46:00 2008 +0200 +++ b/test.td Fri Apr 18 12:24:14 2008 +0200 @@ -11,7 +11,7 @@ int nice(long s, short t) { byte x = 5 + t; - if (x) + if (x == 0) if (s) t = 5 + 1 * 5 * s + t; return 2 * (t + -1) - x;