Skip to content

Commit b9752b9

Browse files
committed
Add srcql functions for upcoming release. Not tested yet
1 parent 17862fa commit b9752b9

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

globals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,18 @@
492492
libsrcml.srcml_append_transform_relaxng_fd.restype = c_int
493493
libsrcml.srcml_append_transform_relaxng_fd.argtypes = [c_void_p, c_int]
494494

495+
# int srcml_append_transform_srcql(struct srcml_archive* archive, const char* srcql_string);
496+
libsrcml.srcml_append_transform_srcql.restype = c_int
497+
libsrcml.srcml_append_transform_srcql.argtypes = [c_void_p, c_char_p]
498+
499+
# 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);
500+
libsrcml.srcml_append_transform_srcql_attribute.restype = c_int
501+
libsrcml.srcml_append_transform_srcql_attribute.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p, c_char_p, c_char_p]
502+
503+
# int srcml_append_transform_srcql_element(struct srcml_archive* archive, const char* srcql_string, const char* prefix, const char* namespace_uri, const char* element);
504+
libsrcml.srcml_append_transform_srcql_element.restype = c_int
505+
libsrcml.srcml_append_transform_srcql_element.argtypes = [c_void_p, c_char_p, c_char_p, c_char_p, c_char_p]
506+
495507
# int srcml_append_transform_param(struct srcml_archive* archive, const char* param_name, const char* param_value);
496508
libsrcml.srcml_append_transform_param.restype = c_int
497509
libsrcml.srcml_append_transform_param.argtypes = [c_void_p, c_char_p, c_char_p]

srcml_archive.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def append_transform_xpath_attribute(self, xpath_string: str, prefix: str, names
558558
# Parameter: element -> Element name
559559
# Return: CHANGED FOR PYLIBSRCML: returns nothing, simply raises an error if status isn't OK
560560
# -------------------------------------------------------------------------------------------
561-
def append_transform_xpath_element(self, xpath_string: str, prefix: str, namespace_uri: str, element: str) :
561+
def append_transform_xpath_element(self, xpath_string: str, prefix: str, namespace_uri: str, element: str) -> None:
562562
if type(xpath_string) != str:
563563
raise srcMLTypeError(self.append_transform_xpath_element,"xpath_string",xpath_string)
564564
if type(prefix) != str:
@@ -647,6 +647,55 @@ def append_transform_relaxng_file(self, relaxng_file: File) :
647647
raise srcMLTypeError(self.append_transform_relaxng_file,"relaxng_file",relaxng_file)
648648
check_srcml_status(libsrcml.srcml_append_transform_relaxng_fd(self.c_archive, relaxng_file.fileno()))
649649

650+
# -------------------------------------------------------------------------------------------
651+
# Append the srcQL query to the list of transformations/queries
652+
# -------------------------------------------------------------------------------------------
653+
def append_transform_srcql(self, srcql_string: str) -> None:
654+
if type(srcql_string) != str:
655+
raise srcMLTypeError(self.append_transform_srcql,"srcql_string",srcql_string)
656+
657+
status = libsrcml.srcml_append_transform_srcql(self.c_archive, srcql_string.encode())
658+
check_srcml_status(status)
659+
660+
# -------------------------------------------------------------------------------------------
661+
# Append the srcQL query to the list of transformations/queries.
662+
# Instead of outputting the results in a separate unit tag, output the complete
663+
# archive marking the XPath results with a user provided element.
664+
# -------------------------------------------------------------------------------------------
665+
def append_transform_srcql_attribute(self, srcql_string: str, prefix: str, namespace_uri: str, attr_name: str, attr_value: str) -> None:
666+
if type(srcql_string) != str:
667+
raise srcMLTypeError(self.append_transform_srcql_attribute,"srcql_string",srcql_string)
668+
if type(prefix) != str:
669+
raise srcMLTypeError(self.append_transform_srcql_attribute,"prefix",prefix)
670+
if type(namespace_uri) != str:
671+
raise srcMLTypeError(self.append_transform_srcql_attribute,"namespace_uri",namespace_uri)
672+
if type(attr_name) != str:
673+
raise srcMLTypeError(self.append_transform_srcql_attribute,"attr_name",attr_name)
674+
if type(attr_value) != str:
675+
raise srcMLTypeError(self.append_transform_srcql_attribute,"attr_value",attr_value)
676+
677+
status = libsrcml.srcml_append_transform_srcql_attribute(self.c_archive, srcql_string.encode(), prefix.encode(), namespace_uri.encode(), attr_name.encode(), attr_value.encode())
678+
check_srcml_status(status)
679+
680+
681+
# -------------------------------------------------------------------------------------------
682+
# Append the srcQL query to the list of transformations/queries.
683+
# Instead of outputting the results in a separate unit tag, output the complete
684+
# archive marking the XPath results with a user provided element.
685+
# -------------------------------------------------------------------------------------------
686+
def append_transform_srcql_element(self, srcql_string: str, prefix: str, namespace_uri: str, element: str) -> None:
687+
if type(srcql_string) != str:
688+
raise srcMLTypeError(self.append_transform_srcql_element,"srcql_string",srcql_string)
689+
if type(prefix) != str:
690+
raise srcMLTypeError(self.append_transform_srcql_element,"prefix",prefix)
691+
if type(namespace_uri) != str:
692+
raise srcMLTypeError(self.append_transform_srcql_element,"namespace_uri",namespace_uri)
693+
if type(element) != str:
694+
raise srcMLTypeError(self.append_transform_srcql_element,"element",element)
695+
696+
status = libsrcml.srcml_append_transform_srcql_element(self.c_archive, srcql_string.encode(), prefix.encode(), namespace_uri.encode(), element.encode())
697+
check_srcml_status(status)
698+
650699
# -------------------------------------------------------------------------------------------
651700
# Append an XSLT parameter to the last transformation
652701
# Parameter: param_name -> Name of a parameter

0 commit comments

Comments
 (0)