Skip to content

Commit

Permalink
Merge pull request #27 from AlexHaxe/more_permanent_temp_store
Browse files Browse the repository at this point in the history
fixed missing modifiers in conditionals
  • Loading branch information
AlexHaxe authored Jul 16, 2018
2 parents def330f + 8dd1360 commit 6424dbb
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 77 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
## dev branch / next version (1.x.x)

## version 1.0.6 (2018-07-16)

- Added `TokenTreeCheckUtils.isTypeEnumAbstract` [#16](https://github.com/HaxeCheckstyle/tokentree/issues/16)
- Added FieldUtils [#17](https://github.com/HaxeCheckstyle/tokentree/issues/17)
- Added `isComment` and `isCIdent` to `TokentTreeAccessHelper` [#23](https://github.com/HaxeCheckstyle/tokentree/issues/23)
- Added `TokenTreeCheckUtils.isOpGtTypedefExtension` [#24](https://github.com/HaxeCheckstyle/tokentree/issues/24)
- Added `TokenTreeCheckUtils.isBrOpenAnonTypeOrTypedef` [#26](https://github.com/HaxeCheckstyle/tokentree/issues/26)
- Added `tempStore` to `TokenStream` [#27](https://github.com/HaxeCheckstyle/tokentree/issues/27)
- Fixed `@:default` [#18](https://github.com/HaxeCheckstyle/tokentree/issues/18)
- Fixed position of `cast` children [#19](https://github.com/HaxeCheckstyle/tokentree/issues/19)
- Fixed position of comments in `case`/`default` [#20](https://github.com/HaxeCheckstyle/tokentree/issues/20)
- Fixed error handling to work with `--no-inline` [#21](https://github.com/HaxeCheckstyle/tokentree/issues/21)
- Fixed position of BinOp() in anon objects [#22](https://github.com/HaxeCheckstyle/tokentree/issues/22)
- Fixed ternary handling [#25](https://github.com/HaxeCheckstyle/tokentree/issues/25)
- Changed isImport to also incluide `using` [#20](https://github.com/HaxeCheckstyle/tokentree/issues/20)
- Fixed missing modifiers in conditionals [#27](https://github.com/HaxeCheckstyle/tokentree/issues/27)
- Changed `isImport` to also incluide `using` [#20](https://github.com/HaxeCheckstyle/tokentree/issues/20)

## version 1.0.5 (2018-07-08)

Expand Down
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"contributors": [
"AlexHaxe"
],
"releasenote": "Added support for some Haxe 4 syntax changes - see CHANGELOG",
"version": "1.0.5",
"releasenote": "Added helper functions TokenTreeCheckUtils and bugfixes - see CHANGELOG",
"version": "1.0.6",
"url": "https://github.com/HaxeCheckstyle/tokentree",
"dependencies": {}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tokentree",
"version": "1.0.5",
"version": "1.0.6",
"description": "TokenTree library used by haxe-checkstyle",
"repository": {
"type": "git",
Expand Down
19 changes: 19 additions & 0 deletions src/tokentree/TokenStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TokenStream {
var bytes:ByteData;

var sharpIfStack:Array<TokenTree>;
var tempStore:Array<TokenTree> = [];

public function new(tokens:Array<Token>, bytes:ByteData) {
this.tokens = tokens;
Expand Down Expand Up @@ -81,6 +82,24 @@ class TokenStream {
}
}

public function consumeToTempStore() {
tempStore.push(consumeToken());
}

public function addToTempStore(token:TokenTree) {
tempStore.push(token);
}

public function applyTempStore(parent:TokenTree) {
while (tempStore.length > 0) {
parent.addChild(tempStore.shift());
}
}

public function getTempStore():Array<TokenTree> {
return tempStore;
}

public inline function error(s:String) {
throw formatCurrentPos() + ": " + s;
}
Expand Down
17 changes: 7 additions & 10 deletions src/tokentree/walk/WalkAbstract.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package tokentree.walk;

class WalkAbstract {
public static function walkAbstract(stream:TokenStream, parent:TokenTree, prefixes:Array<TokenTree>) {
public static function walkAbstract(stream:TokenStream, parent:TokenTree) {
var typeTok:TokenTree = stream.consumeToken();
parent.addChild(typeTok);
var name:TokenTree = WalkTypeNameDef.walkTypeNameDef(stream, typeTok);
// add all comments, annotations
for (prefix in prefixes) name.addChild(prefix);
stream.applyTempStore(name);
if (stream.is(POpen)) WalkPOpen.walkPOpen(stream, name);
var typeParent:TokenTree = name;
var typeChild:TokenTree;
Expand All @@ -31,29 +31,26 @@ class WalkAbstract {
}

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, parent, tempStore);
tempStore = [];
WalkVar.walkVar(stream, parent);
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, parent, tempStore);
tempStore = [];
WalkFunction.walkFunction(stream, parent);
case Sharp(_):
WalkSharp.walkSharp(stream, parent, WalkAbstract.walkAbstractBody);
case At:
tempStore.push(WalkAt.walkAt(stream));
stream.addToTempStore(WalkAt.walkAt(stream));
case BrClose: break;
case Semicolon:
parent.addChild(stream.consumeToken());
case Comment(_), CommentLine(_):
parent.addChild(stream.consumeToken());
default:
tempStore.push(stream.consumeToken());
stream.consumeToTempStore();
}
}
for (tok in tempStore) parent.addChild(tok);
stream.applyTempStore(parent);
}
}
24 changes: 8 additions & 16 deletions src/tokentree/walk/WalkArrayAccess.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,37 @@ class WalkArrayAccess {
public static function walkArrayAccess(stream:TokenStream, parent:TokenTree) {
var bkOpen:TokenTree = stream.consumeTokenDef(BkOpen);
parent.addChild(bkOpen);
var tempStore:Array<TokenTree> = [];
var progress:TokenStreamProgress = new TokenStreamProgress(stream);
while (progress.streamHasChanged()) {
switch (stream.token()) {
case Kwd(KwdFor):
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
stream.applyTempStore(bkOpen);
WalkFor.walkFor(stream, bkOpen);
case Kwd(KwdWhile):
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
stream.applyTempStore(bkOpen);
WalkWhile.walkWhile(stream, bkOpen);
case POpen:
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
stream.applyTempStore(bkOpen);
WalkPOpen.walkPOpen(stream, bkOpen);
case BrOpen:
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
stream.applyTempStore(bkOpen);
WalkBlock.walkBlock(stream, bkOpen);
case BkOpen:
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
stream.applyTempStore(bkOpen);
WalkArrayAccess.walkArrayAccess(stream, bkOpen);
case BkClose:
break;
case At:
tempStore.push(WalkAt.walkAt(stream));
stream.addToTempStore(WalkAt.walkAt(stream));
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, bkOpen, tempStore);
tempStore = [];
WalkFunction.walkFunction(stream, bkOpen);
case Comma:
var comma:TokenTree = stream.consumeTokenDef(Comma);
var child:TokenTree = bkOpen.getLastChild();
if (child == null) child = bkOpen;
child.addChild(comma);
default:
for (stored in tempStore) bkOpen.addChild(stored);
tempStore = [];
stream.applyTempStore(bkOpen);
WalkStatement.walkStatement(stream, bkOpen);
}
}
Expand Down
22 changes: 10 additions & 12 deletions src/tokentree/walk/WalkClass.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import tokentree.TokenTreeAccessHelper;

class WalkClass {

public static function walkClass(stream:TokenStream, parent:TokenTree, prefixes:Array<TokenTree>) {
public static function walkClass(stream:TokenStream, parent:TokenTree) {
var typeTok:TokenTree = stream.consumeToken();
parent.addChild(typeTok);
WalkComment.walkComment(stream, parent);
var name:TokenTree = WalkTypeNameDef.walkTypeNameDef(stream, typeTok);
// add all comments, annotations
for (prefix in prefixes) name.addChild(prefix);
stream.applyTempStore(name);
if (stream.isSharp()) WalkSharp.walkSharp(stream, name, WalkClass.walkClassExtends);
WalkClass.walkClassExtends(stream, name);
var block:TokenTree = stream.consumeTokenDef(BrOpen);
Expand All @@ -28,21 +28,18 @@ class WalkClass {
}

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, parent, tempStore);
tempStore = [];
WalkVar.walkVar(stream, parent);
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, parent, tempStore);
tempStore = [];
WalkFunction.walkFunction(stream, parent);
case Sharp(_):
WalkSharp.walkSharp(stream, parent, WalkClass.walkClassBody);
walkClassContinueAfterSharp(stream, parent);
case At:
tempStore.push(WalkAt.walkAt(stream));
stream.addToTempStore(WalkAt.walkAt(stream));
case BrClose: break;
case Semicolon:
parent.addChild(stream.consumeToken());
Expand All @@ -54,12 +51,12 @@ class WalkClass {
Kwd(KwdOverride),
Kwd(KwdDynamic),
Kwd(KwdExtern):
tempStore.push(stream.consumeToken());
stream.consumeToTempStore();
case Const(CIdent("final")):
tempStore.push(stream.consumeToken());
stream.consumeToTempStore();
// #if (haxe_ver >= 4.0)
// case Kwd(KwdFinal):
// tempStore.push(stream.consumeToken());
// stream.consumeToTempStore();
// #end
case Comment(_), CommentLine(_):
parent.addChild(stream.consumeToken());
Expand All @@ -70,9 +67,10 @@ class WalkClass {
}
}
}
var tempStore:Array<TokenTree> = stream.getTempStore();
if (tempStore.length > 0) {
switch (TokenStream.MODE) {
case RELAXED: for (tok in tempStore) parent.addChild(tok);
case RELAXED: stream.applyTempStore(parent);
case STRICT: throw "invalid token tree structure - found:" + '$tempStore';
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/tokentree/walk/WalkEnum.hx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package tokentree.walk;

class WalkEnum {
public static function walkEnum(stream:TokenStream, parent:TokenTree, prefixes:Array<TokenTree>) {
public static function walkEnum(stream:TokenStream, parent:TokenTree) {
var typeTok:TokenTree = stream.consumeToken();
parent.addChild(typeTok);
if (stream.is(Kwd(KwdAbstract))) {
WalkAbstract.walkAbstract(stream, typeTok, prefixes);
WalkAbstract.walkAbstract(stream, typeTok);
return;
}
var name:TokenTree = WalkTypeNameDef.walkTypeNameDef(stream, typeTok);
// add all comments, annotations
for (prefix in prefixes) name.addChild(prefix);
stream.applyTempStore(name);
WalkBlock.walkBlock(stream, name);
}
}
12 changes: 5 additions & 7 deletions src/tokentree/walk/WalkFile.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package tokentree.walk;

class WalkFile {
public static function walkFile(stream:TokenStream, parent:TokenTree) {
var tempStore:Array<TokenTree> = [];
while (stream.hasMore()) {
switch (stream.token()) {
case Kwd(KwdPackage), Kwd(KwdImport), Kwd(KwdUsing):
for (stored in tempStore) parent.addChild(stored);
tempStore = [];
stream.applyTempStore(parent);
WalkPackageImport.walkPackageImport(stream, parent);
case Sharp(_):
WalkSharp.walkSharp(stream, parent, WalkFile.walkFile);
Expand All @@ -18,20 +16,20 @@ class WalkFile {
default:
}
case At:
tempStore.push(WalkAt.walkAt(stream));
stream.addToTempStore(WalkAt.walkAt(stream));
case Comment(_), CommentLine(_):
WalkComment.walkComment(stream, parent);
case Kwd(KwdClass), Kwd(KwdInterface), Kwd(KwdEnum), Kwd(KwdTypedef), Kwd(KwdAbstract):
WalkType.walkType(stream, parent, tempStore);
tempStore = [];
WalkType.walkType(stream, parent);
case PClose, BrClose, BkClose, Semicolon, Comma:
parent.addChild(stream.consumeToken());
case Kwd(KwdExtern), Kwd(KwdPrivate), Kwd(KwdPublic):
tempStore.push(stream.consumeToken());
stream.consumeToTempStore();
default:
WalkBlock.walkBlock(stream, parent);
}
}
var tempStore:Array<TokenTree> = stream.getTempStore();
for (stored in tempStore) {
switch (stored.tok) {
case Kwd(KwdExtern), Kwd(KwdPrivate), Kwd(KwdPublic), At:
Expand Down
4 changes: 2 additions & 2 deletions src/tokentree/walk/WalkFunction.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tokentree.walk;

class WalkFunction {
public static function walkFunction(stream:TokenStream, parent:TokenTree, prefixes:Array<TokenTree>) {
public static function walkFunction(stream:TokenStream, parent:TokenTree) {
var funcTok:TokenTree = stream.consumeTokenDef(Kwd(KwdFunction));
parent.addChild(funcTok);
WalkComment.walkComment(stream, funcTok);
Expand All @@ -17,7 +17,7 @@ class WalkFunction {
default:
name = WalkTypeNameDef.walkTypeNameDef(stream, funcTok);
}
for (stored in prefixes) name.addChild(stored);
stream.applyTempStore(name);
WalkComment.walkComment(stream, name);
WalkFunction.walkFunctionParameters(stream, name);
WalkComment.walkComment(stream, name);
Expand Down
17 changes: 7 additions & 10 deletions src/tokentree/walk/WalkInterface.hx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package tokentree.walk;

class WalkInterface {
public static function walkInterface(stream:TokenStream, parent:TokenTree, prefixes:Array<TokenTree>) {
public static function walkInterface(stream:TokenStream, parent:TokenTree) {
var typeTok:TokenTree = stream.consumeToken();
parent.addChild(typeTok);
// add name
var name:TokenTree = WalkTypeNameDef.walkTypeNameDef(stream, typeTok);
// add all comments, annotations
for (prefix in prefixes) name.addChild(prefix);
stream.applyTempStore(name);
WalkExtends.walkExtends(stream, name);
WalkImplements.walkImplements(stream, name);
var block:TokenTree = stream.consumeTokenDef(BrOpen);
Expand All @@ -17,29 +17,26 @@ class WalkInterface {
}

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, parent, tempStore);
tempStore = [];
WalkVar.walkVar(stream, parent);
case Kwd(KwdFunction):
WalkFunction.walkFunction(stream, parent, tempStore);
tempStore = [];
WalkFunction.walkFunction(stream, parent);
case Sharp(_):
WalkSharp.walkSharp(stream, parent, WalkInterface.walkInterfaceBody);
case At:
tempStore.push(WalkAt.walkAt(stream));
stream.addToTempStore(WalkAt.walkAt(stream));
case BrClose: break;
case Semicolon:
parent.addChild(stream.consumeToken());
case Comment(_), CommentLine(_):
parent.addChild(stream.consumeToken());
default:
tempStore.push(stream.consumeToken());
stream.consumeToTempStore();
}
}
for (tok in tempStore) parent.addChild(tok);
stream.applyTempStore(parent);
}
}
Loading

0 comments on commit 6424dbb

Please sign in to comment.