Skip to content

Commit

Permalink
complex numbers starting with inf or nan and no sign now work; more c…
Browse files Browse the repository at this point in the history
…onsistent grammar
  • Loading branch information
gpoore committed Jul 12, 2017
1 parent 2812563 commit a48d140
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions bespon/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ def __init__(self, *args, **kwargs):
# delimiters are valid.
self._closing_delim_re_dict = tooling.keydefaultdict(lambda delim: grammar.gen_closing_delim_re(delim))

self._unquoted_string_or_key_path_ascii_re = re.compile(grammar.RE_GRAMMAR['unquoted_string_or_key_path_named_group_ascii'])
self._unquoted_string_or_key_path_below_u0590_re = re.compile(grammar.RE_GRAMMAR['unquoted_string_or_key_path_named_group_below_u0590'])
self._unquoted_string_or_key_path_unicode_re = re.compile(grammar.RE_GRAMMAR['unquoted_string_or_key_path_named_group_unicode'])
self._unquoted_string_or_key_path_ascii_re = re.compile(grammar.RE_GRAMMAR['unquoted_string_or_key_path_named_groups_ascii'])
self._unquoted_string_or_key_path_below_u0590_re = re.compile(grammar.RE_GRAMMAR['unquoted_string_or_key_path_named_groups_below_u0590'])
self._unquoted_string_or_key_path_unicode_re = re.compile(grammar.RE_GRAMMAR['unquoted_string_or_key_path_named_groups_unicode'])
self._alias_path_ascii_re = re.compile(grammar.RE_GRAMMAR['alias_path_ascii'])
self._alias_path_below_u0590_re = re.compile(grammar.RE_GRAMMAR['alias_path_below_u0590'])
self._alias_path_unicode_re = re.compile(grammar.RE_GRAMMAR['alias_path_unicode'])
Expand All @@ -461,6 +461,9 @@ def __init__(self, *args, **kwargs):
grammar.LIT_GRAMMAR['bool_false']: 'bool',
grammar.LIT_GRAMMAR['infinity_word']: 'float',
grammar.LIT_GRAMMAR['not_a_number_word']: 'float'}
if self.extended_types:
self._reserved_word_types[grammar.LIT_GRAMMAR['infinity_word']+grammar.LIT_GRAMMAR['imaginary_unit']] = 'complex'
self._reserved_word_types[grammar.LIT_GRAMMAR['not_a_number_word']+grammar.LIT_GRAMMAR['imaginary_unit']] = 'complex'


@staticmethod
Expand Down Expand Up @@ -1575,6 +1578,13 @@ def _parse_token_unquoted_string_or_key_path(self, line, state, section=False,
if raw_val.lower() in self._reserved_word_types:
raise erring.ParseError('Invalid capitalization of reserved word "{0}"'.format(raw_val.lower()), state)
raise erring.ParseError('Invalid use of reserved word "{0}"'.format(raw_val), state)
if self.extended_types and (implicit_type == 'float' or implicit_type == 'complex'):
# Handle the case of `inf...` or `nan...` when complex numbers
# are enabled. This could be done by creating a different
# regex for extended types that would capture the full complex
# number, but that would involve duplicating what already
# exists elsewhere (underscore handling, etc.).
return self._parse_token_number(raw_val+line, state)
if not state.full_ast:
node = ScalarNode(state, lineno, first_colno, lineno, last_colno, implicit_type)
else:
Expand Down
6 changes: 3 additions & 3 deletions bespon/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ def _capitalization_permutations_pattern(*words):
('key_path_unicode', '{unquoted_string_unicode}{key_path_continue_unicode}+'),

# Unquoted strings and key paths
('unquoted_string_or_key_path_named_group_ascii', r'''
('unquoted_string_or_key_path_named_groups_ascii', r'''
(?P<reserved_word>{reserved_word}(?!{unquoted_continue_ascii}|{path_separator})) |
(?P<unquoted_string>{unquoted_string_ascii}) (?P<key_path>{key_path_continue_ascii}+)?
'''.replace('\x20', '').replace('\n', '')),
('unquoted_string_or_key_path_named_group_below_u0590', r'''
('unquoted_string_or_key_path_named_groups_below_u0590', r'''
(?P<reserved_word>{reserved_word}(?!{unquoted_continue_below_u0590}|{path_separator})) |
(?P<unquoted_string>{unquoted_string_below_u0590}) (?P<key_path>{key_path_continue_below_u0590}+)?
'''.replace('\x20', '').replace('\n', '')),
('unquoted_string_or_key_path_named_group_unicode', r'''
('unquoted_string_or_key_path_named_groups_unicode', r'''
(?P<reserved_word>{reserved_word}(?!{unquoted_continue_unicode}|{path_separator})) |
(?P<unquoted_string>{unquoted_string_unicode}) (?P<key_path>{key_path_continue_unicode}+)?
'''.replace('\x20', '').replace('\n', '')),
Expand Down

0 comments on commit a48d140

Please sign in to comment.