CRAQL: A Composable Language for Querying Source Code

This paper describes the design and implementation of CRAQL (Composable Repository Analysis and Query Language), a new query language for source code. The growth of source code mining and its applications suggest the need for a query language that can fully utilize and correlate across the unique structure and metadata of parsed source code. CRAQL is built on an underlying abstraction analogous to the underpinnings of SQL, but aimed at parsed source code. Thus, while SQL queries' inputs and outputs are sets of tuples, CRAQL queries' inputs and outputs are sets of abstract syntax trees (ASTs). This abstraction makes CRAQL queries composable (the output of one query can become the input to another) and improves the power of the language by allowing for querying of the tree structure and metadata, as well as raw text. Furthermore, the abstraction enables tree-specific language optimizations and allows CRAQL to be easily applied to any language that is parsable into ASTs. These attributes, along with a familiar syntax similar to SQL, allow complex queries to be expressed in a compact, straightforward manner. Questions such as "find the longest series of statements without any loops," "find methods that are never called," "find getters (0-parameter methods with a single statement that returns a member variable)," or "find the percentage of variables declared at the top of a block" all translate to simple, understandable queries in CRAQL. In this paper we describe the language, its features and capabilities. We compare CRAQL to other languages for querying source code and find that it has potential advantages in clarity and compactness. We discuss the features and optimizations added to support searching parse tree collections effectively and efficiently. Finally, we summarize the application of the language to millions of Java source files, the details of which are in a companion paper.

[1]  Hridesh Rajan,et al.  Boa: A language and infrastructure for analyzing ultra-large-scale software repositories , 2013, 2013 35th International Conference on Software Engineering (ICSE).

[2]  Roger F. Crew ASTLOG: A Language for Examining Abstract Syntax Trees , 1997, DSL.

[3]  Juan Julián Merelo Guervós,et al.  Beyond source code: The importance of other artifacts in software development (a case study) , 2006, J. Syst. Softw..

[4]  Donald D. Chamberlin,et al.  XQuery: a query language for XML , 2003, SIGMOD '03.

[5]  Tsuyoshi Murata,et al.  {m , 1934, ACML.

[6]  Andy Zaidman,et al.  Journal of Software Maintenance and Evolution: Research and Practice Automatic Identification of Key Classes in a Software System Using Webmining Techniques , 2022 .

[7]  Benjamin Livshits,et al.  Finding application errors and security flaws using PQL: a program query language , 2005, OOPSLA '05.

[8]  Atul Prakash,et al.  Supporting Queries on Source Code: a Formal Framework , 1994, Int. J. Softw. Eng. Knowl. Eng..

[9]  Lori Pollock,et al.  Integrating natural language and program structure information to improve software search and exploration , 2010 .

[10]  Collin McMillan,et al.  Portfolio: Searching for relevant functions and their usages in millions of lines of code , 2013, TSEM.

[11]  Marko A. Rodriguez,et al.  The Gremlin graph traversal machine and language (invited talk) , 2015, DBPL.

[12]  Alan Mycroft,et al.  Programming language evolution via source code query languages , 2012, PLATEAU '12.

[13]  Gabriele Bavota,et al.  Automatic query reformulations for text retrieval in software engineering , 2013, 2013 35th International Conference on Software Engineering (ICSE).