I ended up writing a Python function that reads the contract and extracts constant definitions from it into a dictionary that can be used by other Python scripts:
import re
def get_integer_constant_definitions_from_contract(contract_path):
"""Searches through a smart contract for constant declarations.
Args:
contract_path: The file path of the contract to search.
Returns: A dictionary whose keys are the constant names and whose values
are the corresponding constant values.
"""
contract = open(contract_path, "r")
contract_text = contract.read()
# Matches constants with names in all caps and base 10 integer values.
p = re.compile("(^[A-Z][A-Z_]+).*=[ ]?([0-9]+)[ ]*$", re.MULTILINE)
base_10_matches = p.findall(contract_text)
constants = {}
for match in base_10_matches:
constants[match[0]] = int(match[1])
# Matches constants with names in all caps and hex integer values.
p = re.compile("(^[A-Z][A-Z_]+).*=[ ]?(0[Xx][0-9A-Fa-f]+)[ ]*$", re.MULTILINE)
hex_matches = p.findall(contract_text)
for match in hex_matches:
constants[match[0]] = int(match[1], 16)
return constants