# HG changeset patch # User aziz # Date 1183297980 0 # Node ID 24db7c5522d509e213050eacdc9e67a6d9e91afe # Parent 7eb83dd38901822bc264e8bff9fa8f504838c055 - Added module Information for compiler messages like warnings, info and errors to the user. - Renamed class Problem to Information. diff -r 7eb83dd38901 -r 24db7c5522d5 trunk/src/Information.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/Information.d Sun Jul 01 13:53:00 2007 +0000 @@ -0,0 +1,44 @@ +/++ + Author: Aziz Köksal + License: GPL2 ++/ +module Information; +import Messages; +import std.string; + +enum Type +{ + Lexer, + Parser, + Semantic +} + +class Information +{ + MID id; + Type type; + uint loc; + string[] arguments; + + this(Type type, MID id, uint loc, string[] arguments) + { + this.id = id; + this.type = type; + this.loc = loc; + this.arguments = arguments; + } + + string getMsg() + { + char[] msg = messages[id]; + + if (arguments.length == 0) + return msg; + + foreach (i, arg; arguments) + msg = replace(msg, format("{%s}", i+1), arg); + + return msg; + } +} + diff -r 7eb83dd38901 -r 24db7c5522d5 trunk/src/Lexer.d --- a/trunk/src/Lexer.d Sun Jul 01 12:18:02 2007 +0000 +++ b/trunk/src/Lexer.d Sun Jul 01 13:53:00 2007 +0000 @@ -4,6 +4,7 @@ +/ module Lexer; import Token; +import Information; import Keywords; import Identifier; import Messages; @@ -22,49 +23,6 @@ const uint _Z_ = 26; /// Control+Z -class Problem -{ - enum Type - { - Lexer, - Parser, - Semantic - } - - MID id; - Type type; - uint loc; - string[] arguments; -/* - this(Type type, MID id, uint loc) - { - this.id = id; - this.type = type; - this.loc = loc; - } -*/ - this(Type type, MID id, uint loc, string[] arguments) - { - this.id = id; - this.type = type; - this.loc = loc; - this.arguments = arguments; - } - - string getMsg() - { - char[] msg = messages[id]; - - if (arguments.length == 0) - return msg; - - foreach (i, arg; arguments) - msg = replace(msg, format("{%s}", i+1), arg); - - return msg; - } -} - class Lexer { Token token; @@ -76,7 +34,7 @@ char[] fileName; - Problem[] errors; + Information[] errors; Identifier[string] idtable; @@ -1482,7 +1440,7 @@ return args; } - errors ~= new Problem(Problem.Type.Lexer, id, loc, arguments(_arguments, _argptr)); + errors ~= new Information(Information.Type.Lexer, id, loc, arguments(_arguments, _argptr)); } public TOK nextToken() diff -r 7eb83dd38901 -r 24db7c5522d5 trunk/src/Parser.d --- a/trunk/src/Parser.d Sun Jul 01 12:18:02 2007 +0000 +++ b/trunk/src/Parser.d Sun Jul 01 13:53:00 2007 +0000 @@ -3,6 +3,7 @@ License: GPL2 +/ module Parser; +import Lexer; enum STC { @@ -21,5 +22,6 @@ class Parser { - + private Lexer lx; + alias lx.nextToken nextToken; } diff -r 7eb83dd38901 -r 24db7c5522d5 trunk/src/main.d --- a/trunk/src/main.d Sun Jul 01 12:18:02 2007 +0000 +++ b/trunk/src/main.d Sun Jul 01 13:53:00 2007 +0000 @@ -3,6 +3,7 @@ License: GPL2 +/ module dparser; +import Parser; import Lexer; import Token; import Messages;