Skip to content

Commit

Permalink
refactored Sharp(_) handling (#298)
Browse files Browse the repository at this point in the history
fixes #76, resolves #79, fixed #238 and resolved #252
  • Loading branch information
AlexHaxe authored Oct 8, 2016
1 parent 250c295 commit e24aec8
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 105 deletions.
3 changes: 3 additions & 0 deletions src/checkstyle/token/TokenStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class TokenStream {
if ((current < 0) || (current >= tokens.length)) throw NO_MORE_TOKENS;
var token:Token = tokens[current];
current++;
#if debugTokenTree
Sys.println (token);
#end
return new TokenTree(token.tok, token.pos, current - 1);
}

Expand Down
17 changes: 10 additions & 7 deletions src/checkstyle/token/walk/WalkAbstract.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ class WalkAbstract {
typeParent = typeChild;
}
}
var tempStore:Array<TokenTree> = [];
var block:TokenTree = stream.consumeTokenDef(BrOpen);
name.addChild(block);
WalkAbstract.walkAbstractBody(stream, block);
block.addChild(stream.consumeTokenDef(BrClose));
}

public static function walkAbstractBody(stream:TokenStream, parent:TokenTree) {
var tempStore:Array<TokenTree> = [];
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case Kwd(KwdVar):
WalkVar.walkVar(stream, block, tempStore);
WalkVar.walkVar(stream, parent, tempStore);
tempStore = [];
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, block, tempStore);
WalkFunction.walkFunction(stream, parent, tempStore);
tempStore = [];
case Sharp(_):
WalkSharp.walkSharp(stream, block);
WalkSharp.walkSharp(stream, parent, WalkAbstract.walkAbstractBody);
case At:
tempStore.push(WalkAt.walkAt(stream));
case BrClose: break;
case Semicolon:
block.addChild(stream.consumeToken());
parent.addChild(stream.consumeToken());
default:
tempStore.push(stream.consumeToken());
}
}
for (tok in tempStore) block.addChild(tok);
block.addChild(stream.consumeTokenDef(BrClose));
for (tok in tempStore) parent.addChild(tok);
}
}
29 changes: 19 additions & 10 deletions src/checkstyle/token/walk/WalkClass.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,44 @@ class WalkClass {
var name:TokenTree = WalkTypeNameDef.walkTypeNameDef(stream, typeTok);
// add all comments, annotations
for (prefix in prefixes) name.addChild(prefix);
if (stream.isSharp()) WalkSharp.walkSharp(stream, name);
if (stream.isSharp()) WalkSharp.walkSharp(stream, name, WalkClass.walkClassExtends);
WalkClass.walkClassExtends(stream, name);
var block:TokenTree = stream.consumeTokenDef(BrOpen);
name.addChild(block);
WalkClass.walkClassBody(stream, block);
block.addChild(stream.consumeTokenDef(BrClose));
}

public static function walkClassExtends(stream:TokenStream, name:TokenTree) {
WalkExtends.walkExtends(stream, name);
if (stream.isSharp()) WalkSharp.walkSharp(stream, name, WalkClass.walkClassExtends);
WalkImplements.walkImplements(stream, name);
if (stream.isSharp()) WalkSharp.walkSharp(stream, name, WalkClass.walkClassExtends);
WalkComment.walkComment(stream, name);
var tempStore:Array<TokenTree> = [];
var block:TokenTree = stream.consumeTokenDef(BrOpen);
name.addChild(block);
}

public static function walkClassBody(stream:TokenStream, parent:TokenTree) {
var tempStore:Array<TokenTree> = [];
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case Kwd(KwdVar):
WalkVar.walkVar(stream, block, tempStore);
WalkVar.walkVar(stream, parent, tempStore);
tempStore = [];
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, block, tempStore);
WalkFunction.walkFunction(stream, parent, tempStore);
tempStore = [];
case Sharp(_):
WalkSharp.walkSharp(stream, block);
WalkSharp.walkSharp(stream, parent, WalkClass.walkClassBody);
case At:
tempStore.push(WalkAt.walkAt(stream));
case BrClose: break;
case Semicolon:
block.addChild(stream.consumeToken());
parent.addChild(stream.consumeToken());
default:
tempStore.push(stream.consumeToken());
}
}
for (tok in tempStore) block.addChild(tok);
block.addChild(stream.consumeTokenDef(BrClose));
for (tok in tempStore) parent.addChild(tok);
}
}
1 change: 1 addition & 0 deletions src/checkstyle/token/walk/WalkComment.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import checkstyle.token.TokenTree;

