Diff
Not logged in

Differences From Artifact [caf474d107a1f8cb]:

To Artifact [4e484112cd314d8d]:


5 5 * Lexer for Polemy programming language. 6 6 */ 7 7 module polemy.lex; 8 8 import polemy._common; 9 9 import std.file : readText; 10 10 import std.ctype : isspace, isalnum; 11 11 12 -/// Exception from this module 13 - 14 12 /*mixin*/ 15 13 template ExceptionWithPosition() 16 14 { 17 15 const LexPosition pos; 18 16 this( const LexPosition pos, string msg, string file=null, size_t line=0, Throwable next=null ) 19 17 { super(sprintf!"[%s] %s"(pos, msg), file, line, next); this.pos = pos; } 20 18 } 21 19 20 +/// 22 21 class UnexpectedEOF : Exception 23 22 { 24 23 mixin ExceptionWithPosition; 25 24 } 26 25 26 +/// 27 27 class LexException : Exception 28 28 { 29 29 mixin ExceptionWithPosition; 30 30 }; 31 31 32 32 /// Represents a position in a source code 33 33 ................................................................................ 93 93 assert( !__traits(compiles, t.pos=p) ); 94 94 assert( !__traits(compiles, t.str=789) ); 95 95 assert( !__traits(compiles, t.quoted=true) ); 96 96 } 97 97 98 98 /// Named Construtors for Lexer 99 99 100 -auto lexerFromFile(T...)( string filename, T rest ) 100 +Lexer lexerFromFile(T...)( string filename, T rest ) 101 101 { 102 102 return lexerFromString( std.file.readText(filename), filename, rest ); 103 103 } 104 104 105 -auto lexerFromString(CharSeq)( CharSeq str, string filename="<unnamed>", int lineno=1, int column=1 ) 105 +/// Named Construtors for Lexer 106 + 107 +LexerT!(PositionedReader!CharSeq) /* ddoc doesn't recognize auto return... bugzilla:2581 */ 108 +lexerFromString(CharSeq)( CharSeq str, string filename="<unnamed>", int lineno=1, int column=1 ) 106 109 { 107 110 return new LexerT!(PositionedReader!CharSeq)( 108 111 PositionedReader!CharSeq(str, filename, lineno, column) 109 112 ); 110 113 } 111 114 112 115 /// Standard Lexer Type (all you have to know is that this is a forward range of Tokens)