Skip to content

Commit

Permalink
Fixed incorrect tokenization case "d*e-1". Fixes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Jul 25, 2017
1 parent 08c7561 commit bf09850
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion baron/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def group_generator(sequence):
if re.match(r'^\d+\.?[eE]$', current) and match_on_next(r'^\d+$', iterator):
current += next(iterator)

if re.match(r'^\d*\.?\d*[eE]$', current) and match_on_next(r'^[-+]$', iterator) and iterator.show_next(2) and re.match(r'^\d+$', iterator.show_next(2)):
if re.match(r'^\d*\.?\d*[eE]$', current) and not re.match('[eE]', current) and match_on_next(r'^[-+]$', iterator) and iterator.show_next(2) and re.match(r'^\d+$', iterator.show_next(2)):
current += next(iterator)
current += next(iterator)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,7 @@ def test_try_import_after_colon():

def test_single_object():
assert baron.dumps({"type": "name", "value": "a"}) == "a"


def test_crash_issue_85():
check_dumps('d*e-1\n')
16 changes: 16 additions & 0 deletions tests/test_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def test_float_exponant():
match('.5678E-10', 'FLOAT_EXPONANT')


def test_floating_point_parser_bug_85():
from baron import parse
assert parse('d*e-1') == [
{'first': {'first': {'type': 'name', 'value': 'd'},
'first_formatting': [],
'second': {'type': 'name', 'value': 'e'},
'second_formatting': [],
'type': 'binary_operator',
'value': '*'},
'first_formatting': [],
'second': {'section': 'number', 'type': 'int', 'value': '1'},
'second_formatting': [],
'type': 'binary_operator',
'value': '-'}]


def test_left_parenthesis():
match('(', 'LEFT_PARENTHESIS')

Expand Down

0 comments on commit bf09850

Please sign in to comment.