Diff
Not logged in

Differences From Artifact [bee9af8d0f8f7348]:

To Artifact [50586221a28fd499]:


9 9 import std.file : readText; 10 10 import std.ctype : isspace, isalnum; 11 11 12 12 /// Exception from this module 13 13 14 14 class LexException : Exception 15 15 { 16 - this( const LexPosition pos, string msg ) 17 - { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } 18 16 const LexPosition pos; 17 + 18 + private this( const LexPosition pos, string msg ) 19 + { super(sprintf!"%s [%s]"(msg, pos)); this.pos = pos; } 19 20 }; 20 21 21 22 /// Represents a position in a source code 22 23 23 24 class LexPosition 24 25 { 25 26 immutable string filename; /// name of the source file 26 - immutable int lineno; /// line number, 1, 2, ... 27 - immutable int column; /// column, 1, 2, ... 27 + immutable int lineno; /// 1-origin 28 + immutable int column; /// 1-origin 28 29 29 30 override string toString() const 30 31 { return sprintf!"%s:%d:%d"(filename, lineno, column); } 31 32 32 33 mixin SimpleConstructor; 33 34 mixin SimpleCompare; 34 35 ................................................................................ 83 84 84 85 assert( !__traits(compiles, new Token) ); 85 86 assert( !__traits(compiles, t.pos=p) ); 86 87 assert( !__traits(compiles, t.str=789) ); 87 88 assert( !__traits(compiles, t.quoted=true) ); 88 89 } 89 90 90 -/// Named Construtor for Lexer 91 +/// Named Construtors for Lexer 91 92 92 93 auto lexerFromFile(T...)( string filename, T rest ) 93 94 { 94 95 return lexerFromString( std.file.readText(filename), filename, rest ); 95 96 } 96 97 97 -/// Named Construtor for Lexer 98 - 99 98 auto lexerFromString(CharSeq)( CharSeq str, string filename="<unnamed>", int lineno=1, int column=1 ) 100 99 { 101 100 return new LexerT!(PositionedReader!CharSeq)( 102 101 PositionedReader!CharSeq(str, filename, lineno, column) 103 102 ); 104 103 } 105 104 106 -/// Standard Lexer Type (all users have to know is that this is a forward range of Tokens) 105 +/// Standard Lexer Type (all you have to know is that this is a forward range of Tokens) 107 106 108 107 alias LexerT!(PositionedReader!string) Lexer; 109 108 110 109 /// Lexer Implementation 111 110 112 111 class LexerT(Reader) 113 112 if( isForwardRange!(Reader) && is(ElementType!(Reader) == dchar) )