diff --git a/pycalphad/io/tdb.py b/pycalphad/io/tdb.py index f1007e1c9..0c052c14f 100644 --- a/pycalphad/io/tdb.py +++ b/pycalphad/io/tdb.py @@ -180,7 +180,8 @@ def _tdb_grammar(): #pylint: disable=R0914 int_number = Word(nums).setParseAction(lambda t: [int(t[0])]) pos_neg_int_number = Word('+-'+nums).setParseAction(lambda t: [int(t[0])]) # '+3' or '-2' are examples # matching float w/ regex is ugly but is recommended by pyparsing - float_number = Regex(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?') \ + regex_after_decimal = r'([0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)' + float_number = Regex(r'[-+]?([0-9]+\.(?!([0-9]|[eE])))|{0}'.format(regex_after_decimal)) \ .setParseAction(lambda t: [float(t[0])]) # symbol name, e.g., phase name, function name symbol_name = Word(alphanums+'_:', min=1) diff --git a/pycalphad/tests/test_database.py b/pycalphad/tests/test_database.py index 3a861e436..030346a76 100644 --- a/pycalphad/tests/test_database.py +++ b/pycalphad/tests/test_database.py @@ -406,3 +406,18 @@ def test_tdb_missing_terminator_element(): FUNCTION EMBCCTI 298.15 -39.72; 6000 N !""" Database(tdb_str) + +def test_database_parsing_of_floats_with_no_values_after_decimal(): + """Floats with no values after the decimal should be properly parsed (gh-143)""" + tdb_string = """$ The element has no values after the decimal in '5004.' + ELEMENT CU FCC_A1 63.546 5004. 33.15 !""" + dbf = Database.from_string(tdb_string, fmt='tdb') + assert "CU" in dbf.elements + + +def test_database_parsing_of_floats_with_multiple_leading_zeros(): + """Floats with multiple leading zeros should be properly parsed (gh-143)""" + tdb_string = """$ The element has multiple leading zeros in '00.546' + ELEMENT CU FCC_A1 00.546 5004.0 33.15 !""" + dbf = Database.from_string(tdb_string, fmt='tdb') + assert "CU" in dbf.elements