srcML / srcML

srcML Toolkit
srcml.org
GNU General Public License v3.0
105 stars 26 forks source link

Implement srcQL inside of libsrcml #1970

Open mlcollard opened 8 months ago

mlcollard commented 8 months ago

The srcQL query language has many advantages over XPath alone. To aid in the distribution of this tool, we will start to integrate the srcQL implementation as it develops. For now, this is limited to the "srcPat" or "srcPattern" part. I.e., source code with logical variables and no srcQL verbs. As verbs are added, the accepted range of srcQL queries will expand internally to libsrcml, however the interface will not have to change. Examples include:

srcml . --srcql='$T $U'
srcml . --srcql='$T $F($T)'

As can be seen above, there is an added option --srcql to the client. Note the use of single quotes on the command line to prevent bash expansion.

As for libsrcml, the following functions are added. See srcml.h for full function header comment.

/**
 * Append the srcQL query to the list of transformations/queries
 * ...
 */
int srcml_append_transform_srcql(struct srcml_archive* archive, const char* srcql_string);

/**
 * Append the srcQL query to the list of transformations/queries.
 * ...  
 */
int srcml_append_transform_srcql_attribute(struct srcml_archive* archive, const char* srcql_string,
                                                            const char* prefix, const char* namespace_uri,
                                                            const char* attr_name, const char* attr_value);

/**
 * Append the srcQL query to the list of transformations/queries.
 * ...
 */
int srcml_append_transform_srcql_element(struct srcml_archive* archive, const char* srcql_string,
                                                            const char* prefix, const char* namespace_uri,
                                                            const char* element);
mlcollard commented 8 months ago

This is almost completely implemented. Some of the test files (copied from the XPath client tests) are not fully converted.