@@ -47,17 +47,11 @@ /// Represents a lexer token class Token { - /// currently we have three kinds of token - enum Kind { - identifier, /// anything other than others - stringLiteral, /// "string literal" - number /// 42 - }; - 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 bool quoted; /// Was it a "quoted" token or unquoted? mixin SimpleConstructor; mixin SimpleCompare; } @@ -64,18 +58,23 @@ unittest { auto p = new immutable(LexPosition)("hello.cpp", 123, 45); - auto t = new Token(p, "class", Token.Kind.identifier); + auto t = new Token(p, "class", false); + auto u = new Token(p, "class", true); assert_eq( t.pos, p ); assert_eq( t.str, "class" ); - assert_eq( t, new Token(p, "class", Token.Kind.identifier) ); - assert_lt( t, new Token(p, "struct", Token.Kind.identifier) ); + assert( !t.quoted ); + assert_eq( t, new Token(p, "class", false) ); + assert_lt( t, new Token(p, "struct", false) ); + assert_ne( t, u ); + assert( u.quoted ); assert( !__traits(compiles, new Token) ); assert( !__traits(compiles, t.pos=p) ); - assert( !__traits(compiles, t.str=789) ); + assert( !__traits(compiles, t.str=789) ); + assert( !__traits(compiles, t.quoted=true) ); } /// Named Construtor for Lexer @@ -116,9 +115,9 @@ /// Range primitive Lexer save() /*@property*/ { - return new Lexer(buffer, filename, lineno, column, current); + return new Lexer(this.tupleof); } private: // implementation @@ -230,16 +229,16 @@ lit ~= c; } if( !buffer.empty ) readChar(); - return new Token(pos, lit, Token.Kind.stringLiteral); + return new Token(pos, lit, true); } else { // normal symbol auto pos = currentPosition(); auto str = ""~readChar(); - return new Token(pos, str, Token.Kind.identifier); + return new Token(pos, str, false); } } else { @@ -249,10 +248,9 @@ ++i; auto str = buffer[0 .. i]; buffer = buffer[i .. $]; column += i; - bool isNumber = find!(`a<'0' || '9'