|
| 1 | +package token.verify; |
| 2 | + |
| 3 | +import haxe.PosInfos; |
| 4 | + |
| 5 | +import massive.munit.Assert; |
| 6 | + |
| 7 | +import haxeparser.Data; |
| 8 | + |
| 9 | +class VerifyTokenTreeList implements IVerifyTokenTree { |
| 10 | + |
| 11 | + var tokens:Array<IVerifyTokenTree>; |
| 12 | + |
| 13 | + public function new(tokens:Array<IVerifyTokenTree>) { |
| 14 | + Assert.isNotNull(tokens); |
| 15 | + this.tokens = tokens; |
| 16 | + } |
| 17 | + |
| 18 | + public function filter(tok:TokenDef, ?pos:PosInfos):IVerifyTokenTree { |
| 19 | + var list:Array<IVerifyTokenTree> = []; |
| 20 | + for (token in tokens) { |
| 21 | + var child:IVerifyTokenTree = token.filter(tok, pos); |
| 22 | + if (!child.isEmpty()) list.push(child); |
| 23 | + } |
| 24 | + return new VerifyTokenTreeList(list); |
| 25 | + } |
| 26 | + |
| 27 | + public function childs(?pos:PosInfos):IVerifyTokenTree { |
| 28 | + var list:Array<IVerifyTokenTree> = []; |
| 29 | + for (token in tokens) { |
| 30 | + var childList:VerifyTokenTreeList = cast token.childs(pos); |
| 31 | + for (i in 0...childList.tokens.length) { |
| 32 | + list.push(childList.tokens[i]); |
| 33 | + } |
| 34 | + } |
| 35 | + return new VerifyTokenTreeList(list); |
| 36 | + } |
| 37 | + |
| 38 | + public function first(?pos:PosInfos):IVerifyTokenTree { |
| 39 | + Assert.isTrue (tokens.length >= 1, pos); |
| 40 | + return tokens[0]; |
| 41 | + } |
| 42 | + |
| 43 | + public function last(?pos:PosInfos):IVerifyTokenTree { |
| 44 | + Assert.isTrue (tokens.length >= 2, pos); |
| 45 | + return tokens[tokens.length - 1]; |
| 46 | + } |
| 47 | + |
| 48 | + public function at(index:Int, ?pos:PosInfos):IVerifyTokenTree { |
| 49 | + Assert.isTrue (tokens.length > index, pos); |
| 50 | + return tokens[index]; |
| 51 | + } |
| 52 | + |
| 53 | + public function count(num:Int, ?pos:PosInfos):IVerifyTokenTree { |
| 54 | + Assert.areEqual(num, tokens.length, pos); |
| 55 | + return this; |
| 56 | + } |
| 57 | + |
| 58 | + public function noChilds(?pos:PosInfos):IVerifyTokenTree { |
| 59 | + var list:Array<IVerifyTokenTree> = []; |
| 60 | + for (token in tokens) list.push (token.noChilds(pos)); |
| 61 | + return new VerifyTokenTreeList(list); |
| 62 | + } |
| 63 | + |
| 64 | + public function oneChild(?pos:PosInfos):IVerifyTokenTree { |
| 65 | + var list:Array<IVerifyTokenTree> = []; |
| 66 | + for (token in tokens) list.push (token.oneChild()); |
| 67 | + return new VerifyTokenTreeList(list); |
| 68 | + } |
| 69 | + |
| 70 | + public function childFirst(?pos:PosInfos):IVerifyTokenTree { |
| 71 | + var list:Array<IVerifyTokenTree> = []; |
| 72 | + for (token in tokens) list.push (token.childFirst(pos)); |
| 73 | + return new VerifyTokenTreeList(list); |
| 74 | + } |
| 75 | + |
| 76 | + public function childLast(?pos:PosInfos):IVerifyTokenTree { |
| 77 | + var list:Array<IVerifyTokenTree> = []; |
| 78 | + for (token in tokens) list.push (token.childLast(pos)); |
| 79 | + return new VerifyTokenTreeList(list); |
| 80 | + } |
| 81 | + |
| 82 | + public function childAt(index:Int, ?pos:PosInfos):IVerifyTokenTree { |
| 83 | + var list:Array<IVerifyTokenTree> = []; |
| 84 | + for (token in tokens) list.push (token.childAt(index, pos)); |
| 85 | + return new VerifyTokenTreeList(list); |
| 86 | + } |
| 87 | + |
| 88 | + public function childCount(count:Int, ?pos:PosInfos):IVerifyTokenTree { |
| 89 | + var list:Array<IVerifyTokenTree> = []; |
| 90 | + for (token in tokens) list.push (token.childCount(count, pos)); |
| 91 | + return new VerifyTokenTreeList(list); |
| 92 | + } |
| 93 | + |
| 94 | + public function childCountAtLeast(count:Int, ?pos:PosInfos):IVerifyTokenTree { |
| 95 | + var list:Array<IVerifyTokenTree> = []; |
| 96 | + for (token in tokens) list.push (token.childCountAtLeast(count, pos)); |
| 97 | + return new VerifyTokenTreeList(list); |
| 98 | + } |
| 99 | + |
| 100 | + public function is(tok:TokenDef, ?pos:PosInfos):IVerifyTokenTree { |
| 101 | + var list:Array<IVerifyTokenTree> = []; |
| 102 | + for (token in tokens) list.push (token.is(tok, pos)); |
| 103 | + return new VerifyTokenTreeList(list); |
| 104 | + } |
| 105 | + |
| 106 | + public function isComment(?pos:PosInfos):IVerifyTokenTree { |
| 107 | + var list:Array<IVerifyTokenTree> = []; |
| 108 | + for (token in tokens) list.push (token.isComment(pos)); |
| 109 | + return new VerifyTokenTreeList(list); |
| 110 | + } |
| 111 | + |
| 112 | + public function isEmpty(?pos:PosInfos):Bool { |
| 113 | + return ((tokens == null) || (tokens.length <= 0)); |
| 114 | + } |
| 115 | +} |
0 commit comments