Skip to content

Commit

Permalink
Merge pull request #106 from sbmlteam/sk-addtemplates
Browse files Browse the repository at this point in the history
Sk addtemplates
  • Loading branch information
skeating authored Oct 28, 2023
2 parents 24c55ab + 66032b2 commit 73aaec9
Show file tree
Hide file tree
Showing 50 changed files with 2,627 additions and 1,357 deletions.
103 changes: 51 additions & 52 deletions deviser/base_files/BaseTexFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
# ------------------------------------------------------------------------ -->


from ..util import global_variables, strFunctions
from . import BaseFile
from ..util import strFunctions


class BaseTexFile(BaseFile.BaseFile):
Expand All @@ -57,27 +57,40 @@ def __init__(self, name, extension, object_desc):
BaseFile.BaseFile.__init__(self, name, extension)

# change the comment delimiter and line length
self.comment = '%'
self.comment = "%"
self.line_length = 72

self.package = object_desc['name']
self.fullname = object_desc['fullname']
self.sbml_classes = object_desc['baseElements']
self.offset = object_desc['offset']
self.plugins = object_desc['plugins']
self.enums = object_desc['enums']
self.level = object_desc['base_level']
self.version = object_desc['base_version']
self.pkg_version = object_desc['pkg_version']
if object_desc['required']:
self.reqd_status = 'true'
if global_variables.is_sbml:
self.package = object_desc["name"]
self.fullname = object_desc["fullname"]
self.sbml_classes = object_desc["baseElements"]
self.offset = object_desc["offset"]
self.plugins = object_desc["plugins"]
self.enums = object_desc["enums"]
self.level = object_desc["base_level"]
self.version = object_desc["base_version"]
self.pkg_version = object_desc["pkg_version"]
if object_desc["required"]:
self.reqd_status = "true"
else:
self.reqd_status = "false"
else:
self.reqd_status = 'false'
self.package = ''
self.fullname = global_variables.package_full_name
self.sbml_classes = object_desc["baseElements"]
self.offset = object_desc["offset"]
self.plugins = []
self.enums = object_desc["enums"]
self.level = object_desc["base_level"]
self.version = object_desc["base_version"]
self.pkg_version = 0
self.reqd_status = "false"


self.prim_class = []

self.start_b = '{'
self.end_b = '}'
self.start_b = "{"
self.end_b = "}"

# expand the information for the classes
self.fulltexname = strFunctions.texify(self.fullname)
Expand All @@ -86,8 +99,12 @@ def __init__(self, name, extension, object_desc):
self.sort_attribute_names(self.sbml_classes)
self.sort_enum_names(self.enums)

self.full_pkg_command = '\\{0}Package'.format(self.fulltexname)
self.brief_pkg_command = '\\{0}'.format(self.upper_package)
if global_variables.is_sbml:
self.full_pkg_command = "\\{0}Package".format(self.fulltexname)
else:
self.full_pkg_command = "\\{0}".format(self.fulltexname)

self.brief_pkg_command = "\\{0}".format(self.upper_package)

########################################################################

Expand All @@ -99,14 +116,14 @@ def sort_class_names(self, classes):
"""
if classes is not None:
for i in range(0, len(classes)):
name = classes[i]['name']
name = classes[i]["name"]
texname = strFunctions.texify(name)
classes[i]['texname'] = texname
classes[i]["texname"] = texname
# hack for render
if name == 'Ellipse' or name == 'Rectangle':
texname = 'Render' + name
classes[i]['texname'] = texname
if name == 'RelAbsVector':
if name == "Ellipse" or name == "Rectangle":
texname = "Render" + name
classes[i]["texname"] = texname
if name == "RelAbsVector":
self.prim_class.append(classes[i])

@staticmethod
Expand All @@ -118,28 +135,12 @@ def sort_attribute_names(classes):
"""
if classes is not None:
for i in range(0, len(classes)):
attribs = classes[i]['attribs']
attribs = classes[i]["attribs"]
BaseTexFile.update_attrib_dicts(attribs)
# for j in range(0, len(attribs)):
# if attribs[j]['type'] in ['lo_element', 'element',
# 'inline_lo_element']:
# name = attribs[j]['element']
# else:
# name = attribs[j]['name']
# texname = strFunctions.texify(name)
# attribs[j]['texname'] = texname
for i in range(0, len(classes)):
if 'lo_attribs' in classes[i]:
lo_attribs = classes[i]['lo_attribs']
if "lo_attribs" in classes[i]:
lo_attribs = classes[i]["lo_attribs"]
BaseTexFile.update_attrib_dicts(lo_attribs)
# for j in range(0, len(lo_attribs)):
# if lo_attribs[j]['type'] in ['lo_element', 'element',
# 'inline_lo_element']:
# name = lo_attribs[j]['element']
# else:
# name = lo_attribs[j]['name']
# texname = strFunctions.texify(name)
# lo_attribs[j]['texname'] = texname

