checkpoint
This commit is contained in:
@@ -92,7 +92,7 @@ class LessParser(object):
|
||||
out.append(pu.parse(self.scope))
|
||||
except SyntaxError as e:
|
||||
self.handle_error(e, 0)
|
||||
self.result = utility.flatten(out)
|
||||
self.result = list(utility.flatten(out))
|
||||
|
||||
def scopemap(self):
|
||||
""" Output scopemap.
|
||||
@@ -222,7 +222,6 @@ class LessParser(object):
|
||||
"""
|
||||
self.scope.add_mixin(Mixin(list(p)[1:], p.lineno(3)).parse(self.scope))
|
||||
self.scope.pop()
|
||||
self.scope.in_mixin = False
|
||||
p[0] = None
|
||||
|
||||
def p_open_mixin(self, p):
|
||||
@@ -230,12 +229,12 @@ class LessParser(object):
|
||||
| identifier t_popen mixin_args_list t_pclose mixin_guard brace_open
|
||||
"""
|
||||
p[1].parse(self.scope)
|
||||
self.scope.current = p[1]
|
||||
p[0] = [p[1], p[3]]
|
||||
if len(p) > 6:
|
||||
p[0].append(p[5])
|
||||
else:
|
||||
p[0].append(None)
|
||||
self.scope.in_mixin = True
|
||||
|
||||
def p_mixin_guard(self, p):
|
||||
""" mixin_guard : less_when mixin_guard_cond_list
|
||||
|
||||
@@ -20,7 +20,7 @@ class Scope(list):
|
||||
super().__init__()
|
||||
self._mixins = {}
|
||||
if init: self.push()
|
||||
self.in_mixin = False
|
||||
self.deferred = False
|
||||
|
||||
def push(self):
|
||||
"""Push level on scope
|
||||
|
||||
@@ -62,10 +62,11 @@ def blocksearch(block, name):
|
||||
Returns:
|
||||
Block OR False
|
||||
"""
|
||||
for b in block.tokens[1]:
|
||||
b = (b if hasattr(b, 'raw') and b.raw() == name
|
||||
else blocksearch(b, name))
|
||||
if b: return b
|
||||
if hasattr(block, 'tokens'):
|
||||
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
|
||||
|
||||
def reverse_guard(lst):
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"""
|
||||
import re, copy
|
||||
from .node import Node
|
||||
from .deferred import Deferred
|
||||
from lesscpy.lessc import utility
|
||||
|
||||
class Block(Node):
|
||||
@@ -36,7 +35,7 @@ class Block(Node):
|
||||
if not self.name.parsed:
|
||||
self.name.parse(scope)
|
||||
if not inner: inner = []
|
||||
inner = list(utility.flatten([p.parse(scope) for p in inner]))
|
||||
inner = list(utility.flatten([p.parse(scope) for p in inner if p]))
|
||||
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()
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
.. moduleauthor:: Jóhann T. Maríusson <jtm@robot.is>
|
||||
"""
|
||||
from .node import Node
|
||||
from lesscpy.lessc import utility
|
||||
|
||||
class Deferred(Node):
|
||||
def __init__(self, mixin, args, lineno=0):
|
||||
@@ -29,19 +30,31 @@ class Deferred(Node):
|
||||
returns:
|
||||
mixed
|
||||
"""
|
||||
mixin, args = self.tokens
|
||||
if hasattr(mixin, 'call'):
|
||||
return mixin.call(scope, args)
|
||||
res = False
|
||||
mixins = scope.mixins(mixin.raw())
|
||||
ident, args = self.tokens
|
||||
# if hasattr(mixin, 'call'):
|
||||
# return mixin.call(scope, args)
|
||||
ident.parse(scope)
|
||||
mixins = scope.mixins(ident.raw())
|
||||
if not mixins:
|
||||
ident.parse(None)
|
||||
mixins = scope.mixins(ident.raw())
|
||||
if not mixins:
|
||||
if scope.deferred:
|
||||
scope.current = scope.deferred
|
||||
ident.parse(scope)
|
||||
mixins = scope.mixins(ident.raw())
|
||||
scope.current = None
|
||||
if mixins:
|
||||
for mixin in mixins:
|
||||
res = mixin.call(scope, args)
|
||||
if res: break
|
||||
if res:
|
||||
res = [p.parse(scope) for p in res]
|
||||
scope.deferred = ident
|
||||
res = [p.parse(scope) for p in res if p]
|
||||
while(any(t for t in res if type(t) is Deferred)):
|
||||
res = [p.parse(scope) for p in res]
|
||||
res = [p.parse(scope) for p in res if p]
|
||||
scope.deferred = None
|
||||
if error and not res:
|
||||
raise SyntaxError('NameError `%s`' % mixin.raw(True))
|
||||
return res
|
||||
|
||||
@@ -62,4 +62,4 @@
|
||||
#gridSystem > .generate(@gridColumns, @gridColumnWidth, @gridGutterWidth);
|
||||
|
||||
// Test
|
||||
//#gridSystem > .generate(7, 27, 1.7);
|
||||
#gridSystem > .generate(7, 27, 1.7);
|
||||
|
||||
@@ -26,15 +26,18 @@ def create_test (args):
|
||||
p.parse(filename=lessf)
|
||||
f = formatter.Formatter(Opt())
|
||||
pout = f.format(p).split('\n')
|
||||
pl = len(pout)
|
||||
i = 0
|
||||
with open(cssf) as cssf:
|
||||
for line in cssf.readlines():
|
||||
if i >= pl:
|
||||
self.fail("%s: result has less lines (%d < %d)" % (cssf, i, pl))
|
||||
line = line.rstrip()
|
||||
if not line: continue
|
||||
self.assertEqual(line, pout[i], '%s: Line %d' % (cssf, i+1))
|
||||
i += 1
|
||||
if len(pout) > i and i:
|
||||
self.fail("%s: result has more lines (%d < %d)" % (cssf, i, len(pout)))
|
||||
if pl > i and i:
|
||||
self.fail("%s: result has more lines (%d > %d)" % (cssf, i, pl))
|
||||
else:
|
||||
self.fail("%s not found..." % cssf)
|
||||
if os.path.exists(minf):
|
||||
@@ -44,13 +47,16 @@ def create_test (args):
|
||||
p.parse(filename=lessf)
|
||||
f = formatter.Formatter(opt)
|
||||
mout = f.format(p).split('\n')
|
||||
ml = len(mout)
|
||||
i = 0
|
||||
with open(minf) as cssf:
|
||||
for line in cssf.readlines():
|
||||
if i >= ml:
|
||||
self.fail("%s: result has less lines (%d < %d)" % (minf, i, ml))
|
||||
self.assertEqual(line.rstrip(), mout[i], '%s: Line %d' % (minf, i+1))
|
||||
i += 1
|
||||
if len(mout) > i and i:
|
||||
self.fail("%s: result has more lines (%d < %d)" % (minf, i, len(mout)))
|
||||
if ml > i and i:
|
||||
self.fail("%s: result has more lines (%d > %d)" % (minf, i, ml))
|
||||
else:
|
||||
self.fail("%s not found..." % minf)
|
||||
return do_test_expected
|
||||
|
||||
Reference in New Issue
Block a user