futzing with ideas
This commit is contained in:
parent
0638cfa187
commit
7a925b5ee4
@ -62,7 +62,7 @@ class HyASTCompiler(object):
|
|||||||
ret = []
|
ret = []
|
||||||
tree.reverse()
|
tree.reverse()
|
||||||
|
|
||||||
if self.returnable:
|
if self.returnable and len(tree) > 0:
|
||||||
el = tree.pop()
|
el = tree.pop()
|
||||||
if not isinstance(el, ast.stmt):
|
if not isinstance(el, ast.stmt):
|
||||||
ret.append(ast.Return(value=el,
|
ret.append(ast.Return(value=el,
|
||||||
|
@ -65,7 +65,7 @@ class Machine(object):
|
|||||||
"""
|
"""
|
||||||
Accept and annotate the result.
|
Accept and annotate the result.
|
||||||
"""
|
"""
|
||||||
if state and state.result:
|
if state and not state.result is None:
|
||||||
result = state.result
|
result = state.result
|
||||||
|
|
||||||
result.start_line, result.end_line = (self.start_line, self.line)
|
result.start_line, result.end_line = (self.start_line, self.line)
|
||||||
@ -87,14 +87,12 @@ class Machine(object):
|
|||||||
if self.submachine:
|
if self.submachine:
|
||||||
self.submachine.process([char])
|
self.submachine.process([char])
|
||||||
if type(self.submachine.state) == Idle:
|
if type(self.submachine.state) == Idle:
|
||||||
if len(self.submachine.nodes) > 1:
|
if len(self.submachine.nodes) != 1:
|
||||||
raise LexException("Funky Submachine stuff")
|
raise LexException("Funky Submachine stuff")
|
||||||
|
|
||||||
nodes = self.submachine.nodes
|
nodes = self.submachine.nodes
|
||||||
self.submachine = None
|
self.submachine = None
|
||||||
|
self.state.nodes.append(nodes[0])
|
||||||
if len(nodes) > 0:
|
|
||||||
self.state.nodes.append(nodes[0])
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
new = self.state.process(char)
|
new = self.state.process(char)
|
||||||
|
@ -22,6 +22,7 @@ from hy.models.expression import HyExpression
|
|||||||
from hy.models.integer import HyInteger
|
from hy.models.integer import HyInteger
|
||||||
from hy.models.symbol import HySymbol
|
from hy.models.symbol import HySymbol
|
||||||
from hy.models.string import HyString
|
from hy.models.string import HyString
|
||||||
|
from hy.models.list import HyList
|
||||||
|
|
||||||
from hy.errors import HyError
|
from hy.errors import HyError
|
||||||
|
|
||||||
@ -95,14 +96,7 @@ class State(object):
|
|||||||
pass # ABC
|
pass # ABC
|
||||||
|
|
||||||
|
|
||||||
class Expression(State):
|
class List(State):
|
||||||
"""
|
|
||||||
Expression state. This will handle stuff like:
|
|
||||||
|
|
||||||
(...... (....))
|
|
||||||
^^^^^^ -- expression
|
|
||||||
^^^^^^^^^^^^^^^ -- expression
|
|
||||||
"""
|
|
||||||
|
|
||||||
def enter(self):
|
def enter(self):
|
||||||
self.buf = ""
|
self.buf = ""
|
||||||
@ -118,12 +112,52 @@ class Expression(State):
|
|||||||
self.nodes.append(ret)
|
self.nodes.append(ret)
|
||||||
self.buf = ""
|
self.buf = ""
|
||||||
|
|
||||||
|
def exit(self):
|
||||||
|
self.commit()
|
||||||
|
self.result = HyList(self.nodes)
|
||||||
|
|
||||||
|
def process(self, char):
|
||||||
|
if char == "(":
|
||||||
|
self.machine.sub(Expression)
|
||||||
|
return
|
||||||
|
|
||||||
|
if char == "[":
|
||||||
|
self.machine.sub(List)
|
||||||
|
return
|
||||||
|
|
||||||
|
if char == "\"":
|
||||||
|
self.machine.sub(String)
|
||||||
|
return
|
||||||
|
|
||||||
|
if char == "]":
|
||||||
|
return Idle
|
||||||
|
|
||||||
|
if char in WHITESPACE:
|
||||||
|
self.commit()
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.buf == "":
|
||||||
|
self._start_line = self.machine.line
|
||||||
|
self._start_column = self.machine.column
|
||||||
|
|
||||||
|
self.buf += char
|
||||||
|
|
||||||
|
|
||||||
|
class Expression(List):
|
||||||
|
"""
|
||||||
|
Expression state. This will handle stuff like:
|
||||||
|
|
||||||
|
(...... (....))
|
||||||
|
^^^^^^ -- expression
|
||||||
|
^^^^^^^^^^^^^^^ -- expression
|
||||||
|
"""
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
self.commit()
|
self.commit()
|
||||||
if self.nodes != []:
|
if self.nodes != []:
|
||||||
self.result = HyExpression(self.nodes)
|
self.result = HyExpression(self.nodes)
|
||||||
else:
|
else:
|
||||||
self.result = None
|
self.result = HyList([])
|
||||||
|
|
||||||
def process(self, char):
|
def process(self, char):
|
||||||
"""
|
"""
|
||||||
@ -137,6 +171,10 @@ class Expression(State):
|
|||||||
self.machine.sub(Expression)
|
self.machine.sub(Expression)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if char == "[":
|
||||||
|
self.machine.sub(List)
|
||||||
|
return
|
||||||
|
|
||||||
if char == "\"":
|
if char == "\"":
|
||||||
self.machine.sub(String)
|
self.machine.sub(String)
|
||||||
return
|
return
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
# DEALINGS IN THE SOFTWARE.
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from hy.models import HyObject
|
from hy.models import HyObject
|
||||||
|
from hy.models.list import HyList
|
||||||
|
|
||||||
|
|
||||||
class HyExpression(HyObject, list):
|
class HyExpression(HyList):
|
||||||
"""
|
"""
|
||||||
Hy S-Expression. Basically just a list.
|
Hy S-Expression. Basically just a list.
|
||||||
"""
|
"""
|
||||||
|
28
hy/models/list.py
Normal file
28
hy/models/list.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright (c) 2012 Paul Tagliamonte <paultag@debian.org>
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
# copy of this software and associated documentation files (the "Software"),
|
||||||
|
# to deal in the Software without restriction, including without limitation
|
||||||
|
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
# and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
# Software is furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
from hy.models import HyObject
|
||||||
|
|
||||||
|
|
||||||
|
class HyList(HyObject, list):
|
||||||
|
"""
|
||||||
|
Hy List. Basically just a list.
|
||||||
|
"""
|
||||||
|
pass
|
4
setup.py
4
setup.py
@ -24,7 +24,9 @@ from hy import __appname__, __version__
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
long_description = open('README.md', 'r').read()
|
long_description = """Hy is a Python <--> Lisp layer. It helps
|
||||||
|
make things work nicer, and lets Python and the Hy lisp variant play
|
||||||
|
nice together. """
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
; copyright ..
|
; copyright ..
|
||||||
|
|
||||||
|
|
||||||
(def test_basic_math (fn ()
|
(def test_basic_math (fn []
|
||||||
(assert (+ 2 2) 4)))
|
(assert (+ 2 2) 4)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user