Adding in the Integer bits.
This commit is contained in:
parent
ea326ee29b
commit
f14ccb6d22
@ -1,6 +1,8 @@
|
||||
from hy.models.expression import HyExpression
|
||||
from hy.models.integer import HyInteger
|
||||
from hy.models.symbol import HySymbol
|
||||
from hy.models.string import HyString
|
||||
|
||||
from hy.errors import HyError
|
||||
|
||||
|
||||
@ -12,6 +14,11 @@ class LexException(HyError):
|
||||
|
||||
|
||||
def _resolve_atom(obj):
|
||||
try:
|
||||
return HyInteger(obj)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return HySymbol(obj)
|
||||
|
||||
|
||||
|
7
hy/models/integer.py
Normal file
7
hy/models/integer.py
Normal file
@ -0,0 +1,7 @@
|
||||
from hy.models import HyObject
|
||||
|
||||
|
||||
class HyInteger(HyObject, int):
|
||||
def __new__(cls, number, *args, **kwargs):
|
||||
number = int(number)
|
||||
return super(HyInteger, cls).__new__(cls, number)
|
@ -1,8 +1,10 @@
|
||||
from hy.lex import tokenize
|
||||
from hy.models.expression import HyExpression
|
||||
from hy.models.integer import HyInteger
|
||||
from hy.models.symbol import HySymbol
|
||||
from hy.models.string import HyString
|
||||
|
||||
from hy.lex import tokenize
|
||||
|
||||
|
||||
def test_lex_expression_symbols():
|
||||
objs = tokenize("(foo bar)")
|
||||
@ -11,3 +13,7 @@ def test_lex_expression_symbols():
|
||||
def test_lex_expression_strings():
|
||||
objs = tokenize("(foo \"bar\")")
|
||||
assert objs == [HyExpression([HySymbol("foo"), HyString("bar")])]
|
||||
|
||||
def test_lex_expression_integer():
|
||||
objs = tokenize("(foo 2)")
|
||||
assert objs == [HyExpression([HySymbol("foo"), HyInteger(2)])]
|
||||
|
Loading…
Reference in New Issue
Block a user