@staticmethod
def update_attrib_dicts(my_list):
Expand All @@ -149,13 +150,12 @@ def update_attrib_dicts(my_list):
:param my_list: the list which we update.
"""
for j in range(0, len(my_list)):
if my_list[j]['type'] in ['lo_element', 'element',
'inline_lo_element']:
name = my_list[j]['element']
if my_list[j]["type"] in ["lo_element", "element", "inline_lo_element"]:
name = my_list[j]["element"]
else:
name = my_list[j]['name']
name = my_list[j]["name"]
texname = strFunctions.texify(name)
my_list[j]['texname'] = texname
my_list[j]["texname"] = texname

@staticmethod
def sort_enum_names(enums):
Expand All @@ -166,9 +166,9 @@ def sort_enum_names(enums):
"""
if enums is not None:
for i in range(0, len(enums)):
name = enums[i]['name']
name = enums[i]["name"]
texname = strFunctions.texify(name)
enums[i]['texname'] = texname
enums[i]["texname"] = texname

def write_to_do(self, text):
"""
Expand All @@ -177,8 +177,7 @@ def write_to_do(self, text):
:param text: the text describing the TODO.
"""
self.write_text_line('\\TODO{0}{1}{2}'.format(self.start_b, text,
self.end_b))
self.write_text_line("\\TODO{0}{1}{2}".format(self.start_b, text, self.end_b))
self.skip_line()

def write_text_line(self, line):
Expand Down
7 changes: 6 additions & 1 deletion deviser/code_files/ExtensionHeaderFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ def write_all_elements(self):
prefixed_name = '{0}{1}'.format(global_variables.prefix, name)
new_element = dict({'name': prefixed_name})
elements.append(new_element)
others = ['List', 'ListNode', 'ExpectedAttributes']
for name in others:
new_element = dict({'name': name})
elements.append(new_element)
self.write_classes(elements)
new_length = len(elements)
for i in range(new_length, no_elements, -1):
Expand Down Expand Up @@ -483,7 +487,8 @@ def write_fwd_file(self):
self.write_cppns_end()
# if we are in another library and using either ASTNode or XMLNode
# we need to declare these here
if global_variables.uses_ASTNode or global_variables.uses_XMLNode:
# don't need xmlnode for now
if global_variables.uses_ASTNode:
self.write_libsbml_fwd()
self.write_end_class_or_struct()
self.write_defn_end()
Expand Down
6 changes: 3 additions & 3 deletions deviser/code_files/OtherLibraryFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ def print_document_errors(self, fileout):
docname = SF.remove_prefix(doc['name'], remove_package=False,
remove_doc_prefix=True)
libname = SF.get_library_suffix(gv.library_name)
if not libname.endswith('ml'):
libname = libname + 'ml'
fileout.copy_line_verbatim((10 * '') + 'if ( errorId == {0}{1}Allowed'
# if not libname.endswith('ml'):
# libname = libname + 'ml'
fileout.copy_line_verbatim((10 * ' ') + 'if ( errorId == {0}{1}Allowed'
'CoreAttributes\n'.format(libname, docname))
level = False
version = False
Expand Down
68 changes: 54 additions & 14 deletions deviser/code_files/ValidationFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ def create_rule_structure(self):
rules = ValidationRulesGeneral\
.ValidationRulesGeneral(self.fullname, number, self.package,
self.pkg_ref, self.level, self.version,
self.pkg_version, self.reqd_status)
self.pkg_version, self.reqd_status,
global_variables.language)
rules.determine_rules()
self.class_rules += rules.rules
if global_variables.is_package:
number = self.offset + 20200
else:
number = 20200
number = self.offset + 20200 if global_variables.is_sbml else 20100
# if global_variables.is_package:
# number = self.offset + 20200
# else:
# number = 20200
for i in range(0, len(self.plugins)):
rules = ValidationRulesForPlugin.ValidationRulesForPlugin(
self.plugins[i], self.fullname, number,
Expand All @@ -130,6 +132,15 @@ def create_rule_structure(self):
self.pkg_ref)
rules.determine_rules()
self.class_rules += rules.rules
if not global_variables.is_sbml:
for att in self.sbml_classes[i]['attribs']:
if att['type'] == 'lo_element':
rules.rules = []
number += 100
rules.number = number
rules.add_lo_rules()
self.class_rules += rules.rules

number += 100
self.populate_error_list()

Expand Down Expand Up @@ -437,28 +448,36 @@ def is_package(i, text_string, length):
is_package = True
return [is_package, len_word]

