From b3de33deeffb97982e5b89e7cabaed9e361900b3 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sun, 16 Dec 2018 16:56:55 +0100 Subject: [PATCH] C++, fix parsing of floating point literals Fixes sphinx-doc/sphinx#5636 --- CHANGES | 1 + sphinx/domains/cpp.py | 13 ++++++++++++- tests/test_domain_cpp.py | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 6482e7f86..867b1dad9 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,7 @@ Bugs fixed * #5627: qthelp: index.html missing in QtHelp * #5659: linkcheck: crashes for a hyperlink containing multibyte character * #5754: DOC: Fix some mistakes in :doc:`/latex` +* #5636: C++, fix parsing of floating point literals. Testing -------- diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 5dfd8f5c3..7a84c3ba6 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -294,7 +294,18 @@ _octal_literal_re = re.compile(r'0[0-7]*') _hex_literal_re = re.compile(r'0[xX][0-7a-fA-F][0-7a-fA-F]*') _binary_literal_re = re.compile(r'0[bB][01][01]*') _integer_suffix_re = re.compile(r'') -_float_literal_re = re.compile(r'[+-]?[0-9]*\.[0-9]+') +_float_literal_re = re.compile(r'''(?x) + [+-]?( + # decimal + ([0-9]+[eE][+-]?[0-9]+) + | ([0-9]*\.[0-9]+([eE][+-]?[0-9]+)?) + | ([0-9]+\.([eE][+-]?[0-9]+)?) + # hex + | (0[xX][0-9a-fA-F]+[pP][+-]?[0-9a-fA-F]+) + | (0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+([pP][+-]?[0-9a-fA-F]+)?) + | (0[xX][0-9a-fA-F]+\.([pP][+-]?[0-9a-fA-F]+)?) + ) +''') _char_literal_re = re.compile(r'''(?x) ((?:u8)|u|U|L)? '( diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index b8856824b..2602f73e6 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -124,8 +124,20 @@ def test_expressions(): expr = i + l + u exprCheck(expr, 'L' + expr + 'E') for suffix in ['', 'f', 'F', 'l', 'L']: - expr = '5.0' + suffix - exprCheck(expr, 'L' + expr + 'E') + for e in [ + '5e42', '5e+42', '5e-42', + '5.', '5.e42', '5.e+42', '5.e-42', + '.5', '.5e42', '.5e+42', '.5e-42', + '5.0', '5.0e42','5.0e+42', '5.0e-42']: + expr = e + suffix + exprCheck(expr, 'L' + expr + 'E') + for e in [ + 'ApF', 'Ap+F', 'Ap-F', + 'A.', 'A.pF', 'A.p+F', 'A.p-F', + '.A', '.ApF', '.Ap+F', '.Ap-F', + 'A.B', 'A.BpF','A.Bp+F', 'A.Bp-F']: + expr = "0x" + e + suffix + exprCheck(expr, 'L' + expr + 'E') exprCheck('"abc\\"cba"', 'LA8_KcE') # string exprCheck('this', 'fpT') # character literals