Adding in Quoting bits.
This commit is contained in:
parent
173598d055
commit
db122f2ec9
@ -19,6 +19,7 @@
|
|||||||
# DEALINGS IN THE SOFTWARE.
|
# DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from hy.lex.states import Idle, LexException
|
from hy.lex.states import Idle, LexException
|
||||||
|
from hy.models.quote import HyQuote
|
||||||
|
|
||||||
|
|
||||||
class Machine(object):
|
class Machine(object):
|
||||||
@ -28,12 +29,17 @@ class Machine(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ("submachine", "nodes", "state", "line", "column",
|
__slots__ = ("submachine", "nodes", "state", "line", "column",
|
||||||
"start_line", "start_column")
|
"start_line", "start_column", "modifier")
|
||||||
|
|
||||||
|
modifiers = {
|
||||||
|
"`": HyQuote
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, state, line, column):
|
def __init__(self, state, line, column):
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
self.line = line
|
self.line = line
|
||||||
self.column = column
|
self.column = column
|
||||||
|
self.modifier = None
|
||||||
self.submachine = None
|
self.submachine = None
|
||||||
self.state = None
|
self.state = None
|
||||||
self.set_state(state)
|
self.set_state(state)
|
||||||
@ -71,6 +77,10 @@ class Machine(object):
|
|||||||
result.start_line, result.end_line = (self.start_line, self.line)
|
result.start_line, result.end_line = (self.start_line, self.line)
|
||||||
result.start_column, result.end_column = (self.start_column,
|
result.start_column, result.end_column = (self.start_column,
|
||||||
self.column)
|
self.column)
|
||||||
|
if self.modifier is not None:
|
||||||
|
result = self.modifier(result)
|
||||||
|
self.modifier = None
|
||||||
|
|
||||||
self.nodes.append(result)
|
self.nodes.append(result)
|
||||||
|
|
||||||
def process(self, buf):
|
def process(self, buf):
|
||||||
@ -95,6 +105,10 @@ class Machine(object):
|
|||||||
self.state.nodes.append(nodes[0])
|
self.state.nodes.append(nodes[0])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if char in self.modifiers:
|
||||||
|
self.modifier = self.modifiers[char]
|
||||||
|
continue
|
||||||
|
|
||||||
new = self.state.process(char)
|
new = self.state.process(char)
|
||||||
if new:
|
if new:
|
||||||
self.set_state(new)
|
self.set_state(new)
|
||||||
|
26
hy/models/quote.py
Normal file
26
hy/models/quote.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# 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 HyQuote(HyObject):
|
||||||
|
def __init__(self, obj):
|
||||||
|
self.obj = obj
|
@ -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.quote import HyQuote
|
||||||
from hy.models.dict import HyDict
|
from hy.models.dict import HyDict
|
||||||
|
|
||||||
from hy.lex.states import LexException
|
from hy.lex.states import LexException
|
||||||
@ -143,3 +144,9 @@ def test_nospace():
|
|||||||
|
|
||||||
assert entry.end_line == 1
|
assert entry.end_line == 1
|
||||||
assert entry.end_column == 13
|
assert entry.end_column == 13
|
||||||
|
|
||||||
|
|
||||||
|
def test_lex_quoted_form():
|
||||||
|
objs = tokenize("`(foo 2)")
|
||||||
|
assert type(objs[0]) == HyQuote
|
||||||
|
assert type(objs[0].obj) == HyExpression
|
||||||
|
Loading…
Reference in New Issue
Block a user