diff --git a/lib/std/special/docs/main.js b/lib/std/special/docs/main.js index 9ec0b65c9b..7cf9396785 100644 --- a/lib/std/special/docs/main.js +++ b/lib/std/special/docs/main.js @@ -47,6 +47,16 @@ var typeKinds = indexTypeKinds(); var typeTypeId = findTypeTypeId(); var pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 }; + var tokenKinds = { + Keyword: 'tok-kw', + String: 'tok-str', + Builtin: 'tok-builtin', + Comment: 'tok-comment', + Function: 'tok-fn', + Null: 'tok-null', + Number: 'tok-number', + Type: 'tok-type', + }; // for each package, is an array with packages to get to this one var canonPkgPaths = computeCanonicalPackagePaths(); @@ -537,18 +547,10 @@ var fnObj = zigAnalysis.fns[value]; return typeIndexName(fnObj.type, wantHtml, wantLink); case typeKinds.Int: - if (wantHtml) { - return '' + value + ''; - } else { - return value + ""; - } + return token(value, tokenKinds.Number, wantHtml); case typeKinds.Optional: if(value === 'null'){ - if (wantHtml) { - return '' + value + ''; - } else { - return value + ""; - } + return token(value, tokenKinds.Null, wantHtml); } else { console.trace("TODO non-null optional value printing"); return "TODO"; @@ -563,11 +565,7 @@ switch (typeObj.kind) { case typeKinds.Array: var name = "["; - if (wantHtml) { - name += '' + typeObj.len + ''; - } else { - name += typeObj.len; - } + name += token(typeObj.len, tokenKinds.Number, wantHtml); name += "]"; name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null); return name; @@ -591,111 +589,48 @@ break; } if (typeObj['const']) { - if (wantHtml) { - name += 'const '; - } else { - name += "const "; - } + name += token('const', tokenKinds.Keyword, wantHtml) + ' '; } if (typeObj['volatile']) { - if (wantHtml) { - name += 'volatile '; - } else { - name += "volatile "; - } + name += token('volatile', tokenKinds.Keyword, wantHtml) + ' '; } if (typeObj.align != null) { - if (wantHtml) { - name += 'align('; - } else { - name += "align("; - } - if (wantHtml) { - name += '' + typeObj.align + ''; - } else { - name += typeObj.align; - } + name += token('align', tokenKinds.Keyword, wantHtml) + '('; + name += token(typeObj.align, tokenKinds.Number, wantHtml); + if (typeObj.hostIntBytes != null) { name += ":"; - if (wantHtml) { - name += '' + typeObj.bitOffsetInHost + ''; - } else { - name += typeObj.bitOffsetInHost; - } + name += token(typeObj.bitOffsetInHost, tokenKinds.Number, wantHtml); name += ":"; - if (wantHtml) { - name += '' + typeObj.hostIntBytes + ''; - } else { - name += typeObj.hostIntBytes; - } + name += token(typeObj.hostIntBytes, tokenKinds.Number, wantHtml); } name += ") "; } name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null); return name; case typeKinds.Float: - if (wantHtml) { - return 'f' + typeObj.bits + ''; - } else { - return "f" + typeObj.bits; - } + return token('f' + typeObj.bits, tokenKinds.Type, wantHtml); case typeKinds.Int: var signed = (typeObj.i != null) ? 'i' : 'u'; var bits = typeObj[signed]; - if (wantHtml) { - return '' + signed + bits + ''; - } else { - return signed + bits; - } + return token(signed + bits, tokenKinds.Type, wantHtml); case typeKinds.ComptimeInt: - if (wantHtml) { - return 'comptime_int'; - } else { - return "comptime_int"; - } + return token('comptime_int', tokenKinds.Type, wantHtml); case typeKinds.ComptimeFloat: - if (wantHtml) { - return 'comptime_float'; - } else { - return "comptime_float"; - } + return token('comptime_float', tokenKinds.Type, wantHtml); case typeKinds.Type: - if (wantHtml) { - return 'type'; - } else { - return "type"; - } + return token('type', tokenKinds.Type, wantHtml); case typeKinds.Bool: - if (wantHtml) { - return 'bool'; - } else { - return "bool"; - } + return token('bool', tokenKinds.Type, wantHtml); case typeKinds.Void: - if (wantHtml) { - return 'void'; - } else { - return "void"; - } + return token('void', tokenKinds.Type, wantHtml); case typeKinds.EnumLiteral: - if (wantHtml) { - return '(enum literal)'; - } else { - return "(enum literal)"; - } + return token('(enum literal)', tokenKinds.Type, wantHtml); case typeKinds.NoReturn: - if (wantHtml) { - return 'noreturn'; - } else { - return "noreturn"; - } + return token('noreturn', tokenKinds.Type, wantHtml); case typeKinds.ErrorSet: if (typeObj.errors == null) { - if (wantHtml) { - return 'anyerror'; - } else { - return "anyerror"; - } + return token('anyerror', tokenKinds.Type, wantHtml); } else { if (wantHtml) { return escapeHtml(typeObj.name); @@ -756,19 +691,11 @@ } if (paramNode.noalias) { - if (wantHtml) { - payloadHtml += 'noalias '; - } else { - payloadHtml += 'noalias '; - } + payloadHtml += token('noalias', tokenKinds.Keyword, wantHtml) + ' '; } if (paramNode.comptime) { - if (wantHtml) { - payloadHtml += 'comptime '; - } else { - payloadHtml += 'comptime '; - } + payloadHtml += token('comptime', tokenKinds.Keyword, wantHtml) + ' '; } var paramName = paramNode.name; @@ -784,10 +711,8 @@ payloadHtml += '...'; } else if (argTypeIndex != null) { payloadHtml += typeIndexName(argTypeIndex, wantHtml, wantSubLink); - } else if (wantHtml) { - payloadHtml += 'var'; } else { - payloadHtml += 'var'; + payloadHtml += token('var', tokenKinds.Keyword, wantHtml); } } } @@ -795,10 +720,8 @@ payloadHtml += ') '; if (typeObj.ret != null) { payloadHtml += typeIndexName(typeObj.ret, wantHtml, wantSubLink, fnDecl); - } else if (wantHtml) { - payloadHtml += 'var'; } else { - payloadHtml += 'var'; + payloadHtml += token('var', tokenKinds.Keyword, wantHtml); } return payloadHtml; default: @@ -1973,4 +1896,12 @@ return key; } } + + function token(value, tokenClass, wantHtml){ + if(wantHtml){ + return '' + value + ''; + } else { + return value + ''; + } + } })();