checkpoint
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
"""
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
11
lesscpy/test/testscope.py
Normal 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()
|
||||
Reference in New Issue
Block a user