mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C++, parse more types of integer literals
Fixes case 0 of sphinx-doc/sphinx#4114
This commit is contained in:
parent
466241d43a
commit
0aa9d4c87e
@ -290,7 +290,11 @@ logger = logging.getLogger(__name__)
|
||||
"""
|
||||
|
||||
# TODO: support hex, oct, etc. work
|
||||
_integer_literal_re = re.compile(r'-?[1-9][0-9]*')
|
||||
_integer_literal_re = re.compile(r'[1-9][0-9]*')
|
||||
_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]+')
|
||||
_identifier_re = re.compile(r'(~?\b[a-zA-Z_][a-zA-Z0-9_]*)\b')
|
||||
_whitespace_re = re.compile(r'(?u)\s+')
|
||||
@ -3781,10 +3785,14 @@ class DefinitionParser(object):
|
||||
return ASTBooleanLiteral(True)
|
||||
if self.skip_word('false'):
|
||||
return ASTBooleanLiteral(False)
|
||||
if self.match(_float_literal_re):
|
||||
return ASTNumberLiteral(self.matched_text)
|
||||
if self.match(_integer_literal_re):
|
||||
return ASTNumberLiteral(self.matched_text)
|
||||
for regex in [_float_literal_re, _binary_literal_re, _hex_literal_re,
|
||||
_integer_literal_re, _octal_literal_re]:
|
||||
pos = self.pos
|
||||
if self.match(regex):
|
||||
while self.current_char in 'uUlLfF':
|
||||
self.pos += 1
|
||||
return ASTNumberLiteral(self.definition[pos:self.pos])
|
||||
|
||||
string = self._parse_string()
|
||||
if string is not None:
|
||||
return ASTStringLiteral(string)
|
||||
|
@ -111,9 +111,20 @@ def test_expressions():
|
||||
exprCheck('nullptr', 'LDnE')
|
||||
exprCheck('true', 'L1E')
|
||||
exprCheck('false', 'L0E')
|
||||
exprCheck('5', 'L5E')
|
||||
exprCheck('5.0', 'L5.0E')
|
||||
exprCheck('"abc\\"cba"', 'LA8_KcE')
|
||||
ints = ['5', '0', '075', '0xF', '0XF', '0b1', '0B1']
|
||||
unsignedSuffix = ['', 'u', 'U']
|
||||
longSuffix = ['', 'l', 'L', 'll', 'LL']
|
||||
for i in ints:
|
||||
for u in unsignedSuffix:
|
||||
for l in longSuffix:
|
||||
expr = i + u + l;
|
||||
exprCheck(expr, 'L' + expr + 'E')
|
||||
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')
|
||||
exprCheck('"abc\\"cba"', 'LA8_KcE') # string
|
||||
# TODO: test the rest
|
||||
exprCheck('(... + Ns)', '(... + Ns)')
|
||||
exprCheck('(5)', 'L5E')
|
||||
|
Loading…
Reference in New Issue
Block a user