@@ -12,20 +12,21 @@ /// Exception from this module class LexException : Exception { - this( const LexPosition pos, string msg ) - { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } const LexPosition pos; + + private this( const LexPosition pos, string msg ) + { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } }; /// 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 int lineno; /// 1-origin + immutable int column; /// 1-origin override string toString() const { return sprintf!"%s:%d:%d"(filename, lineno, column); } @@ -86,25 +87,23 @@ assert( !__traits(compiles, t.str=789) ); assert( !__traits(compiles, t.quoted=true) ); } -/// Named Construtor for Lexer +/// Named Construtors for Lexer auto lexerFromFile(T...)( string filename, T rest ) { return lexerFromString( std.file.readText(filename), filename, rest ); } -/// Named Construtor for Lexer - auto lexerFromString(CharSeq)( CharSeq str, string filename="", int lineno=1, int column=1 ) { return new LexerT!(PositionedReader!CharSeq)( PositionedReader!CharSeq(str, filename, lineno, column) ); } -/// Standard Lexer Type (all users have to know is that this is a forward range of Tokens) +/// Standard Lexer Type (all you have to know is that this is a forward range of Tokens) alias LexerT!(PositionedReader!string) Lexer; /// Lexer Implementation