@@ -7,9 +7,8 @@ module polemy.parse; import polemy._common; import polemy.lex; import polemy.ast; -import std.bigint; /// Parsing Failure class ParserException : Exception @@ -65,9 +64,9 @@ Program parseStatements() { Program p; - while( !lex.empty && (lex.front.kind!=Token.Kind.identifier || lex.front.str!="}") ) + while( !lex.empty && (lex.front.quoted || lex.front.str!="}") ) p ~= parseStatement(); return p; } @@ -79,9 +78,9 @@ if( lex.empty ) throw new ParserException("EOF during parsing a statement"); auto pos = lex.front.pos; - if( lex.front.kind==Token.Kind.identifier && lex.front.str=="var" ) + if( !lex.front.quoted && lex.front.str=="var" ) { // "var" Var "=" Expression ";" lex.popFront; string var = lex.front.str; @@ -180,18 +179,18 @@ if( lex.empty ) throw new ParserException("EOF during parsing an expression"); auto pos = lex.front.pos; - if( lex.front.kind == Token.Kind.number ) + if( lex.front.quoted ) + { + scope(exit) lex.popFront; + return new StrLiteralExpression(pos, lex.front.str); + } + if( isNumber(lex.front.str) ) // is_number { scope(exit) lex.popFront; return new IntLiteralExpression(pos, BigInt(cast(string)lex.front.str)); } - if( lex.front.kind == Token.Kind.stringLiteral ) - { - scope(exit) lex.popFront; - return new StrLiteralExpression(pos, lex.front.str); - } if( tryEat("(") ) { auto e = parseE(); eat(")", "after parenthesized expression"); @@ -230,9 +229,9 @@ if( lex.empty ) { auto e = ParserException.create(lex,"Unexpected EOF"); throw e; } - if( lex.front.kind != Token.Kind.identifier ) { + if( lex.front.quoted ) { auto e = ParserException.create(lex,"Identifier Expected for parameters"); throw e; } params ~= lex.front.str; @@ -271,13 +270,18 @@ } bool tryEat(string kwd) { - if( lex.empty || lex.front.kind!=Token.Kind.identifier || lex.front.str!=kwd ) + if( lex.empty || lex.front.quoted || lex.front.str!=kwd ) return false; lex.popFront; return true; } + + bool isNumber(string s) + { + return find!(`a<'0'||'9'