checkpoint

This commit is contained in:
jtm
2012-03-01 16:23:22 +00:00
parent 57c64bcea8
commit 05f51b39b1
7 changed files with 31 additions and 7 deletions

View File

@@ -189,12 +189,13 @@ class LessParser(object):
self.handle_error(e, p)
p[0] = None
self.scope.pop()
self.scope.add_block(block)
def p_block_replace(self, p):
""" block_decl : identifier ';'
"""
m = p[1].parse(None)
block = self.scope.blocks(m)
block = self.scope.blocks(m.raw())
if block:
p[0] = block.copy(self.scope.current)
else:

View File

@@ -39,7 +39,7 @@ class Scope(list):
"""
"""
self[-1]['__blocks__'].append(block)
self[-1]['__names__'].append(block.name.strip())
self[-1]['__names__'].append(block.raw())
def add_mixin(self, mixin):
"""
@@ -74,14 +74,15 @@ class Scope(list):
i = len(self)
while i >= 0:
i -= 1
print(name, self[i]['__names__'])
if name in self[i]['__names__']:
for b in self[i]['__blocks__']:
if b.name.strip() == name:
if b.raw() == name:
return b
else:
# deep search
for b in self[i]['__blocks__']:
if name.startswith(b.name):
if name.startswith(b.raw()):
b = utility.blocksearch(b, name)
if b: return b
return False

View File

@@ -40,8 +40,8 @@ def blocksearch(block, name):
"""
print('blocksearch', name)
for b in block.inner:
print('cmp', b.name, name)
if b.name == name:
print('cmp', b.raw(), name)
if b.raw() == name:
return b
else:#if name.startswith(b.name):
return blocksearch(b, name)

View File

@@ -24,6 +24,9 @@ class Block(Node):
self.inner = [p.parse(scope) for p in self.inner]
return self
def raw(self):
return self.name.raw()
def format(self, fills):
"""
"""

View File

@@ -54,6 +54,11 @@ class Identifier(Node):
parsed.append(' ')
parsed.extend(name)
return parsed
def raw(self):
"""
"""
return '%'.join('%'.join(p) for p in self.parsed)
def format(self, fills):

View File

@@ -79,7 +79,10 @@ class TestIdentifier(unittest.TestCase):
'.a .next .d .deep, '
'.b .next .c .deep, '
'.b .next .d .deep')
self.assertEqual(id.raw(), '.a% %.next% %.c% %.deep%.a%'
' %.next% %.d% %.deep%.b% %.next%'
' %.c% %.deep%.b% %.next% %.d% %.deep')
if __name__ == '__main__':
unittest.main()

11
lesscpy/test/testscope.py Normal file
View File

@@ -0,0 +1,11 @@
import unittest
if __name__ == '__main__':
import bootstrap
from lesscpy.lessc.scope import Scope
from lesscpy.plib.identifier import Identifier
class TestIdentifier(unittest.TestCase):
pass
if __name__ == '__main__':
unittest.main()