[ck2cti] Allow stoichiometric coefficients ending in decimal points

Cherry-pick of trunk r2936.
This commit is contained in:
Ray Speth 2014-06-20 19:41:22 +00:00
parent b4779c4310
commit d787349771

View file

@ -39,9 +39,6 @@ import numpy as np
import re
import itertools
reFloat = re.compile(r'\+?\d*\.?\d+([eEdD][-+]?\d+)?$')
reInt = re.compile(r'\+?\d+$')
QUANTITY_UNITS = {'MOL': 'mol',
'MOLE': 'mol',
'MOLES': 'mol',
@ -1077,12 +1074,16 @@ class Parser(object):
j = reaction.find(token)
i = len(token)
reaction = reaction[:j] + ' '*i + reaction[j+i:]
if reInt.match(token):
if token == '+':
continue
try:
locs[j] = int(token), 'coeff'
elif reFloat.match(token):
locs[j] = float(token), 'coeff'
elif token != '+':
raise InputParseError('Unexpected token "{0}" in reaction expression "{1}".'.format(token, reaction))
except ValueError:
try:
locs[j] = float(token), 'coeff'
except ValueError:
raise InputParseError('Unexpected token "{0}" in reaction expression "{1}".'.format(token, reaction))
reactants = []
products = []