checkpoint

This commit is contained in:
jtm
2012-04-08 15:44:56 +00:00
parent 64b496093c
commit ccbe525bc2
8 changed files with 75 additions and 83 deletions

View File

@@ -86,11 +86,13 @@ class LessParser(object):
def post_parse(self):
"""
"""
out = []
for pu in self.result:
try:
pu.parse(self.scope)
out.append(pu.parse(self.scope))
except SyntaxError as e:
self.handle_error(e, 0)
self.result = utility.flatten(out)
def scopemap(self):
""" Output scopemap.

View File

@@ -39,7 +39,7 @@ def pairwise(lst):
yield lst[i], lst[i+1]
yield lst[-1], None
def rename(blocks, scope):
def rename(blocks, scope, stype):
""" Rename all sub-blocks moved under another
block. (mixins)
Args:
@@ -47,12 +47,12 @@ def rename(blocks, scope):
scope (object): Scope object
"""
for p in blocks:
if hasattr(p, 'inner'):
p.name.parse(scope)
if p.inner:
if type(p) is stype:
p.tokens[0].parse(scope)
if p.tokens[1]:
scope.push()
scope.current = p.name
rename(p.inner, scope)
scope.current = p.tokens[0]
rename(p.tokens[1], scope, stype)
scope.pop()
def blocksearch(block, name):
@@ -62,8 +62,8 @@ def blocksearch(block, name):
Returns:
Block OR False
"""
for b in block.inner:
b = (b if b.raw() == name
for b in block.tokens[1]:
b = (b if hasattr(b, 'raw') and b.raw() == name
else blocksearch(b, name))
if b: return b
return False

View File

@@ -9,6 +9,7 @@
"""
import re, copy
from .node import Node
from .deferred import Deferred
from lesscpy.lessc import utility
class Block(Node):
@@ -31,18 +32,13 @@ class Block(Node):
if not self.parsed:
scope.push()
self.name, inner = self.tokens
scope.current = self.name
if not self.name.parsed:
self.name.parse(scope)
if not inner: inner = []
self.parsed = [p.parse(scope)
for p in inner
if p and type(p) is not type(self)]
self.parsed = [p for p in utility.flatten(self.parsed) if p]
if not inner:
self.inner = []
else:
self. inner = [p for p in inner
if p and type(p) is type(self)]
if self.inner:
self.inner = [p.parse(scope) for p in self.inner]
inner = list(utility.flatten([p.parse(scope) for p in inner]))
self.parsed = [p for p in inner if p and type(p) is not Block]
self.inner = [p for p in inner if p and type(p) is Block]
scope.pop()
return self
@@ -54,8 +50,8 @@ class Block(Node):
str
"""
try:
return self.name.raw(clean)
except AttributeError:
return self.tokens[0].raw(clean)
except (AttributeError, TypeError):
pass
def fmt(self, fills):
@@ -100,6 +96,6 @@ class Block(Node):
if self.tokens[1]:
tokens = copy.deepcopy(self.tokens[1])
out = [p for p in tokens if p]
utility.rename(out, scope)
utility.rename(out, scope, Block)
return out
return None

View File

@@ -32,20 +32,18 @@ class Deferred(Node):
mixin, args = self.tokens
if hasattr(mixin, 'call'):
return mixin.call(scope, args)
res = False
mixins = scope.mixins(mixin.raw())
if mixins:
for mixin in mixins:
res = mixin.call(scope, args)
if res: return res
else:
res = self
if error:
if res: break
if res:
res = [p.parse(scope) for p in res]
while(any(t for t in res if type(t) is Deferred)):
res = [p.parse(scope) for p in res]
if error and not res:
raise SyntaxError('NameError `%s`' % mixin.raw(True))
return res
def fmt(self, fills):
"""
"""
return ''

View File

@@ -78,7 +78,7 @@ class Mixin(Node):
val = tmp.value
else:
val = arg
var = Variable(var.tokens[:-1] + [val])
var = Variable(var.tokens[:-1] + [val])
else:
#arg
if utility.is_variable(var):
@@ -90,7 +90,7 @@ class Mixin(Node):
val = tmp.value
else:
val = arg
var = Variable([var, None, arg])
var = Variable([var, None, val])
else:
return None
return var
@@ -129,7 +129,6 @@ class Mixin(Node):
list or False
"""
ret = False
variables = copy.deepcopy(scope[-1]['__variables__'])
if args:
args = [[a.parse(scope)
if type(a) is Expression
@@ -143,9 +142,6 @@ class Mixin(Node):
else:
if self.parse_guards(scope):
body = copy.deepcopy(self.body)
scope.update([self.scope], -1)
body.parse(scope)
ret = list(utility.flatten([body.parsed, body.inner]))
utility.rename(ret, scope)
scope[-1]['__variables__'] = variables
ret = body.tokens[1]
if ret: utility.rename(ret, scope, Block)
return ret

View File

@@ -1,36 +1,36 @@
.a .span1 {
width: 12px;
}
.a .span2 {
width: 36px;
}
.a .span3 {
width: 60px;
}
.a .span4 {
width: 84px;
}
.a .span5 {
width: 108px;
}
.a .span6 {
width: 132px;
}
.a .span7 {
width: 156px;
}
.a .span8 {
width: 180px;
}
.a .span9 {
width: 204px;
}
.a .span10 {
width: 228px;
.a .span12 {
width: 276px;
}
.a .span11 {
width: 252px;
}
.a .span12 {
width: 276px;
.a .span10 {
width: 228px;
}
.a .span9 {
width: 204px;
}
.a .span8 {
width: 180px;
}
.a .span7 {
width: 156px;
}
.a .span6 {
width: 132px;
}
.a .span5 {
width: 108px;
}
.a .span4 {
width: 84px;
}
.a .span3 {
width: 60px;
}
.a .span2 {
width: 36px;
}
.a .span1 {
width: 12px;
}

View File

@@ -1,12 +1,12 @@
.a .span1{width:12px;}
.a .span2{width:36px;}
.a .span3{width:60px;}
.a .span4{width:84px;}
.a .span5{width:108px;}
.a .span6{width:132px;}
.a .span7{width:156px;}
.a .span8{width:180px;}
.a .span9{width:204px;}
.a .span10{width:228px;}
.a .span11{width:252px;}
.a .span12{width:276px;}
.a .span11{width:252px;}
.a .span10{width:228px;}
.a .span9{width:204px;}
.a .span8{width:180px;}
.a .span7{width:156px;}
.a .span6{width:132px;}
.a .span5{width:108px;}
.a .span4{width:84px;}
.a .span3{width:60px;}
.a .span2{width:36px;}
.a .span1{width:12px;}

View File

@@ -62,4 +62,4 @@
#gridSystem > .generate(@gridColumns, @gridColumnWidth, @gridGutterWidth);
// Test
#gridSystem > .generate(7, 27, 1.7);
//#gridSystem > .generate(7, 27, 1.7);