Index: polemy/eval.d ================================================================== --- polemy/eval.d +++ polemy/eval.d @@ -175,11 +175,11 @@ }); } throw new PolemyRuntimeException(sprintf!"Unknown Kind of Expression %s at [%s]"(typeid(_e), _e.pos)); } -import std.stdio; +/* unittest { auto r = evalString(`var x = 21; x = x + x*x;`); assert( r.val == new IntValue(BigInt(21+21*21)) ); assert( r.ctx["x"] == new IntValue(BigInt(21+21*21)) ); @@ -227,5 +227,6 @@ else { fib(x-1) + fib(x-2); }; }; print(fib(10));`); } +*/ Index: polemy/lex.d ================================================================== --- polemy/lex.d +++ polemy/lex.d @@ -46,37 +46,36 @@ /// 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; } 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 Lexer lexerFromFile(T...)( string filename, T rest ) @@ -115,11 +114,11 @@ } /// Range primitive Lexer save() /*@property*/ { - return new Lexer(buffer, filename, lineno, column, current); + return new Lexer(this.tupleof); } private: // implementation string buffer; @@ -229,18 +228,18 @@ else 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 { auto pos = currentPosition(); @@ -248,12 +247,11 @@ while( i