abstract-syntax-tree

How to find move constructors in codebase using Clang AST tools?

旧街凉风 提交于 2019-12-25 07:38:31
问题 Following up a comment from this question: how can I find move constructors in C++ codebase using Clang AST tools? (find definitions / declarations only) 回答1: The Clang AST matcher now provides this functionality with the isMoveConstructor matcher. Here's an example program: #include <iostream> #include "clang/AST/AST.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceLocation.h"

Get last evaluated expression inside function

耗尽温柔 提交于 2019-12-25 07:08:12
问题 This is related to this other question: Last evaluated expression in Javascript But I wanted to provide more details about what I wanted to do and show how I finally solved the problem as some users requested in the comments. I have snippets of Javascript that are written by users of my app. This snippets need to go to a kind of template like this: var foo1 = function(data, options) { <snippet of code written by user> } var foo2 = function(data, options) { <snippet of code written by user> }

Parsing markup into Abstract Syntax Tree using Regular Expression

房东的猫 提交于 2019-12-25 05:01:41
问题 This question is supplementary to: Recursive processing of markup using Regular Expression and DOMDocument The code supplied by the selected answer has been a great help to understand building a basic syntax tree. However I am now having troubles tightening the regular expressions to only match my syntax rather than {. but not {{ . Ideally I would like it to only match my syntax which is: {<anchor>} {!image!} {*strong*} {/emphasis/} {|code|} {-strikethrough-} {>small<} Two tags, a and small

python/Pyqt5 - how to avoid eval while using ast and getting ValueError: malformed string in attemt to improve code safety

百般思念 提交于 2019-12-25 00:53:05
问题 I'm trying to prevent to use eval based on an example how-to-avoid-eval-in-python-for-string-conversion using ast . The challange is that there are a dozen of these self.ch%s_label 's to be made but the variable for it changes based on user input in the GUI. My code: import ast ...etc. .... channel_no += 1 ch_width = eval('self.ch%s_label.frameGeometry().width()' % (channel_no)) When I change it into: ch_width = ast.literal_eval('self.ch%s_label.frameGeometry().width()' % (channel_no)) I'll

Rewrite method incorrectly rewrite change to ICompilationUnit the second rewrite update

岁酱吖の 提交于 2019-12-25 00:17:35
问题 I have this method UpdateProperty: public void run(ObjectNavigatorModel model, String propertyKey, String propertyValue) { // get reference to CompilationUnit ICompilationUnit cu = model.getICompilationUnit(); try { cu.becomeWorkingCopy(null); } catch (JavaModelException e1) { e1.printStackTrace(); } // unit instance of CompilationUnit CompilationUnit unit = model.getCompilationUnit(); AST ast = unit.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); // get methods map MethodVisitor

AST module ['zero' 'zero' 'zero' 'zero' 2 'zero' 'zero' 'zero' 'zero' 'zero' 'zero' 7 ^ SyntaxError: invalid syntax

大憨熊 提交于 2019-12-24 20:09:30
问题 I have a pandas data frame, It contains a column that looks like this 0 [zero, zero, zero, zero, 2, zero, zero, zero, ... 1 [zero, zero, zero, 3, zero, zero, zero, 4, zer... 2 [zero, zero, zero, zero, zero, zero, zero, 2, ... 3 [1, zero, 6, 1, zero, zero, zero, zero, zero, ... 4 [zero, zero, zero, zero, 6, zero, zero, [2, 0]... Name: y, dtype: object this column is the output of this function def santa(the_frame): g = dict([[key, [*g]] for key, g in groupby(the_frame, key=lambda x: (x-1)//7)]

Handling line feed in ANTLR4 grammar with Python target

青春壹個敷衍的年華 提交于 2019-12-24 19:44:35
问题 I am working on an ANTLR4 grammar for parsing Python DSL scripts (a subset of Python, basically) with the target set as the Python 3 . I am having difficulties handling the line feed. In my grammar, I use lexer::members and NEWLINE embedded code based on Bart Kiers's Python3 grammar for ANTLR4 which are ported to Python so that they can be used with Python 3 runtime for ANTLR instead of Java. My grammar differs from the one provided by Bart (which is almost the same used in the Python 3 spec)

how to convert a hive query into abstract syntax tree?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 16:09:16
问题 Can anyone tell me how to convert a hive query into abstract syntax tree? For example: select * from orders where cust_num = 100; How can i convert this into AST? and how can i convert this AST into a QB tree? please help. Thanks in advance. 回答1: You can make use of EXPLAIN command with EXTENDED . Suppose I have a table called demo with a column as n1 , then issuing Explain would give me this : hive> EXPLAIN EXTENDED select * from demo where n1='aaa'; OK ABSTRACT SYNTAX TREE: (TOK_QUERY (TOK

JDT - Bindings are lost after copying subtree

痞子三分冷 提交于 2019-12-24 15:11:47
问题 I have a code that removes all complex (not SimpleName expressions) from if s. It works fine and the code like if(obj.getSomeInt() > 10) { /* body */ } is converted to boolean value = obj.getSomeInt() > 10; if(value) { /* body */ } But before changing AST the call to resolveBinding() and resolveTypeBinding() for obj gives correct results, but after I get null for the both calls. Is that as designed? If yes, please tell how to fix that? My code: if(node instanceof IfStatement) { IfStatement

rewriting code with ast; python

左心房为你撑大大i 提交于 2019-12-24 12:47:33
问题 I am learning AST and it seems like a powerful thing but I'm confused where the code went and why it disappeared. Say I want to rewrite example = """def fake(x):\n y = ['useless list']\n return x """ as example = """def fake(x):\n return x """ I can't see any way to rewrite in this manner. I can't even find a way to get the text of the line: In [1]: example = """def fake(x):\n ...: y = ['useless list']\n ...: return x ...: """ In [3]: import ast In [4]: p = ast.parse(example) In [5]: p Out[5]