Diff
Not logged in

Differences From Artifact [caf474d107a1f8cb]:

To Artifact [4e484112cd314d8d]:


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