class WalkComment {
public static function walkComment(stream:TokenStream, parent:TokenTree) {
if (!stream.hasMore()) return;
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
Expand Down
8 changes: 7 additions & 1 deletion src/checkstyle/token/walk/WalkFile.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ class WalkFile {
tempStore = [];
WalkPackageImport.walkPackageImport(stream, parent);
case Sharp(_):
WalkSharp.walkSharp(stream, parent);
WalkSharp.walkSharp(stream, parent, WalkFile.walkFile);
if (!stream.hasMore()) return;
switch (stream.token()) {
case BrOpen:
WalkBlock.walkBlock(stream, parent.childs[parent.childs.length - 1]);
default:
}
case At:
tempStore.push(WalkAt.walkAt(stream));
case Comment(_), CommentLine(_):
Expand Down
18 changes: 11 additions & 7 deletions src/checkstyle/token/walk/WalkInterface.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@ class WalkInterface {
for (prefix in prefixes) name.addChild(prefix);
WalkExtends.walkExtends(stream, name);
WalkImplements.walkImplements(stream, name);
var tempStore:Array<TokenTree> = [];
var block:TokenTree = stream.consumeTokenDef(BrOpen);
name.addChild(block);
WalkInterface.walkInterfaceBody(stream, block);
block.addChild(stream.consumeTokenDef(BrClose));
}

public static function walkInterfaceBody(stream:TokenStream, parent:TokenTree) {
var tempStore:Array<TokenTree> = [];
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case Kwd(KwdVar):
WalkVar.walkVar(stream, block, tempStore);
WalkVar.walkVar(stream, parent, tempStore);
tempStore = [];
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, block, tempStore);
WalkFunction.walkFunction(stream, parent, tempStore);
tempStore = [];
case Sharp(_):
WalkSharp.walkSharp(stream, block);
WalkSharp.walkSharp(stream, parent, WalkInterface.walkInterfaceBody);
case At:
tempStore.push(WalkAt.walkAt(stream));
case BrClose: break;
case Semicolon:
block.addChild(stream.consumeToken());
parent.addChild(stream.consumeToken());
default:
tempStore.push(stream.consumeToken());
}
}
for (tok in tempStore) block.addChild(tok);
block.addChild(stream.consumeTokenDef(BrClose));
for (tok in tempStore) parent.addChild(tok);
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/token/walk/WalkNew.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ class WalkNew {
var newTok:TokenTree = stream.consumeTokenDef(Kwd(KwdNew));
parent.addChild(newTok);
var name:TokenTree = WalkTypeNameDef.walkTypeNameDef(stream, newTok);

var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case Binop(OpGt):
var gt:TokenTree = stream.consumeTokenDef(Binop(OpGt));
name.addChild(gt);
default:
}
}
WalkPOpen.walkPOpen(stream, name);
}
}
18 changes: 11 additions & 7 deletions src/checkstyle/token/walk/WalkPOpen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@ class WalkPOpen {
public static function walkPOpen(stream:TokenStream, parent:TokenTree) {
var pOpen:TokenTree = stream.consumeTokenDef(POpen);
parent.addChild(pOpen);
WalkPOpen.walkPOpenParts(stream, pOpen);
pOpen.addChild(stream.consumeTokenDef(PClose));
}

public static function walkPOpenParts(stream:TokenStream, parent:TokenTree) {
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case POpen:
WalkPOpen.walkPOpen(stream, pOpen);
WalkPOpen.walkPOpen(stream, parent);
case BrOpen:
WalkObjectDecl.walkObjectDecl(stream, pOpen);
WalkObjectDecl.walkObjectDecl(stream, parent);
case BkOpen:
WalkArrayAccess.walkArrayAccess(stream, pOpen);
WalkArrayAccess.walkArrayAccess(stream, parent);
case PClose:
break;
case Sharp(_):
WalkSharp.walkSharp(stream, pOpen);
WalkSharp.walkSharp(stream, parent, WalkPOpen.walkPOpenParts);
case Comma:
var comma:TokenTree = stream.consumeToken();
pOpen.addChild(comma);
parent.addChild(comma);
default:
WalkStatement.walkStatement(stream, pOpen);
WalkStatement.walkStatement(stream, parent);
}
}
pOpen.addChild(stream.consumeTokenDef(PClose));
}
}
Loading

0 comments on commit e24aec8

Please sign in to comment.