Skip to content

Commit

Permalink
Add support for binary and octal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldedik committed Jul 14, 2021
1 parent 5134ad2 commit 82b8e44
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion neon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


__author__ = "Pavel Dedik"
__version__ = "0.1.6"
__version__ = "0.1.7"


from .decoder import parse
Expand Down
10 changes: 1 addition & 9 deletions neon/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from __future__ import unicode_literals

import re

import dateutil.parser

from . import errors
Expand All @@ -15,9 +13,6 @@
#: List of all tokens.
TOKENS = []

#: Pattern for matching hexadecimal numbers.
PATTERN_HEX = re.compile(r"0x[0-9a-fA-F]+")


def token(cls):
"""Registers a token class."""
Expand Down Expand Up @@ -108,10 +103,7 @@ class Integer(Primitive):
@classmethod
def convert(cls, string):
try:
if string.isdigit():
return int(string)
if PATTERN_HEX.match(string):
return int(string, base=16)
return int(string, 0)
except ValueError:
return

Expand Down
4 changes: 4 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_entity():
string: "a () #' text"
integer: 5902
hexint: 0xAA
octint: 0o666
binint: 0b111000111
float: 5.234
floatbig: 5e10
nones: [NULL, null, Null]
Expand All @@ -36,6 +38,8 @@ def test_types():
"string": "a () #' text",
"integer": 5902,
"hexint": 0xAA,
"octint": 0o666,
"binint": 0b111000111,
"float": 5.234,
"floatbig": 5e10,
"nones": [None] * 3,
Expand Down

0 comments on commit 82b8e44

Please sign in to comment.