# HG changeset patch # User Anders Johnsen # Date 1216669554 -7200 # Node ID 0ea5d2f3e96b04dd6d5f8c445a59c1f7b8dd107a # Parent ee202c72cd30bbdb5363da4470c0ccc59976915b Parsing "this" as constructor. Also removed regex from the test run program(seg fault - dmd???) diff -r ee202c72cd30 -r 0ea5d2f3e96b lexer/Keyword.d --- a/lexer/Keyword.d Mon Jul 21 21:32:20 2008 +0200 +++ b/lexer/Keyword.d Mon Jul 21 21:45:54 2008 +0200 @@ -45,6 +45,8 @@ "typeof" : Tok.Typeof, "sizeof" : Tok.Sizeof, "alias" : Tok.Alias, + "this" : Tok.This, +// "super" : Tok.Super, // control flow "if" : Tok.If, diff -r ee202c72cd30 -r 0ea5d2f3e96b lexer/Lexer.d --- a/lexer/Lexer.d Mon Jul 21 21:32:20 2008 +0200 +++ b/lexer/Lexer.d Mon Jul 21 21:45:54 2008 +0200 @@ -84,7 +84,7 @@ { case CharType.EOF: SLoc loc; - return Token(Tok.EOF, loc + 1, 0); + return Token(Tok.EOF, loc+1, 0); case CharType.Whitespace: position += 1; diff -r ee202c72cd30 -r 0ea5d2f3e96b lexer/Token.d --- a/lexer/Token.d Mon Jul 21 21:32:20 2008 +0200 +++ b/lexer/Token.d Mon Jul 21 21:45:54 2008 +0200 @@ -195,7 +195,7 @@ Void, - Struct, Function, Delegate, Class, + Struct, Function, Delegate, Class, This, Interface, Union, Typedef, Typeid, Typeof, Sizeof, Alias, @@ -290,6 +290,8 @@ Tok.Comma:"Comma", Tok.Return:"Return", Tok.Struct:"Struct", + Tok.Class:"Class", + Tok.This:"This", Tok.Colon:"Colon", Tok.Seperator:"Seperator", Tok.Cast:"Cast", diff -r ee202c72cd30 -r 0ea5d2f3e96b parser/Parser.d --- a/parser/Parser.d Mon Jul 21 21:32:20 2008 +0200 +++ b/parser/Parser.d Mon Jul 21 21:45:54 2008 +0200 @@ -101,7 +101,10 @@ else if ( isa(Tok.OpenParentheses) ) return parseFunc(type, iden, att); else - messages.report(UnexpectedTok, next().location).arg(next().getType); + { + auto n1 = next(); + messages.report(UnexpectedTok, n1.location).arg(n1.getType); + } return null; } t = peek(len); @@ -109,8 +112,12 @@ .arg(sm.getText(t.asRange)); while(len--) next(); - while(peek.type != Tok.Identifier) + while( !isa(Tok.Identifier) && !isa(Tok.EOF)) next(); + if ( isa(Tok.EOF ) ) + messages.report(UnexpectedTok, t.location) + .fatal(ExitLevel.Parser); + type = Id(peek); goto parseDeclAfterInvalidType; } @@ -356,8 +363,17 @@ while ( peek.isAttribute ) nes ~= parseAttribute(nes[$-1]); - auto m_decl = parseDecl(nes[$-1].a); - action.actOnClassMember(decl, m_decl); + switch(peek.type) + { + case Tok.This: + auto id = Id(next); + auto m_decl = parseFunc(iden, id, nes[$-1].a); + break; + + default: + auto m_decl = parseDecl(nes[$-1].a); + action.actOnClassMember(decl, m_decl); + } nes = parseAttributeScope(nes); } diff -r ee202c72cd30 -r 0ea5d2f3e96b tests/run.d --- a/tests/run.d Mon Jul 21 21:32:20 2008 +0200 +++ b/tests/run.d Mon Jul 21 21:45:54 2008 +0200 @@ -35,14 +35,14 @@ void main(char[][] args) { scope scan = new FileScan; - scope regex = new Regex(valid_filenames); +// scope regex = new Regex(valid_filenames); // DMD FAILS!! ?? // Return true for files/folders to include bool filter(FilePath p, bool isDir) { if (isDir) return p.name[0] != '.'; else - return p.ext == "d" && regex.test(p.name); + return p.ext == "d" ; //&& regex.test(p.name); } scan.sweep(test_folder, &filter, true); FilePath[] files = scan.files;