Index: main.d ================================================================== --- main.d +++ main.d @@ -1,9 +1,10 @@ -/* - * Author: k.inaba +/** + * Authors: k.inaba * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Entry point for the polemy interpreter + * + * Entry point for Polemy interpreter. */ import std.stdio; import polemy.lex; import polemy.parse; Index: polemy/_common.d ================================================================== --- polemy/_common.d +++ polemy/_common.d @@ -1,13 +1,13 @@ -module polemy._common; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * "Always-opend" modules inside polemy +/** + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * "Always-opend" modules inside Polemy. */ - +module polemy._common; public import std.array; public import std.range; public import std.algorithm; public import std.conv : to; public import std.bigint; public import polemy.tricks; Index: polemy/ast.d ================================================================== --- polemy/ast.d +++ polemy/ast.d @@ -1,13 +1,13 @@ -module polemy.ast; -import polemy._common; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Syntax tree for the polemy programming language +/* + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * Syntax tree for Polemy programming language. */ - +module polemy.ast; +import polemy._common; import polemy.lex : LexPosition; alias Statement[] Program; abstract class Statement Index: polemy/eval.d ================================================================== --- polemy/eval.d +++ polemy/eval.d @@ -1,12 +1,13 @@ -module polemy.eval; -import polemy._common; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Evaluator for the polemy programming language +/** + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * Evaluator for Polemy programming language. */ +module polemy.eval; +import polemy._common; import polemy.ast; import polemy.runtime; Context eval(Program prog) { Index: polemy/lex.d ================================================================== --- polemy/lex.d +++ polemy/lex.d @@ -1,24 +1,25 @@ +/** + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * Lexer for Polemy programming language. + */ module polemy.lex; import polemy._common; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Lexer for the polemy programming language - */ import std.file : readText; import std.string : munch; import std.ctype; /// Represents a position in a source code class LexPosition { - immutable string filename; ///< name of the source file - immutable int lineno; ///< line number: 1, 2, ... - immutable int column; ///< column: 1, 2, ... + immutable string filename; /// name of the source file + immutable int lineno; /// line number, 1, 2, ... + immutable int column; /// column, 1, 2, ... override string toString() const { return sprintf!"%s:%d:%d"(filename, lineno, column); } mixin SimpleConstructor; @@ -46,13 +47,13 @@ /// Represents a lexer token class Token { enum Kind {identifier, stringLiteral, number}; - immutable LexPosition pos; ///< position where the token occurred in the source - immutable string str; ///< the token string itself - immutable Kind kind; ///< which kind of token? + immutable LexPosition pos; /// position where the token occurred in the source + immutable string str; /// the token string itself + immutable Kind kind; /// which kind of token? mixin SimpleConstructor; mixin SimpleCompare; } @@ -86,27 +87,31 @@ } /// Lexer is a forward range of Tokens class Lexer -{ +{ + /// Range primitive bool empty() /*@property*/ { return current is null; } + /// Range primitive Token front() /*@property*/ { return std.exception.enforce(current, "Lexer has already reached the end"); } + /// Range primitive void popFront() /*@property*/ { std.exception.enforce(current, "Lexer has already reached the end"); current = readNext(); } + /// Range primitive Lexer save() /*@property*/ { return new Lexer(buffer, filename, lineno, column, current); } @@ -328,27 +333,28 @@ unittest { //!! be sure to run the unittest on the root of the source directory auto lexf = lexerFromFile("polemy/lex.d"); + lexf = find!`a.str == "module"`(lexf); assert( lexf.front.str == "module", lexf.front.str ); assert( lexf.front.pos.filename == "polemy/lex.d" ); - assert( lexf.front.pos.lineno == 1 ); + assert( lexf.front.pos.lineno == 7 ); assert( lexf.front.pos.column == 1 ); lexf.popFront; assert( lexf.front.str == "polemy" ); - assert( lexf.front.pos.lineno == 1 ); + assert( lexf.front.pos.lineno == 7 ); assert( lexf.front.pos.column == 8 ); lexf.popFront; assert( lexf.front.str == "." ); lexf.popFront; assert( lexf.front.str == "lex" ); lexf.popFront; assert( lexf.front.str == ";" ); lexf.popFront; assert( lexf.front.str == "import" ); - assert( lexf.front.pos.lineno == 2 ); + assert( lexf.front.pos.lineno == 8 ); assert( lexf.front.pos.column == 1 ); } unittest { Index: polemy/parse.d ================================================================== --- polemy/parse.d +++ polemy/parse.d @@ -1,13 +1,13 @@ -module polemy.parse; -import polemy._common; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Parser for the polemy programming language +/* + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * Parser for Polemy programming language */ - +module polemy.parse; +import polemy._common; import polemy.lex; import polemy.ast; import std.bigint; /// Parsing Failure Index: polemy/runtime.d ================================================================== --- polemy/runtime.d +++ polemy/runtime.d @@ -1,12 +1,13 @@ -module polemy.runtime; -import polemy._common; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Runtime data structures for the polemy programming language +/** + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * Runtime data structures for Polemy programming language. */ +module polemy.runtime; +import polemy._common; class PolemyRuntimeException : Exception { this(string msg) { super(msg); } } Index: polemy/tricks.d ================================================================== --- polemy/tricks.d +++ polemy/tricks.d @@ -1,11 +1,12 @@ -module polemy.tricks; -/* - * Author: k.inaba - * License: NYSL 0.9982 (http://www.kmonos.net/nysl/ - * Tricks and utilities for D programming +/** + * Authors: k.inaba + * License: NYSL 0.9982 http://www.kmonos.net/nysl/ + * + * Common tricks and utilities for programming in D. */ +module polemy.tricks; static import std.array; static import std.format; /// Simple Wrapper for std.format.doFormat