diff --git a/.gitignore b/.gitignore index dcbc9e7..38fefcd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ -bin/ /.vscode/.BROWSE.VC.DB -debug.log +bin node_modules +dump +*.log +*.vsix +haxelib/haxelib.zip diff --git a/.haxerc b/.haxerc index 8b6b442..ba312cf 100644 --- a/.haxerc +++ b/.haxerc @@ -1,4 +1,4 @@ { - "version": "4.0.5", + "version": "a443fd3", "resolveLibs": "scoped" -} \ No newline at end of file +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 9a15fa9..8cfa388 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "haxe.executable": "auto", "[haxe]": { "editor.formatOnSave": true, "editor.formatOnPaste": true diff --git a/README.md b/README.md index 19bcf23..88f09a5 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,6 @@ This is a VSCode extension that exists solely to aid the development of the [vsh ## Features -- **hxparser Syntax Tree Visualizer** - - The `hxparser: Visualize` commands opens a new editor to the side that displays the [hxparser](https://github.com/vshaxe/hxparser) / [](https://github.com/vshaxe/haxe-hxparser) parse tree for the current Haxe source file. Selecting tokens in the source will scroll to the appropriate position in the tree, and selecting tokens in the tree will highlight the token in the source. - - ![](images/visualizer.gif) - - When changing the file, the tree is updated with [haxe-languageserver](https://github.com/vshaxe/haxe-languageserver)'s internal parse tree (obtained through incremental parsing). - - It's also possible to view the original JSON response from hxparser or to view the parse tree re-printed as Haxe code. - - **haxe-formatter test file highlighting** [haxe-formatter](https://github.com/vshaxe/haxe-formatter) uses a custom `.hxtest` file extension for unit test definitions. These files are highlighted by the debug tools: @@ -40,4 +30,4 @@ This is a VSCode extension that exists solely to aid the development of the [vsh npx lix run vshaxe-build --target all ``` -6. After modifying and rebuilding the extension itself, restart VSCode, reload the window or run a debug instance with F5 ([standard vscode workflow](https://code.visualstudio.com/docs/extensions/debugging-extensions)). \ No newline at end of file +6. After modifying and rebuilding the extension itself, restart VSCode, reload the window or run a debug instance with F5 ([standard vscode workflow](https://code.visualstudio.com/docs/extensions/debugging-extensions)). diff --git a/haxe_libraries/haxe-hxparser.hxml b/haxe_libraries/haxe-hxparser.hxml deleted file mode 100644 index e1aa0ab..0000000 --- a/haxe_libraries/haxe-hxparser.hxml +++ /dev/null @@ -1,3 +0,0 @@ --D haxe-hxparser=0.0.1 -# @install: lix --silent download "gh://github.com/vshaxe/haxe-hxparser#b27d7939dce2b6bc12a3d0b7e7dcca435f1ea125" into haxe-hxparser/0.0.1/github/b27d7939dce2b6bc12a3d0b7e7dcca435f1ea125 --cp ${HAXE_LIBCACHE}/haxe-hxparser/0.0.1/github/b27d7939dce2b6bc12a3d0b7e7dcca435f1ea125/src diff --git a/haxe_libraries/haxeparser.hxml b/haxe_libraries/haxeparser.hxml index d64f1f6..ef79630 100644 --- a/haxe_libraries/haxeparser.hxml +++ b/haxe_libraries/haxeparser.hxml @@ -1,4 +1,4 @@ --D haxeparser=3.3.0 -# @install: lix --silent download "gh://github.com/Simn/haxeparser#48160b190cacafb0003d0c8d085dca2c85e21e31" into haxeparser/3.3.0/github/48160b190cacafb0003d0c8d085dca2c85e21e31 +# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#7e98c9aef901b8e26541cf3f8a6e1da0385b237a" into haxeparser/4.3.0-rc.1/github/7e98c9aef901b8e26541cf3f8a6e1da0385b237a -lib hxparse --cp ${HAXE_LIBCACHE}/haxeparser/3.3.0/github/48160b190cacafb0003d0c8d085dca2c85e21e31/src +-cp ${HAXE_LIBCACHE}/haxeparser/4.3.0-rc.1/github/7e98c9aef901b8e26541cf3f8a6e1da0385b237a/src +-D haxeparser=4.3.0-rc.1 diff --git a/haxe_libraries/hxnodejs.hxml b/haxe_libraries/hxnodejs.hxml index 483b01c..41f1257 100644 --- a/haxe_libraries/hxnodejs.hxml +++ b/haxe_libraries/hxnodejs.hxml @@ -1,6 +1,7 @@ --D hxnodejs=10.0.0 -# @install: lix --silent download "haxelib:/hxnodejs#10.0.0" into hxnodejs/10.0.0/haxelib --cp ${HAXE_LIBCACHE}/hxnodejs/10.0.0/haxelib/src ---macro allowPackage('sys') -# should behave like other target defines and not be defined in macro context ---macro define('nodejs') +-D hxnodejs=12.1.0 +# @install: lix --silent download "haxelib:/hxnodejs#12.1.0" into hxnodejs/12.1.0/haxelib +-cp ${HAXE_LIBCACHE}/hxnodejs/12.1.0/haxelib/src +--macro allowPackage('sys') +# should behave like other target defines and not be defined in macro context +--macro define('nodejs') +--macro _internal.SuppressDeprecated.run() diff --git a/haxe_libraries/hxparse.hxml b/haxe_libraries/hxparse.hxml index 2ac3804..4eab137 100644 --- a/haxe_libraries/hxparse.hxml +++ b/haxe_libraries/hxparse.hxml @@ -1,3 +1,3 @@ --D hxparse=4.0.0 -# @install: lix --silent download "gh://github.com/Simn/hxparse#53b79171d36c1146ca349e48b7b69885be5e0024" into hxparse/4.0.0/github/53b79171d36c1146ca349e48b7b69885be5e0024 --cp ${HAXE_LIBCACHE}/hxparse/4.0.0/github/53b79171d36c1146ca349e48b7b69885be5e0024/src +# @install: lix --silent download "gh://github.com/simn/hxparse#32e376f80c4b0e999e9f3229947d4dac2138382b" into hxparse/4.0.1/github/32e376f80c4b0e999e9f3229947d4dac2138382b +-cp ${HAXE_LIBCACHE}/hxparse/4.0.1/github/32e376f80c4b0e999e9f3229947d4dac2138382b/src +-D hxparse=4.0.1 diff --git a/haxe_libraries/tokentree.hxml b/haxe_libraries/tokentree.hxml index ac52b3f..fd0702f 100644 --- a/haxe_libraries/tokentree.hxml +++ b/haxe_libraries/tokentree.hxml @@ -1,3 +1,3 @@ --D tokentree=1.0.28 -# @install: lix --silent download "gh://github.com/HaxeCheckstyle/tokentree#0b48308e5cec2daf8e721dc69835be1360272d8a" into tokentree/1.0.28/github/0b48308e5cec2daf8e721dc69835be1360272d8a --cp ${HAXE_LIBCACHE}/tokentree/1.0.28/github/0b48308e5cec2daf8e721dc69835be1360272d8a/src +# @install: lix --silent download "haxelib:/tokentree#1.2.10" into tokentree/1.2.10/haxelib +-cp ${HAXE_LIBCACHE}/tokentree/1.2.10/haxelib/src +-D tokentree=1.2.10 diff --git a/haxe_libraries/vscode.hxml b/haxe_libraries/vscode.hxml index aaea943..dc78193 100644 --- a/haxe_libraries/vscode.hxml +++ b/haxe_libraries/vscode.hxml @@ -1,4 +1,4 @@ --D vscode=1.35.0 -# @install: lix --silent download "haxelib:/vscode#1.35.0" into vscode/1.35.0/haxelib +-D vscode=1.60.0 +# @install: lix --silent download "haxelib:/vscode#1.60.0" into vscode/1.60.0/haxelib -lib hxnodejs --cp ${HAXE_LIBCACHE}/vscode/1.35.0/haxelib/src +-cp ${HAXE_LIBCACHE}/vscode/1.60.0/haxelib/src diff --git a/haxe_libraries/vshaxe-build.hxml b/haxe_libraries/vshaxe-build.hxml index 948705d..9d98694 100644 --- a/haxe_libraries/vshaxe-build.hxml +++ b/haxe_libraries/vshaxe-build.hxml @@ -1,4 +1,4 @@ -D vshaxe-build=0.0.1 -# @install: lix --silent download "gh://github.com/vshaxe/vshaxe-build#39ab9c6315ae76080e5399391c8fa561daec6d55" into vshaxe-build/0.0.1/github/39ab9c6315ae76080e5399391c8fa561daec6d55 -# @run: haxelib run-dir vshaxe-build ${HAXE_LIBCACHE}/vshaxe-build/0.0.1/github/39ab9c6315ae76080e5399391c8fa561daec6d55 --cp ${HAXE_LIBCACHE}/vshaxe-build/0.0.1/github/39ab9c6315ae76080e5399391c8fa561daec6d55/ +# @install: lix --silent download "gh://github.com/vshaxe/vshaxe-build#4ce362be7c300163470d618be2fb8fa98a616e49" into vshaxe-build/0.0.1/github/4ce362be7c300163470d618be2fb8fa98a616e49 +# @run: haxelib run-dir vshaxe-build ${HAXE_LIBCACHE}/vshaxe-build/0.0.1/github/4ce362be7c300163470d618be2fb8fa98a616e49 +-cp ${HAXE_LIBCACHE}/vshaxe-build/0.0.1/github/4ce362be7c300163470d618be2fb8fa98a616e49/ diff --git a/package-lock.json b/package-lock.json index 778977d..0a764e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,34 @@ { "name": "vshaxe-debug-tools", "version": "0.0.1", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "vshaxe-debug-tools", + "version": "0.0.1", + "hasInstallScript": true, + "devDependencies": { + "lix": "^15.5.3" + }, + "engines": { + "vscode": "^1.23.0" + } + }, + "node_modules/lix": { + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/lix/-/lix-15.5.3.tgz", + "integrity": "sha512-vrn+w6aS7X+rq+5cd3kyYZzXpjSXXu4mEMSNDA3g8wn0QV9mGeZHl62ej6dMHhEH7kYFWQCoFeyjLaHRKkXFpA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "haxe": "bin/haxeshim.js", + "haxelib": "bin/haxelibshim.js", + "lix": "bin/lix.js", + "neko": "bin/nekoshim.js" + } + } + }, "dependencies": { "lix": { "version": "15.5.3", diff --git a/package.json b/package.json index 5f5cc58..92672c5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "vscode": "^1.23.0" }, "devDependencies": { - "lix": "^15.5.3" + "lix": "^15.10.1" }, "scripts": { "postinstall": "npx lix download" @@ -19,7 +19,6 @@ "url": "https://github.com/vshaxe/vshaxe-debug-tools" }, "activationEvents": [ - "onCommand:vshaxeDebugTools.visualizeParseTree", "onCommand:vshaxeDebugTools.visualizeTokenTree", "onCommand:vshaxeDebugTools.methodResultsView.open", "onCommand:vshaxeDebugTools.methodResultsView.update", @@ -38,27 +37,11 @@ "onView:haxe.methods", "onView:haxe.cache", "onWebviewPanel:vshaxeDebugTools.tokenTree", - "onWebviewPanel:vshaxeDebugTools.parseTree", "workspaceContains:./*.hxml" ], "main": "bin/extension", "contributes": { - "configuration": { - "title": "Haxe Extension Debug Tools", - "properties": { - "hxparservis.path": { - "description": "Path to the hxparser executable. If not defined, an embedded js version is used.", - "type": "string", - "default": null - } - } - }, "commands": [ - { - "command": "vshaxeDebugTools.visualizeParseTree", - "title": "Visualize Parse Tree", - "category": "Haxe Extension Debug Tools" - }, { "command": "vshaxeDebugTools.visualizeTokenTree", "title": "Visualize TokenTree", diff --git a/src/Main.hx b/src/Main.hx index 42e73f1..d5a3ae8 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -1,6 +1,5 @@ package; -import features.vis.hxParserVis.HxParserVisFeature; import features.vis.tokenTreeVis.TokenTreeVisFeature; import vscode.*; import features.*; @@ -11,7 +10,6 @@ class Main { static function activate(context:ExtensionContext) { Vscode.commands.executeCommand("setContext", "vshaxeDebugToolsActivated", true); - new HxParserVisFeature(context); new TokenTreeVisFeature(context); new CursorOffsetFeature(context); new HxTestSeparatorFeature(context); diff --git a/src/features/vis/VisFeatureBase.hx b/src/features/vis/VisFeatureBase.hx index 1e675cf..2a95aaa 100644 --- a/src/features/vis/VisFeatureBase.hx +++ b/src/features/vis/VisFeatureBase.hx @@ -51,12 +51,6 @@ class VisFeatureBase> { update(); })); - context.subscriptions.push(commands.registerCommand('$viewType.updateParseTree', function(uri:String, parseTree:String) { - if (panel != null && provider.previousEditor != null && uri == provider.previousEditor.document.uri.toString()) { - panel.webview.html = haxe.Unserializer.run(parseTree); - } - })); - context.subscriptions.push(window.onDidChangeTextEditorSelection(function(e) { if (panel != null && e.textEditor == window.activeTextEditor) { panel.webview.postMessage(e.textEditor.document.offsetAt(e.textEditor.selection.anchor)); diff --git a/src/features/vis/hxParserVis/GenVis.hx b/src/features/vis/hxParserVis/GenVis.hx deleted file mode 100644 index 57f3dab..0000000 --- a/src/features/vis/hxParserVis/GenVis.hx +++ /dev/null @@ -1,252 +0,0 @@ -package features.vis.hxParserVis; - -#if macro -import haxe.macro.Context; -import haxe.macro.Expr; -import haxe.macro.Type; -import util.GenWalker.extractTypeName; -import util.GenWalker.getNullType; - -using haxe.macro.Tools; - -class GenVis { - static function gen() { - var root = Context.getType("hxParser.ParseTree.File"); - var fields = new Map(); - - genVis(macro v, root, root, fields, null); - - // Context.defineModule("hxParserVis.Vis", Lambda.array(fields)); - - var printer = new haxe.macro.Printer(); - var parts = [ - "package features.vis.hxParserVis;", - "import hxParser.ParseTree;", - "using StringTools;", - ]; - - var td = macro class Vis { - var ctx:SyntaxTreePrinter; - var offset:Int; - public function new(ctx) { - this.ctx = ctx; - offset = 0; - } - - public static var none = '<none>'; - - public function visToken(t:Token):String { - inline function renderPosition(start:Int, end:Int) { - return "[" + start + "-" + end + ")"; - } - - inline function renderTrivia(t:Trivia, prefix:String) { - var s = t.toString().htmlEscape(); - var start = offset; - var end = offset += t.text.length; - var id = ctx.registerPos(start, end); - var link = ctx.makeLink(start, end); - return '
  • ' + prefix + ': ' + s + " " + renderPosition(start, end) + '
  • '; - } - - var trivias = []; - if (t.leadingTrivia != null) { - for (t in t.leadingTrivia) - trivias.push(renderTrivia(t, "LEAD")); - } - - var start = offset; - var end = !t.appearsInSource() ? start : offset += t.text.length; - var link = ctx.makeLink(start, end); - var id = ctx.registerPos(start, end); - var selected = ctx.isUnderCursor(start, end); - - var s = t.toString().htmlEscape(); - var parts = [ - '' + s + " " + renderPosition(start, end) + - '' - ]; - - if (t.inserted) - parts.push('(missing)'); - if (t.implicit) - parts.push('(implicit)'); - - if (t.trailingTrivia != null) { - for (t in t.trailingTrivia) - trivias.push(renderTrivia(t, "TAIL")); - } - if (trivias.length > 0) - parts.push('"); - - return parts.join(" "); - } - - public function visArray(c:Array, vis:T->String):String { - var parts = [for (el in c) "
  • " + vis(el) + "
  • "]; - return if (parts.length == 0) none else "
      " + parts.join("") + "
    "; - } - - public function visCommaSeparated(c:CommaSeparated, vis:T->String):String { - var parts = [vis(c.arg)]; - for (el in c.args) { - parts.push(visToken(el.comma)); - parts.push(vis(el.arg)); - } - return "
      " + [for (s in parts) '
    • ' + s + '
    • '].join("") + "
    "; - } - - public function visCommaSeparatedTrailing(c:CommaSeparatedAllowTrailing, vis:T->String):String { - var parts = [vis(c.arg)]; - for (el in c.args) { - parts.push(visToken(el.comma)); - parts.push(vis(el.arg)); - } - if (c.comma != null) - parts.push(visToken(c.comma)); - return "
      " + [for (s in parts) '
    • ' + s + '
    • '].join("") + "
    "; - } - } - for (field in fields) - td.fields.push(field); - - parts.push(printer.printTypeDefinition(td)); - sys.io.File.saveContent("src/features/vis/hxParserVis/Vis.hx", parts.join("\n\n")); - } - - static function genVis(expr:Expr, type:Type, origType, fields:Map, name:Null):Expr { - switch (type) { - case TInst(_.get() => {pack: ["hxParser"], name: "Token"}, _): - return macro visToken($expr); - - case TInst(_.get() => {pack: [], name: "Array"}, [elemT]) if (name != null): - var visExpr = genVis(macro el, elemT, elemT, fields, name + "_elem"); - return macro visArray($expr, function(el) return $visExpr); - - case TType(_.get() => dt, params): - switch [dt, params] { - case [{pack: ["hxParser"], name: "CommaSeparated"}, [elemT]] if (name != null): - var visExpr = genVis(macro el, elemT, elemT, fields, name + "_elem"); - return macro visCommaSeparated($expr, function(el) return $visExpr); - - case [{pack: ["hxParser"], name: "CommaSeparatedAllowTrailing"}, [elemT]] if (name != null): - var visExpr = genVis(macro el, elemT, elemT, fields, name + "_elem"); - return macro visCommaSeparatedTrailing($expr, function(el) return $visExpr); - - case [{pack: [], name: "Null"}, _]: - throw "Null should be handled elsewhere."; - - default: - return genVis(expr, dt.type.applyTypeParameters(dt.params, params), origType, fields, dt.name); - } - - case TEnum(_.get() => en, _): - return genEnumVis(expr, en, origType, fields); - - case TAnonymous(_.get() => anon) if (name != null): - return genAnonVis(expr, anon, origType, fields, name); - - default: - } - throw 'TODO: ${type.toString()}'; - } - - static function genEnumVis(expr:Expr, en:EnumType, origType:Type, fields:Map):Expr { - var visName = "vis" + en.name; - if (!fields.exists(en.name)) { - fields.set(en.name, null); // TODO: this sucks - - var cases = []; - for (ctor in en.constructs) { - switch (ctor.type) { - case TFun(args, _): - var patternArgs = []; - var exprs = []; - for (arg in args) { - var name = arg.name; - patternArgs.push(macro var $name); - var local = macro $i{name}; - - var visExpr = switch (getNullType(arg.t)) { - case None: - genVis(local, arg.t, arg.t, fields, en.name + "_" + ctor.name + "_" + arg.name); - case Some(realT): - var e = genVis(local, realT, realT, fields, en.name + "_" + ctor.name + "_" + arg.name); - macro(if ($local != null) $e - else - none); - } - - exprs.push(macro $v{arg.name + ": "} + $visExpr); - } - - var argList = macro ${Lambda.fold(exprs, function(e, acc) return macro $acc + "
  • " + $e + "
  • ", macro "
      ")} + "
    "; - - cases.push({ - values: [macro $i{ctor.name} ($a{patternArgs})], - expr: macro $v{'${ctor.name}'} + $argList, - }); - - case TEnum(_): - cases.push({ - values: [macro $i{ctor.name}], - expr: macro $v{ctor.name} , - }); - - default: - throw false; - } - } - - var expr = {expr: ESwitch(macro v, cases, null), pos: en.pos}; - - var ct = extractTypeName(origType); - var field = (macro class { - public function $visName(v : $ct):String { - return $expr; - } - }).fields[0]; - - fields.set(en.name, field); - } - return macro $i{visName} ($expr); - } - - static function genAnonVis(expr:Expr, anon:AnonType, origType:Type, fields:Map, name:String):Expr { - var visName = 'vis$name'; - if (!fields.exists(name)) { - fields.set(name, null); // TODO: this sucks - - var exprs = []; - anon.fields.sort(function(a, b) return Context.getPosInfos(a.pos).min - Context.getPosInfos(b.pos).min); - for (field in anon.fields) { - var fname = field.name; - - var visExpr = switch (getNullType(field.type)) { - case None: - genVis(macro v.$fname, field.type, field.type, fields, name + "_" + fname); - case Some(realT): - var e = genVis(macro v.$fname, realT, realT, fields, name + "_" + fname); - macro(if (v.$fname != null) $e - else - none); - } - - exprs.push(macro $v{fname + ": "} + $visExpr); - } - - var expr = macro ${Lambda.fold(exprs, function(el, acc) return macro $acc + "
  • " + $el + "
  • ", macro "
      ")} + "
    "; - - var ct = extractTypeName(origType); - var field = (macro class { - public function $visName(v : $ct):String { - return $v{'${name}'}+ $expr; - } - }).fields[0]; - - fields.set(name, field); - } - return macro $i{visName} ($expr); - } -} -#end diff --git a/src/features/vis/hxParserVis/HxParserContentData.hx b/src/features/vis/hxParserVis/HxParserContentData.hx deleted file mode 100644 index 923363f..0000000 --- a/src/features/vis/hxParserVis/HxParserContentData.hx +++ /dev/null @@ -1,9 +0,0 @@ -package features.vis.hxParserVis; - -import hxParser.JResult; -import hxParser.ParseTree.File; - -typedef HxParserContentData = { - var unparsedData:JResult; - var parsedTree:File; -} diff --git a/src/features/vis/hxParserVis/HxParserContentProvider.hx b/src/features/vis/hxParserVis/HxParserContentProvider.hx deleted file mode 100644 index 89b04dd..0000000 --- a/src/features/vis/hxParserVis/HxParserContentProvider.hx +++ /dev/null @@ -1,50 +0,0 @@ -package features.vis.hxParserVis; - -import hxParser.HxParser; -import hxParser.HxParserCli; -import hxParser.JResult; -import hxParser.Converter; -import js.lib.Promise; -import util.Result; -import features.vis.ContentProviderBase; - -class HxParserContentProvider extends ContentProviderBase { - var outputKind:OutputKind = SyntaxTree; - - public function switchOutputKind(outputKind:OutputKind) { - this.outputKind = outputKind; - } - - override function printHtml(editor:String, fontFamily:String, fontSize:String):String { - return new HxParserHtmlPrinter().print(editor, content, currentNodePos, outputKind, fontFamily, fontSize); - } - - override function reparse():Promise { - return new Promise(function(resolve, reject) { - var editor = getActiveEditor(); - if (editor == null) - return; - - var src = editor.document.getText(); - - function handleResult(result:Result) - switch (result) { - case Success(data): - content = { - unparsedData: data, - parsedTree: new Converter(data).convertResultToFile() - } - resolve(rerender()); - case Failure(reason): - reject('hxparser failed: $reason'); - }; - - var hxparserPath = Vscode.workspace.getConfiguration("hxparservis").get("path"); - if (hxparserPath == null) { - handleResult(HxParser.parse(src)); - } else { - HxParserCli.parse(hxparserPath, src, handleResult); - } - }); - } -} diff --git a/src/features/vis/hxParserVis/HxParserHtmlPrinter.hx b/src/features/vis/hxParserVis/HxParserHtmlPrinter.hx deleted file mode 100644 index 7dd1799..0000000 --- a/src/features/vis/hxParserVis/HxParserHtmlPrinter.hx +++ /dev/null @@ -1,61 +0,0 @@ -package features.vis.hxParserVis; - -#if !macro -import hxParser.ParseTree.File; -import hxParser.Printer; -import features.vis.HtmlPrinterBase; -import features.vis.TreePrinterBase.TreePrinterResult; - -using StringTools; - -class HxParserHtmlPrinter extends HtmlPrinterBase { - public function print(uri:String, content:HxParserContentData, currentPos:Int, output:OutputKind, fontFamily:String, fontSize:String):String { - return switch (output) { - case SyntaxTree: printSyntaxTree(uri, content, currentPos, fontFamily, fontSize, makeLinks(output, true)); - case Haxe: printHaxe(content.parsedTree); - case Json: printJson(content.unparsedData, true); - } - } - - override function printTree(uri:String, content:HxParserContentData, currentPos:Int):TreePrinterResult { - return new SyntaxTreePrinter().print(uri, content.parsedTree, currentPos); - } - - function makeLinks(outputKind:OutputKind, addButtons:Bool):Array { - if (!addButtons) { - return []; - } - - inline function makeAnchor(outputKind:OutputKind):String { - var link = 'command:hxparservis.switchOutput?${haxe.Json.stringify([Std.string(outputKind)])}'; - return '$outputKind'; - } - - var links = []; - inline function maybeAdd(kind:OutputKind) { - if (outputKind != kind) - links.push(makeAnchor(kind)); - } - maybeAdd(Haxe); - maybeAdd(SyntaxTree); - maybeAdd(Json); - return links; - } - - function printHaxe(tree:File):String { - var haxeCode = Printer.print(tree, function(s) return s.htmlEscape()); - return buildHtmlWithHighlighting(haxeCode, Haxe, true); - } - - function printJson(data:Any, addButtons:Bool):String { - var json = haxe.Json.stringify(data, null, " "); - return buildHtmlWithHighlighting(json, Json, addButtons); - } - - function buildHtmlWithHighlighting(body:String, outputKind:OutputKind, addButtons:Bool):String { - var codeBlock = '
    $body
    '; - return buildHtml([HtmlPrinterBase.themeCss], [HtmlPrinterBase.highlightJs, "hljs.initHighlightingOnLoad();"], [], codeBlock, - makeLinks(outputKind, addButtons)); - } -} -#end diff --git a/src/features/vis/hxParserVis/HxParserVisFeature.hx b/src/features/vis/hxParserVis/HxParserVisFeature.hx deleted file mode 100644 index 6b7a3da..0000000 --- a/src/features/vis/hxParserVis/HxParserVisFeature.hx +++ /dev/null @@ -1,17 +0,0 @@ -package features.vis.hxParserVis; - -import Vscode.*; -import vscode.*; -import features.vis.VisFeatureBase; -import features.vis.hxParserVis.HxParserContentProvider; - -class HxParserVisFeature extends VisFeatureBase { - public function new(context:ExtensionContext) { - super(context, new HxParserContentProvider(), "parseTree", "Parse Tree", "vshaxeDebugTools.visualizeParseTree"); - - context.subscriptions.push(commands.registerCommand("hxparservis.switchOutput", function(outputKind:String) { - provider.switchOutputKind(outputKind); - update(); - })); - } -} diff --git a/src/features/vis/hxParserVis/OutputKind.hx b/src/features/vis/hxParserVis/OutputKind.hx deleted file mode 100644 index 53026e0..0000000 --- a/src/features/vis/hxParserVis/OutputKind.hx +++ /dev/null @@ -1,7 +0,0 @@ -package features.vis.hxParserVis; - -enum abstract OutputKind(String) to String from String { - var SyntaxTree; - var Haxe; - var Json; -} diff --git a/src/features/vis/hxParserVis/SyntaxTreePrinter.hx b/src/features/vis/hxParserVis/SyntaxTreePrinter.hx deleted file mode 100644 index 18e83b0..0000000 --- a/src/features/vis/hxParserVis/SyntaxTreePrinter.hx +++ /dev/null @@ -1,14 +0,0 @@ -package features.vis.hxParserVis; - -import features.vis.TreePrinterBase; -import hxParser.ParseTree.File; - -class SyntaxTreePrinter extends TreePrinterBase { - public function new() { - super("parseTree"); - } - - override function makeHtml(t:File):String { - return new features.vis.hxParserVis.Vis(this).visFile(t); - } -} diff --git a/src/features/vis/hxParserVis/Vis.hx b/src/features/vis/hxParserVis/Vis.hx deleted file mode 100644 index 7ae6f9d..0000000 --- a/src/features/vis/hxParserVis/Vis.hx +++ /dev/null @@ -1,351 +0,0 @@ -package features.vis.hxParserVis; - -import hxParser.ParseTree; - -using StringTools; - -class Vis { - var ctx : SyntaxTreePrinter; - var offset : Int; - public function new(ctx) { - this.ctx = ctx; - offset = 0; - } - public static var none = '<none>'; - public function visToken(t:Token):String { - inline function renderPosition(start:Int, end:Int) { - return "[" + start + "-" + end + ")"; - }; - inline function renderTrivia(t:Trivia, prefix:String) { - var s = t.toString().htmlEscape(); - var start = offset; - var end = offset += t.text.length; - var id = ctx.registerPos(start, end); - var link = ctx.makeLink(start, end); - return '
  • ' + prefix + ': ' + s + " " + renderPosition(start, end) + '
  • '; - }; - var trivias = []; - if (t.leadingTrivia != null) { - for (t in t.leadingTrivia) trivias.push(renderTrivia(t, "LEAD")); - }; - var start = offset; - var end = !t.appearsInSource() ? start : offset += t.text.length; - var link = ctx.makeLink(start, end); - var id = ctx.registerPos(start, end); - var selected = ctx.isUnderCursor(start, end); - var s = t.toString().htmlEscape(); - var parts = ['' + s + " " + renderPosition(start, end) + '']; - if (t.inserted) parts.push('(missing)'); - if (t.implicit) parts.push('(implicit)'); - if (t.trailingTrivia != null) { - for (t in t.trailingTrivia) trivias.push(renderTrivia(t, "TAIL")); - }; - if (trivias.length > 0) parts.push('
      ' + trivias.join("") + "
    "); - return parts.join(" "); - } - public function visArray(c:Array, vis:T -> String):String { - var parts = [for (el in c) "
  • " + vis(el) + "
  • "]; - return if (parts.length == 0) none else "
      " + parts.join("") + "
    "; - } - public function visCommaSeparated(c:CommaSeparated, vis:T -> String):String { - var parts = [vis(c.arg)]; - for (el in c.args) { - parts.push(visToken(el.comma)); - parts.push(vis(el.arg)); - }; - return "
      " + [for (s in parts) '
    • ' + s + '
    • '].join("") + "
    "; - } - public function visCommaSeparatedTrailing(c:CommaSeparatedAllowTrailing, vis:T -> String):String { - var parts = [vis(c.arg)]; - for (el in c.args) { - parts.push(visToken(el.comma)); - parts.push(vis(el.arg)); - }; - if (c.comma != null) parts.push(visToken(c.comma)); - return "
      " + [for (s in parts) '
    • ' + s + '
    • '].join("") + "
    "; - } - public function visVarDecl(v:VarDecl):String { - return "VarDecl" + "
      " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "typeHint: " + (if (v.typeHint != null) visTypeHint(v.typeHint) else none) + "
    • " + "
    • " + "assignment: " + (if (v.assignment != null) visAssignment(v.assignment) else none) + "
    • " + "
    "; - } - public function visUsingDecl(v:UsingDecl):String { - return "UsingDecl" + "
      " + "
    • " + "usingKeyword: " + visToken(v.usingKeyword) + "
    • " + "
    • " + "path: " + visNPath(v.path) + "
    • " + "
    • " + "semicolon: " + visToken(v.semicolon) + "
    • " + "
    "; - } - public function visUnderlyingType(v:UnderlyingType):String { - return "UnderlyingType" + "
      " + "
    • " + "parenOpen: " + visToken(v.parenOpen) + "
    • " + "
    • " + "type: " + visComplexType(v.type) + "
    • " + "
    • " + "parenClose: " + visToken(v.parenClose) + "
    • " + "
    "; - } - public function visTypedefDecl(v:TypedefDecl):String { - return "TypedefDecl" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "flags: " + visArray(v.flags, function(el) return visNCommonFlag(el)) + "
    • " + "
    • " + "typedefKeyword: " + visToken(v.typedefKeyword) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypeDeclParameters(v.params) else none) + "
    • " + "
    • " + "assign: " + visToken(v.assign) + "
    • " + "
    • " + "type: " + visComplexType(v.type) + "
    • " + "
    • " + "semicolon: " + (if (v.semicolon != null) visToken(v.semicolon) else none) + "
    • " + "
    "; - } - public function visTypePathParameters(v:TypePathParameters):String { - return "TypePathParameters" + "
      " + "
    • " + "lt: " + visToken(v.lt) + "
    • " + "
    • " + "params: " + visCommaSeparated(v.params, function(el) return visTypePathParameter(el)) + "
    • " + "
    • " + "gt: " + visToken(v.gt) + "
    • " + "
    "; - } - public function visTypePathParameter(v:TypePathParameter):String { - return switch v { - case Type(var type):"Type" + "
      " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    "; - case Literal(var literal):"Literal" + "
      " + "
    • " + "literal: " + visLiteral(literal) + "
    • " + "
    "; - case ArrayExpr(var bracketOpen, var elems, var bracketClose):"ArrayExpr" + "
      " + "
    • " + "bracketOpen: " + visToken(bracketOpen) + "
    • " + "
    • " + "elems: " + (if (elems != null) visCommaSeparatedTrailing(elems, function(el) return visExpr(el)) else none) + "
    • " + "
    • " + "bracketClose: " + visToken(bracketClose) + "
    • " + "
    "; - }; - } - public function visTypePath(v:TypePath):String { - return "TypePath" + "
      " + "
    • " + "path: " + visNPath(v.path) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypePathParameters(v.params) else none) + "
    • " + "
    "; - } - public function visTypeHint(v:TypeHint):String { - return "TypeHint" + "
      " + "
    • " + "colon: " + visToken(v.colon) + "
    • " + "
    • " + "type: " + visComplexType(v.type) + "
    • " + "
    "; - } - public function visTypeDeclParameters(v:TypeDeclParameters):String { - return "TypeDeclParameters" + "
      " + "
    • " + "lt: " + visToken(v.lt) + "
    • " + "
    • " + "params: " + visCommaSeparated(v.params, function(el) return visTypeDeclParameter(el)) + "
    • " + "
    • " + "gt: " + visToken(v.gt) + "
    • " + "
    "; - } - public function visTypeDeclParameter(v:TypeDeclParameter):String { - return "TypeDeclParameter" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "constraints: " + visConstraints(v.constraints) + "
    • " + "
    "; - } - public function visStructuralExtension(v:StructuralExtension):String { - return "StructuralExtension" + "
      " + "
    • " + "gt: " + visToken(v.gt) + "
    • " + "
    • " + "path: " + visTypePath(v.path) + "
    • " + "
    • " + "comma: " + visToken(v.comma) + "
    • " + "
    "; - } - public function visStringToken(v:StringToken):String { - return switch v { - case SingleQuote(var token):"SingleQuote" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - case DoubleQuote(var token):"DoubleQuote" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - }; - } - public function visPackage(v:Package):String { - return "Package" + "
      " + "
    • " + "packageKeyword: " + visToken(v.packageKeyword) + "
    • " + "
    • " + "path: " + (if (v.path != null) visNPath(v.path) else none) + "
    • " + "
    • " + "semicolon: " + visToken(v.semicolon) + "
    • " + "
    "; - } - public function visObjectFieldName(v:ObjectFieldName):String { - return switch v { - case NString(var string):"NString" + "
      " + "
    • " + "string: " + visStringToken(string) + "
    • " + "
    "; - case NIdent(var ident):"NIdent" + "
      " + "
    • " + "ident: " + visToken(ident) + "
    • " + "
    "; - }; - } - public function visObjectField(v:ObjectField):String { - return "ObjectField" + "
      " + "
    • " + "name: " + visObjectFieldName(v.name) + "
    • " + "
    • " + "colon: " + visToken(v.colon) + "
    • " + "
    • " + "expr: " + visExpr(v.expr) + "
    • " + "
    "; - } - public function visNPath(v:NPath):String { - return "NPath" + "
      " + "
    • " + "ident: " + visToken(v.ident) + "
    • " + "
    • " + "idents: " + visArray(v.idents, function(el) return visNDotIdent(el)) + "
    • " + "
    "; - } - public function visNEnumFieldArgs(v:NEnumFieldArgs):String { - return "NEnumFieldArgs" + "
      " + "
    • " + "parenOpen: " + visToken(v.parenOpen) + "
    • " + "
    • " + "args: " + (if (v.args != null) visCommaSeparated(v.args, function(el) return visNEnumFieldArg(el)) else none) + "
    • " + "
    • " + "parenClose: " + visToken(v.parenClose) + "
    • " + "
    "; - } - public function visNEnumFieldArg(v:NEnumFieldArg):String { - return "NEnumFieldArg" + "
      " + "
    • " + "questionMark: " + (if (v.questionMark != null) visToken(v.questionMark) else none) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "typeHint: " + visTypeHint(v.typeHint) + "
    • " + "
    "; - } - public function visNEnumField(v:NEnumField):String { - return "NEnumField" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypeDeclParameters(v.params) else none) + "
    • " + "
    • " + "args: " + (if (v.args != null) visNEnumFieldArgs(v.args) else none) + "
    • " + "
    • " + "typeHint: " + (if (v.typeHint != null) visTypeHint(v.typeHint) else none) + "
    • " + "
    • " + "semicolon: " + visToken(v.semicolon) + "
    • " + "
    "; - } - public function visNDotIdent(v:NDotIdent):String { - return switch v { - case PDotIdent(var name):"PDotIdent" + "
      " + "
    • " + "name: " + visToken(name) + "
    • " + "
    "; - case PDot(var dot):"PDot" + "
      " + "
    • " + "dot: " + visToken(dot) + "
    • " + "
    "; - }; - } - public function visNConst(v:NConst):String { - return switch v { - case PConstLiteral(var literal):"PConstLiteral" + "
      " + "
    • " + "literal: " + visLiteral(literal) + "
    • " + "
    "; - case PConstIdent(var ident):"PConstIdent" + "
      " + "
    • " + "ident: " + visToken(ident) + "
    • " + "
    "; - }; - } - public function visNCommonFlag(v:NCommonFlag):String { - return switch v { - case PPrivate(var token):"PPrivate" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - case PExtern(var token):"PExtern" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - }; - } - public function visNAnnotations(v:NAnnotations):String { - return "NAnnotations" + "
      " + "
    • " + "doc: " + (if (v.doc != null) visToken(v.doc) else none) + "
    • " + "
    • " + "metadata: " + visArray(v.metadata, function(el) return visMetadata(el)) + "
    • " + "
    "; - } - public function visMethodExpr(v:MethodExpr):String { - return switch v { - case None(var semicolon):"None" + "
      " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - case Expr(var expr, var semicolon):"Expr" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - case Block(var expr):"Block" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - }; - } - public function visMetadata(v:Metadata):String { - return switch v { - case WithArgs(var name, var args, var parenClose):"WithArgs" + "
      " + "
    • " + "name: " + visToken(name) + "
    • " + "
    • " + "args: " + visCommaSeparated(args, function(el) return visExpr(el)) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case Simple(var name):"Simple" + "
      " + "
    • " + "name: " + visToken(name) + "
    • " + "
    "; - }; - } - public function visMacroExpr(v:MacroExpr):String { - return switch v { - case Var(var varKeyword, var decls):"Var" + "
      " + "
    • " + "varKeyword: " + visToken(varKeyword) + "
    • " + "
    • " + "decls: " + visCommaSeparated(decls, function(el) return visVarDecl(el)) + "
    • " + "
    "; - case TypeHint(var typeHint):"TypeHint" + "
      " + "
    • " + "typeHint: " + visTypeHint(typeHint) + "
    • " + "
    "; - case Expr(var expr):"Expr" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case Class(var classDecl):"Class" + "
      " + "
    • " + "classDecl: " + visClassDecl(classDecl) + "
    • " + "
    "; - }; - } - public function visLiteral(v:Literal):String { - return switch v { - case PLiteralString(var s):"PLiteralString" + "
      " + "
    • " + "s: " + visStringToken(s) + "
    • " + "
    "; - case PLiteralRegex(var token):"PLiteralRegex" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - case PLiteralInt(var token):"PLiteralInt" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - case PLiteralFloat(var token):"PLiteralFloat" + "
      " + "
    • " + "token: " + visToken(token) + "
    • " + "
    "; - }; - } - public function visImportMode(v:ImportMode):String { - return switch v { - case INormal:"INormal"; - case IIn(var inKeyword, var ident):"IIn" + "
      " + "
    • " + "inKeyword: " + visToken(inKeyword) + "
    • " + "
    • " + "ident: " + visToken(ident) + "
    • " + "
    "; - case IAs(var asKeyword, var ident):"IAs" + "
      " + "
    • " + "asKeyword: " + visToken(asKeyword) + "
    • " + "
    • " + "ident: " + visToken(ident) + "
    • " + "
    "; - case IAll(var dotStar):"IAll" + "
      " + "
    • " + "dotStar: " + visToken(dotStar) + "
    • " + "
    "; - }; - } - public function visImportDecl(v:ImportDecl):String { - return "ImportDecl" + "
      " + "
    • " + "importKeyword: " + visToken(v.importKeyword) + "
    • " + "
    • " + "path: " + visNPath(v.path) + "
    • " + "
    • " + "mode: " + visImportMode(v.mode) + "
    • " + "
    • " + "semicolon: " + visToken(v.semicolon) + "
    • " + "
    "; - } - public function visGuard(v:Guard):String { - return "Guard" + "
      " + "
    • " + "ifKeyword: " + visToken(v.ifKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(v.parenOpen) + "
    • " + "
    • " + "expr: " + visExpr(v.expr) + "
    • " + "
    • " + "parenClose: " + visToken(v.parenClose) + "
    • " + "
    "; - } - public function visFunctionArgument(v:FunctionArgument):String { - return "FunctionArgument" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "questionMark: " + (if (v.questionMark != null) visToken(v.questionMark) else none) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "typeHint: " + (if (v.typeHint != null) visTypeHint(v.typeHint) else none) + "
    • " + "
    • " + "assignment: " + (if (v.assignment != null) visAssignment(v.assignment) else none) + "
    • " + "
    "; - } - public function visFunction(v:Function):String { - return "Function" + "
      " + "
    • " + "name: " + (if (v.name != null) visToken(v.name) else none) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypeDeclParameters(v.params) else none) + "
    • " + "
    • " + "parenOpen: " + visToken(v.parenOpen) + "
    • " + "
    • " + "args: " + (if (v.args != null) visCommaSeparated(v.args, function(el) return visFunctionArgument(el)) else none) + "
    • " + "
    • " + "parenClose: " + visToken(v.parenClose) + "
    • " + "
    • " + "typeHint: " + (if (v.typeHint != null) visTypeHint(v.typeHint) else none) + "
    • " + "
    • " + "expr: " + visExpr(v.expr) + "
    • " + "
    "; - } - public function visFile(v:File):String { - return "File" + "
      " + "
    • " + "pack: " + (if (v.pack != null) visPackage(v.pack) else none) + "
    • " + "
    • " + "decls: " + visArray(v.decls, function(el) return visDecl(el)) + "
    • " + "
    • " + "eof: " + visToken(v.eof) + "
    • " + "
    "; - } - public function visFieldModifier(v:FieldModifier):String { - return switch v { - case Static(var keyword):"Static" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - case Public(var keyword):"Public" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - case Private(var keyword):"Private" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - case Override(var keyword):"Override" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - case Macro(var keyword):"Macro" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - case Inline(var keyword):"Inline" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - case Dynamic(var keyword):"Dynamic" + "
      " + "
    • " + "keyword: " + visToken(keyword) + "
    • " + "
    "; - }; - } - public function visExprElse(v:ExprElse):String { - return "ExprElse" + "
      " + "
    • " + "elseKeyword: " + visToken(v.elseKeyword) + "
    • " + "
    • " + "expr: " + visExpr(v.expr) + "
    • " + "
    "; - } - public function visExpr(v:Expr):String { - return switch v { - case EWhile(var whileKeyword, var parenOpen, var exprCond, var parenClose, var exprBody):"EWhile" + "
      " + "
    • " + "whileKeyword: " + visToken(whileKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "exprCond: " + visExpr(exprCond) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    • " + "exprBody: " + visExpr(exprBody) + "
    • " + "
    "; - case EVar(var varKeyword, var decl):"EVar" + "
      " + "
    • " + "varKeyword: " + visToken(varKeyword) + "
    • " + "
    • " + "decl: " + visVarDecl(decl) + "
    • " + "
    "; - case EUntyped(var untypedKeyword, var expr):"EUntyped" + "
      " + "
    • " + "untypedKeyword: " + visToken(untypedKeyword) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case EUnsafeCast(var castKeyword, var expr):"EUnsafeCast" + "
      " + "
    • " + "castKeyword: " + visToken(castKeyword) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case EUnaryPrefix(var op, var expr):"EUnaryPrefix" + "
      " + "
    • " + "op: " + visToken(op) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case EUnaryPostfix(var expr, var op):"EUnaryPostfix" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "op: " + visToken(op) + "
    • " + "
    "; - case ETry(var tryKeyword, var expr, var catches):"ETry" + "
      " + "
    • " + "tryKeyword: " + visToken(tryKeyword) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "catches: " + visArray(catches, function(el) return visCatch(el)) + "
    • " + "
    "; - case EThrow(var throwKeyword, var expr):"EThrow" + "
      " + "
    • " + "throwKeyword: " + visToken(throwKeyword) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case ETernary(var exprCond, var questionMark, var exprThen, var colon, var exprElse):"ETernary" + "
      " + "
    • " + "exprCond: " + visExpr(exprCond) + "
    • " + "
    • " + "questionMark: " + visToken(questionMark) + "
    • " + "
    • " + "exprThen: " + visExpr(exprThen) + "
    • " + "
    • " + "colon: " + visToken(colon) + "
    • " + "
    • " + "exprElse: " + visExpr(exprElse) + "
    • " + "
    "; - case ESwitch(var switchKeyword, var expr, var braceOpen, var cases, var braceClose):"ESwitch" + "
      " + "
    • " + "switchKeyword: " + visToken(switchKeyword) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "braceOpen: " + visToken(braceOpen) + "
    • " + "
    • " + "cases: " + visArray(cases, function(el) return visCase(el)) + "
    • " + "
    • " + "braceClose: " + visToken(braceClose) + "
    • " + "
    "; - case ESafeCast(var castKeyword, var parenOpen, var expr, var comma, var type, var parenClose):"ESafeCast" + "
      " + "
    • " + "castKeyword: " + visToken(castKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "comma: " + visToken(comma) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case EReturnExpr(var returnKeyword, var expr):"EReturnExpr" + "
      " + "
    • " + "returnKeyword: " + visToken(returnKeyword) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case EReturn(var returnKeyword):"EReturn" + "
      " + "
    • " + "returnKeyword: " + visToken(returnKeyword) + "
    • " + "
    "; - case EParenthesis(var parenOpen, var expr, var parenClose):"EParenthesis" + "
      " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case EObjectDecl(var braceOpen, var fields, var braceClose):"EObjectDecl" + "
      " + "
    • " + "braceOpen: " + visToken(braceOpen) + "
    • " + "
    • " + "fields: " + visCommaSeparatedTrailing(fields, function(el) return visObjectField(el)) + "
    • " + "
    • " + "braceClose: " + visToken(braceClose) + "
    • " + "
    "; - case ENew(var newKeyword, var path, var args):"ENew" + "
      " + "
    • " + "newKeyword: " + visToken(newKeyword) + "
    • " + "
    • " + "path: " + visTypePath(path) + "
    • " + "
    • " + "args: " + visCallArgs(args) + "
    • " + "
    "; - case EMetadata(var metadata, var expr):"EMetadata" + "
      " + "
    • " + "metadata: " + visMetadata(metadata) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    "; - case EMacroEscape(var ident, var braceOpen, var expr, var braceClose):"EMacroEscape" + "
      " + "
    • " + "ident: " + visToken(ident) + "
    • " + "
    • " + "braceOpen: " + visToken(braceOpen) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "braceClose: " + visToken(braceClose) + "
    • " + "
    "; - case EMacro(var macroKeyword, var expr):"EMacro" + "
      " + "
    • " + "macroKeyword: " + visToken(macroKeyword) + "
    • " + "
    • " + "expr: " + visMacroExpr(expr) + "
    • " + "
    "; - case EIs(var parenOpen, var expr, var isKeyword, var path, var parenClose):"EIs" + "
      " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "isKeyword: " + visToken(isKeyword) + "
    • " + "
    • " + "path: " + visTypePath(path) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case EIntDot(var int, var dot):"EIntDot" + "
      " + "
    • " + "int: " + visToken(int) + "
    • " + "
    • " + "dot: " + visToken(dot) + "
    • " + "
    "; - case EIn(var exprLeft, var inKeyword, var exprRight):"EIn" + "
      " + "
    • " + "exprLeft: " + visExpr(exprLeft) + "
    • " + "
    • " + "inKeyword: " + visToken(inKeyword) + "
    • " + "
    • " + "exprRight: " + visExpr(exprRight) + "
    • " + "
    "; - case EIf(var ifKeyword, var parenOpen, var exprCond, var parenClose, var exprThen, var exprElse):"EIf" + "
      " + "
    • " + "ifKeyword: " + visToken(ifKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "exprCond: " + visExpr(exprCond) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    • " + "exprThen: " + visExpr(exprThen) + "
    • " + "
    • " + "exprElse: " + (if (exprElse != null) visExprElse(exprElse) else none) + "
    • " + "
    "; - case EFunction(var functionKeyword, var fun):"EFunction" + "
      " + "
    • " + "functionKeyword: " + visToken(functionKeyword) + "
    • " + "
    • " + "fun: " + visFunction(fun) + "
    • " + "
    "; - case EFor(var forKeyword, var parenOpen, var exprIter, var parenClose, var exprBody):"EFor" + "
      " + "
    • " + "forKeyword: " + visToken(forKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "exprIter: " + visExpr(exprIter) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    • " + "exprBody: " + visExpr(exprBody) + "
    • " + "
    "; - case EField(var expr, var ident):"EField" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "ident: " + visNDotIdent(ident) + "
    • " + "
    "; - case EDollarIdent(var ident):"EDollarIdent" + "
      " + "
    • " + "ident: " + visToken(ident) + "
    • " + "
    "; - case EDo(var doKeyword, var exprBody, var whileKeyword, var parenOpen, var exprCond, var parenClose):"EDo" + "
      " + "
    • " + "doKeyword: " + visToken(doKeyword) + "
    • " + "
    • " + "exprBody: " + visExpr(exprBody) + "
    • " + "
    • " + "whileKeyword: " + visToken(whileKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "exprCond: " + visExpr(exprCond) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case EContinue(var continueKeyword):"EContinue" + "
      " + "
    • " + "continueKeyword: " + visToken(continueKeyword) + "
    • " + "
    "; - case EConst(var const):"EConst" + "
      " + "
    • " + "const: " + visNConst(const) + "
    • " + "
    "; - case ECheckType(var parenOpen, var expr, var colon, var type, var parenClose):"ECheckType" + "
      " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "colon: " + visToken(colon) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case ECall(var expr, var args):"ECall" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "args: " + visCallArgs(args) + "
    • " + "
    "; - case EBreak(var breakKeyword):"EBreak" + "
      " + "
    • " + "breakKeyword: " + visToken(breakKeyword) + "
    • " + "
    "; - case EBlock(var braceOpen, var elems, var braceClose):"EBlock" + "
      " + "
    • " + "braceOpen: " + visToken(braceOpen) + "
    • " + "
    • " + "elems: " + visArray(elems, function(el) return visBlockElement(el)) + "
    • " + "
    • " + "braceClose: " + visToken(braceClose) + "
    • " + "
    "; - case EBinop(var exprLeft, var op, var exprRight):"EBinop" + "
      " + "
    • " + "exprLeft: " + visExpr(exprLeft) + "
    • " + "
    • " + "op: " + visToken(op) + "
    • " + "
    • " + "exprRight: " + visExpr(exprRight) + "
    • " + "
    "; - case EArrayDecl(var bracketOpen, var elems, var bracketClose):"EArrayDecl" + "
      " + "
    • " + "bracketOpen: " + visToken(bracketOpen) + "
    • " + "
    • " + "elems: " + (if (elems != null) visCommaSeparatedTrailing(elems, function(el) return visExpr(el)) else none) + "
    • " + "
    • " + "bracketClose: " + visToken(bracketClose) + "
    • " + "
    "; - case EArrayAccess(var expr, var bracketOpen, var exprKey, var bracketClose):"EArrayAccess" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "bracketOpen: " + visToken(bracketOpen) + "
    • " + "
    • " + "exprKey: " + visExpr(exprKey) + "
    • " + "
    • " + "bracketClose: " + visToken(bracketClose) + "
    • " + "
    "; - }; - } - public function visEnumDecl(v:EnumDecl):String { - return "EnumDecl" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "flags: " + visArray(v.flags, function(el) return visNCommonFlag(el)) + "
    • " + "
    • " + "enumKeyword: " + visToken(v.enumKeyword) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypeDeclParameters(v.params) else none) + "
    • " + "
    • " + "braceOpen: " + visToken(v.braceOpen) + "
    • " + "
    • " + "fields: " + visArray(v.fields, function(el) return visNEnumField(el)) + "
    • " + "
    • " + "braceClose: " + visToken(v.braceClose) + "
    • " + "
    "; - } - public function visDecl(v:Decl):String { - return switch v { - case UsingDecl(var decl):"UsingDecl" + "
      " + "
    • " + "decl: " + visUsingDecl(decl) + "
    • " + "
    "; - case TypedefDecl(var decl):"TypedefDecl" + "
      " + "
    • " + "decl: " + visTypedefDecl(decl) + "
    • " + "
    "; - case ImportDecl(var decl):"ImportDecl" + "
      " + "
    • " + "decl: " + visImportDecl(decl) + "
    • " + "
    "; - case EnumDecl(var decl):"EnumDecl" + "
      " + "
    • " + "decl: " + visEnumDecl(decl) + "
    • " + "
    "; - case ClassDecl(var decl):"ClassDecl" + "
      " + "
    • " + "decl: " + visClassDecl2(decl) + "
    • " + "
    "; - case AbstractDecl(var decl):"AbstractDecl" + "
      " + "
    • " + "decl: " + visAbstractDecl(decl) + "
    • " + "
    "; - }; - } - public function visConstraints(v:Constraints):String { - return switch v { - case Single(var colon, var type):"Single" + "
      " + "
    • " + "colon: " + visToken(colon) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    "; - case None:"None"; - case Multiple(var colon, var parenOpen, var types, var parenClose):"Multiple" + "
      " + "
    • " + "colon: " + visToken(colon) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "types: " + visCommaSeparated(types, function(el) return visComplexType(el)) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - }; - } - public function visComplexType(v:ComplexType):String { - return switch v { - case TypePath(var path):"TypePath" + "
      " + "
    • " + "path: " + visTypePath(path) + "
    • " + "
    "; - case StructuralExtension(var braceOpen, var types, var fields, var braceClose):"StructuralExtension" + "
      " + "
    • " + "braceOpen: " + visToken(braceOpen) + "
    • " + "
    • " + "types: " + visArray(types, function(el) return visStructuralExtension(el)) + "
    • " + "
    • " + "fields: " + visAnonymousStructureFields(fields) + "
    • " + "
    • " + "braceClose: " + visToken(braceClose) + "
    • " + "
    "; - case Parenthesis(var parenOpen, var type, var parenClose):"Parenthesis" + "
      " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    "; - case Optional(var questionMark, var type):"Optional" + "
      " + "
    • " + "questionMark: " + visToken(questionMark) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    "; - case Function(var typeLeft, var arrow, var typeRight):"Function" + "
      " + "
    • " + "typeLeft: " + visComplexType(typeLeft) + "
    • " + "
    • " + "arrow: " + visToken(arrow) + "
    • " + "
    • " + "typeRight: " + visComplexType(typeRight) + "
    • " + "
    "; - case AnonymousStructure(var braceOpen, var fields, var braceClose):"AnonymousStructure" + "
      " + "
    • " + "braceOpen: " + visToken(braceOpen) + "
    • " + "
    • " + "fields: " + visAnonymousStructureFields(fields) + "
    • " + "
    • " + "braceClose: " + visToken(braceClose) + "
    • " + "
    "; - }; - } - public function visClassRelation(v:ClassRelation):String { - return switch v { - case Implements(var implementsKeyword, var path):"Implements" + "
      " + "
    • " + "implementsKeyword: " + visToken(implementsKeyword) + "
    • " + "
    • " + "path: " + visTypePath(path) + "
    • " + "
    "; - case Extends(var extendsKeyword, var path):"Extends" + "
      " + "
    • " + "extendsKeyword: " + visToken(extendsKeyword) + "
    • " + "
    • " + "path: " + visTypePath(path) + "
    • " + "
    "; - }; - } - public function visClassField(v:ClassField):String { - return switch v { - case Variable(var annotations, var modifiers, var varKeyword, var name, var typeHint, var assignment, var semicolon):"Variable" + "
      " + "
    • " + "annotations: " + visNAnnotations(annotations) + "
    • " + "
    • " + "modifiers: " + visArray(modifiers, function(el) return visFieldModifier(el)) + "
    • " + "
    • " + "varKeyword: " + visToken(varKeyword) + "
    • " + "
    • " + "name: " + visToken(name) + "
    • " + "
    • " + "typeHint: " + (if (typeHint != null) visTypeHint(typeHint) else none) + "
    • " + "
    • " + "assignment: " + (if (assignment != null) visAssignment(assignment) else none) + "
    • " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - case Property(var annotations, var modifiers, var varKeyword, var name, var parenOpen, var read, var comma, var write, var parenClose, var typeHint, var assignment, var semicolon):"Property" + "
      " + "
    • " + "annotations: " + visNAnnotations(annotations) + "
    • " + "
    • " + "modifiers: " + visArray(modifiers, function(el) return visFieldModifier(el)) + "
    • " + "
    • " + "varKeyword: " + visToken(varKeyword) + "
    • " + "
    • " + "name: " + visToken(name) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "read: " + visToken(read) + "
    • " + "
    • " + "comma: " + visToken(comma) + "
    • " + "
    • " + "write: " + visToken(write) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    • " + "typeHint: " + (if (typeHint != null) visTypeHint(typeHint) else none) + "
    • " + "
    • " + "assignment: " + (if (assignment != null) visAssignment(assignment) else none) + "
    • " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - case Function(var annotations, var modifiers, var functionKeyword, var name, var params, var parenOpen, var args, var parenClose, var typeHint, var expr):"Function" + "
      " + "
    • " + "annotations: " + visNAnnotations(annotations) + "
    • " + "
    • " + "modifiers: " + visArray(modifiers, function(el) return visFieldModifier(el)) + "
    • " + "
    • " + "functionKeyword: " + visToken(functionKeyword) + "
    • " + "
    • " + "name: " + visToken(name) + "
    • " + "
    • " + "params: " + (if (params != null) visTypeDeclParameters(params) else none) + "
    • " + "
    • " + "parenOpen: " + visToken(parenOpen) + "
    • " + "
    • " + "args: " + (if (args != null) visCommaSeparated(args, function(el) return visFunctionArgument(el)) else none) + "
    • " + "
    • " + "parenClose: " + visToken(parenClose) + "
    • " + "
    • " + "typeHint: " + (if (typeHint != null) visTypeHint(typeHint) else none) + "
    • " + "
    • " + "expr: " + visMethodExpr(expr) + "
    • " + "
    "; - }; - } - public function visClassDecl2(v:ClassDecl2):String { - return "ClassDecl2" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "flags: " + visArray(v.flags, function(el) return visNCommonFlag(el)) + "
    • " + "
    • " + "decl: " + visClassDecl(v.decl) + "
    • " + "
    "; - } - public function visClassDecl(v:ClassDecl):String { - return "ClassDecl" + "
      " + "
    • " + "kind: " + visToken(v.kind) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypeDeclParameters(v.params) else none) + "
    • " + "
    • " + "relations: " + visArray(v.relations, function(el) return visClassRelation(el)) + "
    • " + "
    • " + "braceOpen: " + visToken(v.braceOpen) + "
    • " + "
    • " + "fields: " + visArray(v.fields, function(el) return visClassField(el)) + "
    • " + "
    • " + "braceClose: " + visToken(v.braceClose) + "
    • " + "
    "; - } - public function visCatch(v:Catch):String { - return "Catch" + "
      " + "
    • " + "catchKeyword: " + visToken(v.catchKeyword) + "
    • " + "
    • " + "parenOpen: " + visToken(v.parenOpen) + "
    • " + "
    • " + "ident: " + visToken(v.ident) + "
    • " + "
    • " + "typeHint: " + visTypeHint(v.typeHint) + "
    • " + "
    • " + "parenClose: " + visToken(v.parenClose) + "
    • " + "
    • " + "expr: " + visExpr(v.expr) + "
    • " + "
    "; - } - public function visCase(v:Case):String { - return switch v { - case Default(var defaultKeyword, var colon, var body):"Default" + "
      " + "
    • " + "defaultKeyword: " + visToken(defaultKeyword) + "
    • " + "
    • " + "colon: " + visToken(colon) + "
    • " + "
    • " + "body: " + visArray(body, function(el) return visBlockElement(el)) + "
    • " + "
    "; - case Case(var caseKeyword, var patterns, var guard, var colon, var body):"Case" + "
      " + "
    • " + "caseKeyword: " + visToken(caseKeyword) + "
    • " + "
    • " + "patterns: " + visCommaSeparated(patterns, function(el) return visExpr(el)) + "
    • " + "
    • " + "guard: " + (if (guard != null) visGuard(guard) else none) + "
    • " + "
    • " + "colon: " + visToken(colon) + "
    • " + "
    • " + "body: " + visArray(body, function(el) return visBlockElement(el)) + "
    • " + "
    "; - }; - } - public function visCallArgs(v:CallArgs):String { - return "CallArgs" + "
      " + "
    • " + "parenOpen: " + visToken(v.parenOpen) + "
    • " + "
    • " + "args: " + (if (v.args != null) visCommaSeparated(v.args, function(el) return visExpr(el)) else none) + "
    • " + "
    • " + "parenClose: " + visToken(v.parenClose) + "
    • " + "
    "; - } - public function visBlockElement(v:BlockElement):String { - return switch v { - case Var(var varKeyword, var decls, var semicolon):"Var" + "
      " + "
    • " + "varKeyword: " + visToken(varKeyword) + "
    • " + "
    • " + "decls: " + visCommaSeparated(decls, function(el) return visVarDecl(el)) + "
    • " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - case InlineFunction(var inlineKeyword, var functionKeyword, var fun, var semicolon):"InlineFunction" + "
      " + "
    • " + "inlineKeyword: " + visToken(inlineKeyword) + "
    • " + "
    • " + "functionKeyword: " + visToken(functionKeyword) + "
    • " + "
    • " + "fun: " + visFunction(fun) + "
    • " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - case Expr(var expr, var semicolon):"Expr" + "
      " + "
    • " + "expr: " + visExpr(expr) + "
    • " + "
    • " + "semicolon: " + visToken(semicolon) + "
    • " + "
    "; - }; - } - public function visAssignment(v:Assignment):String { - return "Assignment" + "
      " + "
    • " + "assign: " + visToken(v.assign) + "
    • " + "
    • " + "expr: " + visExpr(v.expr) + "
    • " + "
    "; - } - public function visAnonymousStructureFields(v:AnonymousStructureFields):String { - return switch v { - case ShortNotation(var fields):"ShortNotation" + "
      " + "
    • " + "fields: " + (if (fields != null) visCommaSeparatedTrailing(fields, function(el) return visAnonymousStructureField(el)) else none) + "
    • " + "
    "; - case ClassNotation(var fields):"ClassNotation" + "
      " + "
    • " + "fields: " + visArray(fields, function(el) return visClassField(el)) + "
    • " + "
    "; - }; - } - public function visAnonymousStructureField(v:AnonymousStructureField):String { - return "AnonymousStructureField" + "
      " + "
    • " + "questionMark: " + (if (v.questionMark != null) visToken(v.questionMark) else none) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "typeHint: " + visTypeHint(v.typeHint) + "
    • " + "
    "; - } - public function visAbstractRelation(v:AbstractRelation):String { - return switch v { - case To(var toKeyword, var type):"To" + "
      " + "
    • " + "toKeyword: " + visToken(toKeyword) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    "; - case From(var fromKeyword, var type):"From" + "
      " + "
    • " + "fromKeyword: " + visToken(fromKeyword) + "
    • " + "
    • " + "type: " + visComplexType(type) + "
    • " + "
    "; - }; - } - public function visAbstractDecl(v:AbstractDecl):String { - return "AbstractDecl" + "
      " + "
    • " + "annotations: " + visNAnnotations(v.annotations) + "
    • " + "
    • " + "flags: " + visArray(v.flags, function(el) return visNCommonFlag(el)) + "
    • " + "
    • " + "abstractKeyword: " + visToken(v.abstractKeyword) + "
    • " + "
    • " + "name: " + visToken(v.name) + "
    • " + "
    • " + "params: " + (if (v.params != null) visTypeDeclParameters(v.params) else none) + "
    • " + "
    • " + "underlyingType: " + (if (v.underlyingType != null) visUnderlyingType(v.underlyingType) else none) + "
    • " + "
    • " + "relations: " + visArray(v.relations, function(el) return visAbstractRelation(el)) + "
    • " + "
    • " + "braceOpen: " + visToken(v.braceOpen) + "
    • " + "
    • " + "fields: " + visArray(v.fields, function(el) return visClassField(el)) + "
    • " + "
    • " + "braceClose: " + visToken(v.braceClose) + "
    • " + "
    "; - } -} \ No newline at end of file diff --git a/src/features/vis/tokenTreeVis/TokenTreeVis.hx b/src/features/vis/tokenTreeVis/TokenTreeVis.hx index a0502c9..a14acf4 100644 --- a/src/features/vis/tokenTreeVis/TokenTreeVis.hx +++ b/src/features/vis/tokenTreeVis/TokenTreeVis.hx @@ -1,5 +1,8 @@ package features.vis.tokenTreeVis; +import sys.io.File; +import sys.FileSystem; +import haxe.display.FsPath; import features.vis.TreePrinterBase; import tokentree.TokenTree; @@ -20,6 +23,12 @@ class TokenTreeVis extends TreePrinterBase { if (t.pos != null) { start = t.pos.min; end = t.pos.max; + final path = uriToFsPath(uri).toString(); + if (FileSystem.exists(path)) { + final content = File.getContent(path); + start = utf8Offset(content, start, 1); + end = utf8Offset(content, end, 1); + } } var link = makeLink(start, end); var id = registerPos(start, end); @@ -32,10 +41,12 @@ class TokenTreeVis extends TreePrinterBase { } var s = tokName.htmlEscape(); var colorClass = getTokenColor(t); + // @formatter:off var parts = [ '' + s + ' ' + renderPosition(start, end) + "" ]; + // @formatter:on if (t.inserted) parts.push('(missing)'); if (t.children != null) { @@ -48,17 +59,59 @@ class TokenTreeVis extends TreePrinterBase { return parts.join(" "); } + function utf8Offset(string:String, offset:Int, direction:Int):Int { + var ret = offset; + var i = 0, j = 0; + while (j < string.length && i < offset) { + var ch = string.charCodeAt(j); + if (ch >= 0x0000 && ch <= 0x007F) { + // 1 + } else if (ch >= 0x0080 && ch <= 0x07FF) { + // 2 + ret -= direction; + } else if (ch >= 0xD800 && ch < 0xDC00) { + // surrogate pair + ret -= direction * 2; + j++; + } else if (ch >= 0x0800 && ch <= 0xFFFF) { + // 3 + ret -= direction * 2; + } else if (ch >= 0x10000 && ch <= 0x10FFFF) { + // 4 + ret -= direction * 3; + } else {} // invalid char + i++; + j++; + } + return ret; + } + + final driveLetterPathRe = ~/^\/[a-zA-Z]:/; + final uriRe = ~/^(([^:\/?#]+?):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/; + + function uriToFsPath(uri:String):FsPath { + if (!uriRe.match(uri) || uriRe.matched(2) != "file") + throw 'Invalid uri: $uri'; + + final path = uriRe.matched(5).urlDecode(); + if (driveLetterPathRe.match(path)) + return new FsPath(path.charAt(1).toLowerCase() + path.substr(2)); + else + return new FsPath(path); + } + function getTokenColor(t:TokenTree):String { return switch (t.tok) { case null: ""; - case Kwd(KwdIf), Kwd(KwdElse), Kwd(KwdFor), Kwd(KwdWhile), Kwd(KwdDo), Kwd(KwdSwitch), Kwd(KwdCase), Kwd(KwdDefault), Kwd(KwdReturn), Kwd(KwdTry), Kwd(KwdCatch), Kwd(KwdThrow), Kwd(KwdBreak), Kwd(KwdContinue): + case Kwd(KwdIf), Kwd(KwdElse), Kwd(KwdFor), Kwd(KwdWhile), Kwd(KwdDo), Kwd(KwdSwitch), Kwd(KwdCase), Kwd(KwdDefault), Kwd(KwdReturn), Kwd(KwdTry), + Kwd(KwdCatch), Kwd(KwdThrow), Kwd(KwdBreak), Kwd(KwdContinue): "keyword-control"; case Kwd(_): "keyword"; case Const(CIdent(s)): if (~/^[A-Z]/.match(s)) { "type"; - } else if (t.access().firstOf(t -> t.match(POpen)).exists()) { + } else if (t.access().firstOf(POpen).exists()) { "function"; } else { "ident"; diff --git a/test/features/hxParserVis/GenTestPage.hx b/test/features/hxParserVis/GenTestPage.hx deleted file mode 100644 index f48472d..0000000 --- a/test/features/hxParserVis/GenTestPage.hx +++ /dev/null @@ -1,26 +0,0 @@ -package features.hxParserVis; - -import features.vis.hxParserVis.HxParserHtmlPrinter; -import hxParser.Converter; -import hxParser.HxParser.HxParser; -import sys.io.File; - -using StringTools; - -class GenTestPage { - public static function main() { - var src = File.getContent("src/features/vis/hxParserVis/HxParserHtmlPrinter.hx"); - switch (HxParser.parse(src)) { - case Success(data): - var content = { - unparsedData: data, - parsedTree: new Converter(data).convertResultToFile() - } - var html = new HxParserHtmlPrinter().print("", content, 0, SyntaxTree, "Segoe UI", "13"); - html = html.replace("", ""); - File.saveContent("bin/TestPage.html", html); - case _: - Sys.exit(1); - } - } -} diff --git a/vshaxe-build.json b/vshaxe-build.json index 73ff84d..e4c59fa 100644 --- a/vshaxe-build.json +++ b/vshaxe-build.json @@ -4,8 +4,7 @@ "targets": [{ "name": "all", "targetDependencies": [ - "extension", - "generate-sample-html" + "extension" ], "composite": true, "args": { @@ -14,10 +13,9 @@ }, { "name": "extension", - "targetDependencies": ["generate-vis"], "args": { "classPaths": ["src"], - "haxelibs": ["haxe-hxparser", "vscode", "haxeparser", "hxparse", "tokentree"], + "haxelibs": ["vscode", "haxeparser", "hxparse", "tokentree"], "defines": [ "JSTACK_MAIN=Main.activate", "JSTACK_NO_SHUTDOWN" @@ -29,32 +27,6 @@ }, "packageName": "Main" } - }, - { - "name": "generate-vis", - "inherit": "empty", - "args": { - "classPaths": ["src"], - "haxelibs": ["haxe-hxparser"], - "macros": ["features.vis.hxParserVis.GenVis.gen()"], - "debug": true - } - }, - { - "name": "generate-sample-html", - "args": { - "classPaths": ["src", "test"], - "haxelibs": ["haxe-hxparser"], - "debug": true, - "output": { - "target": "js", - "path": "bin/test.js" - }, - "main": "features.hxParserVis.GenTestPage" - }, - "afterBuildCommands": [ - ["node", "bin/test.js"] - ] } ] -} \ No newline at end of file +}