@staticmethod
def replace_name(i, text_string, length):
def replace_name(self, i, text_string, length):
in_name = True
return_name_rep = ''
# we dont want to lower the s of SBase
# or name if it starts with the prefix for the language
isSBase = False
is_language_prefix = False
num_letters = 0
while in_name and i < length:
letter = text_string[i]
if i != length-1:
next_letter = text_string[i+1]
else:
next_letter = ' '
if letter == '\\':
isSBase = False
# we dont want to lower the s of SBase
if next_letter == 'S' or next_letter == 's':
test_str = text_string[i+1:i+7]
if test_str.lower() == 'sbase ':
isSBase = True
if global_variables.is_sbml:
isSBase = self.is_sbase(text_string, i, next_letter)
else:
[is_language_prefix, num_letters] = self.is_language_prefix(text_string, i, next_letter)
if isSBase:
return_name_rep += '\'S'
i += 1
elif is_language_prefix:
return_name_rep += '<'
for j in range(0, num_letters):
return_name_rep += '{0}'.format(text_string[i + j + 1].upper())
i += num_letters
else:
return_name_rep += '<{0}'.format(next_letter.lower())
i += 1
i += 1
elif next_letter == ' ' or next_letter == '.':
if isSBase:
return_name_rep += '{0}\''.format(letter)
Expand All @@ -471,6 +490,27 @@ def replace_name(i, text_string, length):
continue
return [i-1, return_name_rep]

def is_language_prefix(self, text, index, next_letter):
prefix = global_variables.language.upper()
if not prefix.startswith(next_letter):
return [False, 0]
length_prefix = len(prefix)
match = True
for i in range(0, length_prefix):
if prefix[i] != text[index + i + 1]:
match = False
return [match, length_prefix]

@staticmethod
def is_sbase(text, index, next_letter):
if len(text) < index + 7:
return False
if next_letter == 'S' or next_letter == 's':
test_str = text[index + 1:index + 7]
if test_str.lower() == 'sbase ':
return True
return False

@staticmethod
def replace_uri(i, text_string, length):
in_uri = True
Expand Down
2 changes: 1 addition & 1 deletion deviser/code_files/templates/ConstructorException.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SBML_CONSTRUCTOR_EXCEPTION_H
#define SBML_CONSTRUCTOR_EXCEPTION_H

#include <common/extern.h>
#include <sbml/common/extern.h>
#include <sbml/SBMLNamespaces.h>

#ifdef __cplusplus
Expand Down
13 changes: 1 addition & 12 deletions deviser/code_files/templates/Error.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SBMLError_h
#define SBMLError_h

#include <common/extern.h>
#include <sbml/common/extern.h>
<verbatim>
#include <xml/XMLError.h>
</verbatim>
Expand All @@ -21,17 +21,6 @@ typedef enum
, SBMLNotUTF8 = 10001 /*!< File does not use UTF-8 encoding. */
, SBMLUnrecognizedElement = 10002 /*!< Encountered unrecognized element. */
, SBMLNotSchemaConformant = 10003 /*!< Document does not conform to the SBML_Lang XML schema. */
, SBMLInvalidMathElement = 10201
, SBMLMissing<Annotation>Namespace = 10401 /*!< Missing declaration of the XML namespace for the annotation. */
, SBMLDuplicate<Annotation>Namespaces = 10402 /*!< Multiple annotations using the same XML namespace. */
, SBMLNamespaceIn<Annotation> = 10403 /*!< The SBML_Lang XML namespace cannot be used in an <Annotation> object. */
, SBMLMultiple<Annotation>s = 10404 /*!< Only one <Annotation> object is permitted under a given SBML_Lang object. */
, SBML<Annotation>NotElement = 10405
, SBMLNotesNotInXHTMLNamespace = 10801 /*!< Notes must be placed in the XHTML XML namespace. */
, SBMLNotesContainsXMLDecl = 10802 /*!< XML declarations are not permitted in Notes objects. */
, SBMLNotesContainsDOCTYPE = 10803 /*!< XML DOCTYPE elements are not permitted in Notes objects. */
, SBMLInvalidNotesContent = 10804 /*!< Invalid notes content found. */
, SBMLOnlyOneNotesElementAllowed = 10805 /*!< Only one Notes subobject is permitted on a given SBML_Lang object. */
<add_specific_errors/>
, SBMLUnknownCoreAttribute = 99994 /*!< Encountered an unknown attribute in the SBML_Lang Core namespace. */
, SBMLCodesUpperBound = 99999 /*!< Upper boundary of libSBML-specific diagnostic codes. */
Expand Down
4 changes: 2 additions & 2 deletions deviser/code_files/templates/ErrorLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <sbml/common/extern.h>
<verbatim>
#include <sbml/xml/XMLError.h>
#include <sbml/xml/XMLErrorLog.h>
#include <xml/XMLError.h>
#include <xml/XMLErrorLog.h>
</verbatim>
#include <sbml/SBMLError.h>

Expand Down
Loading

0 comments on commit 73aaec9

Please sign in to comment.