abstract-syntax-tree

JS: rename variables for refactor (using an AST, not text)

耗尽温柔 提交于 2020-01-14 22:29:27
问题 I often need to rename variables when refactoring code, which I currently do in a somewhat hacky way using regexs - I end up having to come with silly text workaround workarounds for the lack of actual structure, eg, rename 'req' to 'request' and avoid side effects with similar names like 'require'. Thinking about this stuff: it's kind of like modifying the DOM with regexs: it just doesn't work. I've learnt about ASTs and code structure modification tools like Esprima. Is there a tool to

Eclipse Java AST parser: insert statement before if/for/while

半世苍凉 提交于 2020-01-14 03:05:52
问题 I'm using the org.eclipse.jdt parser. I want to rewrite this code: public void foo(){ ... ... if(a>b) ... ... } into this: public void foo(){ ... ... System.out.println("hello"); if(a>b) ... ... } Supposing that ifnode is an IF_STATEMENT node, I can do something similar to this: Block block = ast.newBlock(); TextElement siso = ast.newTextElement(); siso.setText("System.out.println(\"hello\");"); ListRewrite listRewrite = rewriter.getListRewrite(block, Block.STATEMENTS_PROPERTY); listRewrite

How to write a Typescript plugin?

萝らか妹 提交于 2020-01-13 20:17:25
问题 Are there any docs / examples of writing a Typescript plugin? For the last time I am very inspired with the idea of bringing Typescript into my projects. However, currently I see this is not possible because of my failed attempts to find any docs about writing a Typescript plugin . I need this plugin for combining classes metadata during compilation and then generating an asset. It was not that easy but I've already written such for babel and now I am interested if it is possible to do the

Eclipse JDT ASTParser convert enum declaration node incorrectly

爷,独闯天下 提交于 2020-01-13 03:47:18
问题 I am working on analyzing Java code by using JDT and going to build a standalone analysis tool depend on org.eclipse.jdt.core package instead of an eclipse plug-in. But I found that my tool did not work correctly on enum declaration node which appeared in Java code. In my AST which created by jdt, keyword enum was regarded as a typename instead of an enum declaration. So I want to know how I should be can ensure that my tool can deal the enum declaration correctly. The jdt package that I used

Building a control-flow graph from an AST with a visitor pattern using Java

淺唱寂寞╮ 提交于 2020-01-12 03:53:08
问题 I'm trying to figure out how to implement my LEParserCfgVisitor class as to build a control-flow graph from an Abstract-Syntax-Tree already generated with JavaCC. I know there are tools that already exist, but I'm trying to do it in preparation for my Compilers final. I know I need to have a data structure that keeps the graph in memory, and I want to be able to keep attributes like IN, OUT, GEN, KILL in each node as to be able to do a control-flow analysis later on. My main problem is that I

Developing Abstract Syntax Tree

只愿长相守 提交于 2020-01-11 15:30:13
问题 I've scoured the internet looking for some newbie information on developing a C# Abstract Syntax Trees but I can only find information for people already 'in-the-know'. I am a line-of-business application developer so topics like these are a bit over my head, but this is for my own education so I'm willing to spend the time and learn whatever concepts are necessary. Generally, I'd like to learn about the techniques behind developing an abstract representation of code from a code string. More

How to avoid building intermediates and useless AST nodes with ANTLR3?

被刻印的时光 ゝ 提交于 2020-01-11 07:09:15
问题 I wrote an ANTLR3 grammar subdivided into smaller rules to increase readability. For example: messageSequenceChart: 'msc' mscHead bmsc 'endmsc' end ; # Where mscHead is a shortcut to : mscHead: mscName mscParameterDecl? timeOffset? end mscInstInterface? mscGateInterface ; I know the built-in ANTLR AST building feature allows the user to declare intermediate AST nodes that won't be in the final AST. But what if you build the AST by hand? messageSequenceChart returns [msc::MessageSequenceChart*

How could I search references to a field on a AST or a CompilationUnit in eclipse?

会有一股神秘感。 提交于 2020-01-05 08:42:32
问题 Hi, I'm developing an Eclipse plugin. I need to find all the references in the source using AST's or jdt.core.dom or something like that. I need this references like ASTNodes in order to get the parent node and check several things in the expression where references are involved. Thanks beforehand. Edited: I want to concrete a little more, My problem is that I try to catch some references to a constant but... I have not idea how I can do to catch in the matches this references. I need check

How to find the type of a selected member in Eclipse?

旧巷老猫 提交于 2020-01-05 04:37:12
问题 I am co-developing an Eclipse plugin where Users can select Classes and Methods from their code and attach them to notes that are saved in a different file. I want to find a way to determine what type of member was selected by the user when they choose to create an attachment. For example: I want to attach a class named "HelloClass" to a note called "HelloNote". I select the "HelloClass" member name in the editor, right-click and select my "Create Attachment" action. This action calls the

Parse Python file and evaluate selected functions

核能气质少年 提交于 2020-01-04 06:14:32
问题 I have a file that contains several python functions, each with some statements. def func1(): codeX... def func2(): codeY... codeX and codeY can be multiple statements. I want to be able to parse the file, find a function by name, then evaluate the code in that function. With the ast module, I can parse the file, find the FunctionDef objects, and get the list of Stmt objects, but how do I turn this into bytecode that I can pass to eval? Should I use the compile module, or the parser module