abstract-syntax-tree

Accessing Javadoc with Javaparser returns null

若如初见. 提交于 2019-12-13 04:53:03
问题 I'm parsing Java source files with Javaparser (javaparser-core 2.0.0) to get Javadoc comments from methods. However, I always get null When I call MethodDeclaration.getJavaDoc() . Looking at the source of MethodDeclaration , I can see why: public JavadocComment getJavaDoc() { return null; } (It appears Javadoc is available from Node.getComment() instead) My question is: Why is method Javadoc not available from MethodDeclaration.getJavaDoc() ? 回答1: The answer is: because we added the interface

Saving modified AST in a new file with eclipse plugin

谁说胖子不能爱 提交于 2019-12-13 00:53:28
问题 I have a eclipse plugin code to manipulate a class (smcho.Hello) in a project/workspace. I could create a CompilationUnit and did some modifications on it, but I need to save the result in different file to check the differences between the two version. This is the code how I get the CompilationUnit. IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("Hello"); project.open(null); IJavaProject javaProject = JavaCore.create(project); IType lwType

Use AST module to mutate and delete assignment/function calls

自古美人都是妖i 提交于 2019-12-13 00:28:56
问题 For example if I wanted to change greater than to less than or equal to I have successfully executed: def visit_Gt(self, node): new_node = ast.GtE() return ast.copy_location(new_node, node) How would I visit/detect an assignment operation ( = ) and a function call () and simply delete them? I'm reading through the AST documentation and I can't find a way to visit the assignment or function call classes and then return nothing. An example of what I'm seeking for assignment operations: print(

Compile subsection of Jinja2 AST

自古美人都是妖i 提交于 2019-12-12 21:05:16
问题 Can one compile or revert a portion of the Jinja2 AST? For example, is it possible to call a function or method from jinja2.environment or jinja2.compiler.generate or some equivalent on a list of nodes extracted from within a template? For example, given a template y.html : avant-tag {% xyz %} tag content {{ 3 + 5 }} {% endxyz %} apres-tag and an extension y.py : # -*- coding: utf-8 -*- from jinja2 import nodes, Environment, FileSystemLoader from jinja2.ext import Extension class YExtension

Iterative update of abstract syntax tree with boost spirit

旧时模样 提交于 2019-12-12 21:01:10
问题 I have a working boost spirit parser and was thinking if it is possible to do iterative update of an abstract syntax tree with boost spirit? I have a struct similar to: struct ast; typedef boost::variant< boost::recursive_wrapper<ast> > node; struct ast { std::vector<int> value; std::vector<node> children; }; Which is being parsed by use of: bool r = phrase_parse(begin, end, grammar, space, ast); Would it be possible to do iterative update of abstract syntax tree with boost spirit? I have not

CDT IASTNode getRawSignature after preprocessor

好久不见. 提交于 2019-12-12 20:27:43
问题 In CDT core plugin, there is a method getRawSignature of interface IASTNode that was described as: Returns the raw signature of the IASTNode before it is processed by the preprocessor. Example: #define ONE 1 int x=ONE; // getRawSignature() for this declaration would return "int x=ONE;" But I want to get the String signature after the node is processed by the preprocessor In the above example, the expected string is: int x=1 How to get this string? I have looked at some other methods, but no

Rascal: what does the bool collectBindings in creating AST do?

非 Y 不嫁゛ 提交于 2019-12-12 16:19:38
问题 I have a question about creating a AST in rascal. I normally do the following: model = createM3FromEclipseProject(|project://testproject|); decls = createAstsFromEclipseProject(model.id, false); At first i would set the collectBindings to true. But for some projects i get a stack overflow error. This could be because i use Luna eclipse but it made me wonder what the collectionbinding does? I tried to look it up but i could not find any documentation (maybe my google skills are bad). I also

Grails 2.1.1 - How to develop a plugin with an AstTransformer?

只愿长相守 提交于 2019-12-12 15:15:35
问题 I want to replace the auto injected log object, which is of type org.apache.commons.logging.Log with an object of type org.slf4j.Logger , so that I can use it properly with Logback. Therefore I need to create a ...Transformer class (written in Java) - that's what I got from Graeme Rocher over at the "grails-user" mailing list. I'm also aware that I have to pack this ...Transformer class within a plugin and make it a *.jar archive which I can load within the lib/ folder of the plugin. But I

How do i access v8 parse tree how can it be done?

微笑、不失礼 提交于 2019-12-12 08:33:04
问题 I like to take the v8 engine and to transform its code to other programming language based on this for example if i understand it right first step i need to get the parse tree my question is : can i get it already from v8 or do i need to generate it from the js code . what is the easer way ? 回答1: It looks hard to get the AST (Annotated Syntax Tree, the Parse tree) from V8 itself but there are plenty of other parsers for JavaScript that will do what you're looking for. I'd recommend having a

Unparse AST < O(exp(n))?

落爺英雄遲暮 提交于 2019-12-12 08:23:50
问题 Abstract problem description: The way I see it, unparsing means to create a token stream from an AST, which when parsed again produces an equal AST. So parse(unparse(AST)) = AST holds. This is the equal to finding a valid parse tree which would produce the same AST. The language is described by a context free S-attributed grammar using a eBNF variant. So the unparser has to find a valid 'path' through the traversed nodes in which all grammar constraints hold. This bascially means to find a