Rebuilding.
This commit is contained in:
parent
84453e75d2
commit
5c6d98a24a
@ -4,4 +4,4 @@ from hy.lex.states import Idle
|
|||||||
def tokenize(buf):
|
def tokenize(buf):
|
||||||
machine = Machine(Idle, 0, 0)
|
machine = Machine(Idle, 0, 0)
|
||||||
machine.process(buf)
|
machine.process(buf)
|
||||||
print machine.nodes
|
return machine.nodes
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
from hy.models.expression import HyExpression
|
||||||
|
from hy.models.symbol import HySymbol
|
||||||
from hy.errors import HyError
|
from hy.errors import HyError
|
||||||
|
|
||||||
|
|
||||||
WHITESPACE = [" ", "\t", "\n", "\r"]
|
WHITESPACE = [" ", "\t", "\n", "\r"]
|
||||||
|
|
||||||
|
|
||||||
@ -7,6 +10,10 @@ class LexException(HyError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_atom(obj):
|
||||||
|
return HySymbol(obj)
|
||||||
|
|
||||||
|
|
||||||
class State(object):
|
class State(object):
|
||||||
__slots__ = ("machine",)
|
__slots__ = ("machine",)
|
||||||
|
|
||||||
@ -26,12 +33,12 @@ class Expression(State):
|
|||||||
self.buf = ""
|
self.buf = ""
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
self.nodes.append(self.buf)
|
self.nodes.append(_resolve_atom(self.buf))
|
||||||
self.buf = ""
|
self.buf = ""
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
self.commit()
|
self.commit()
|
||||||
self.machine.nodes.append(self.nodes)
|
self.machine.nodes.append(HyExpression(self.nodes))
|
||||||
|
|
||||||
def process(self, char):
|
def process(self, char):
|
||||||
if char == ")":
|
if char == ")":
|
||||||
|
4
hy/models/__init__.py
Normal file
4
hy/models/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class HyObject(object):
|
||||||
|
pass
|
5
hy/models/expression.py
Normal file
5
hy/models/expression.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from hy.models import HyObject
|
||||||
|
|
||||||
|
|
||||||
|
class HyExpression(HyObject, list):
|
||||||
|
pass
|
14
hy/models/string.py
Normal file
14
hy/models/string.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from hy.models import HyObject
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
_str_type = str
|
||||||
|
else:
|
||||||
|
_str_type = unicode
|
||||||
|
|
||||||
|
|
||||||
|
class HyString(HyObject, _str_type):
|
||||||
|
def __new__(cls, value):
|
||||||
|
obj = _str_type.__new__(cls, value)
|
||||||
|
return obj
|
10
hy/models/symbol.py
Normal file
10
hy/models/symbol.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from hy.models.string import HyString
|
||||||
|
|
||||||
|
|
||||||
|
class HySymbol(HyString):
|
||||||
|
def __init__(self, string):
|
||||||
|
self += string
|
||||||
|
|
||||||
|
def eval(self, lns, *args, **kwargs):
|
||||||
|
obj = self.lookup(lns, self)
|
||||||
|
return obj
|
@ -1,5 +1,8 @@
|
|||||||
from hy.lex import tokenize
|
from hy.lex import tokenize
|
||||||
|
from hy.models.expression import HyExpression
|
||||||
|
from hy.models.symbol import HySymbol
|
||||||
|
|
||||||
|
|
||||||
def test_lex_expression():
|
def test_lex_expression():
|
||||||
objs = tokenize("(foo bar)")
|
objs = tokenize("(foo bar)")
|
||||||
|
assert objs == [HyExpression([HySymbol("foo"), HySymbol("bar")])]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user