scripts: Handle vk.xml latexmath in helper files

The vk.xml file contains latex-formatted metadata which must be
parsed for codegen.

Change-Id: Ie64c9974371d2bb66ba460165a0c23505991ebd7
diff --git a/scripts/helper_file_generator.py b/scripts/helper_file_generator.py
index 89d0788..e64dd8a 100644
--- a/scripts/helper_file_generator.py
+++ b/scripts/helper_file_generator.py
@@ -190,6 +190,24 @@
             elif elem.tag == 'name':
                 name = noneStr(elem.text)
         return (type, name)
+    # Extract length values from latexmath.  Currently an inflexible solution that looks for specific
+    # patterns that are found in vk.xml.  Will need to be updated when new patterns are introduced.
+    def parseLateXMath(self, source):
+        name = 'ERROR'
+        decoratedName = 'ERROR'
+        if 'mathit' in source:
+            # Matches expressions similar to 'latexmath:[$\lceil{\mathit{rasterizationSamples} \over 32}\rceil$]'
+            match = re.match(r'latexmath\s*\:\s*\[\s*\$\\l(\w+)\s*\{\s*\\mathit\s*\{\s*(\w+)\s*\}\s*\\over\s*(\d+)\s*\}\s*\\r(\w+)\$\s*\]', source)
+            if not match or match.group(1) != match.group(4):
+                raise 'Unrecognized latexmath expression'
+            name = match.group(2)
+            decoratedName = '{}/{}'.format(*match.group(2, 3))
+        else:
+            # Matches expressions similar to 'latexmath : [$dataSize \over 4$]'
+            match = re.match(r'latexmath\s*\:\s*\[\s*\$\s*(\w+)\s*\\over\s*(\d+)\s*\$\s*\]', source)
+            name = match.group(1)
+            decoratedName = '{}/{}'.format(*match.group(1, 2))
+        return name, decoratedName
     #
     # Retrieve the value of the len tag
     def getLen(self, param):
@@ -203,6 +221,9 @@
                 result = len.split(',')[0]
             else:
                 result = len
+            if 'latexmath' in len:
+                param_type, param_name = self.getTypeNameTuple(param)
+                len_name, result = self.parseLateXMath(len)
             # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol
             result = str(result).replace('::', '->')
         return result