Handle calling scope better

This commit is contained in:
robotis
2012-06-04 07:27:53 +00:00
parent 4c399c4ca9
commit 78e32011c7
4 changed files with 9 additions and 5 deletions

View File

@@ -286,7 +286,7 @@ class LessParser(object):
""" call_mixin : identifier t_popen mixin_args_list t_pclose ';'
"""
p[1].parse(None)
p[0] = Deferred(p[1], p[3], p.lineno(4), self.scope.current)
p[0] = Deferred(p[1], p[3], p.lineno(4))
def p_mixin_args_arguments(self, p):
""" mixin_args_list : less_arguments

View File

@@ -21,6 +21,7 @@ class Scope(list):
self._mixins = {}
if init: self.push()
self.deferred = False
self.real = []
def push(self):
"""Push level on scope

View File

@@ -32,12 +32,14 @@ class Block(Node):
scope.push()
self.name, inner = self.tokens
scope.current = self.name
scope.real.append(self.name)
if not self.name.parsed:
self.name.parse(scope)
if not inner: 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.real.pop()
scope.pop()
return self

View File

@@ -11,7 +11,7 @@ from .node import Node
from lesscpy.lessc import utility
class Deferred(Node):
def __init__(self, mixin, args, lineno=0, caller=None):
def __init__(self, mixin, args, lineno=0):
"""This node represents mixin calls. The calls
to these mixins are deferred until the second
parse cycle. lessc.js allows calls to mixins not
@@ -22,7 +22,6 @@ class Deferred(Node):
"""
self.tokens = [mixin, args]
self.lineno = lineno
self.caller = caller
def parse(self, scope, error=False):
""" Parse function. We search for mixins
@@ -46,6 +45,9 @@ class Deferred(Node):
ident.parse(scope)
mixins = scope.mixins(ident.raw())
# if scope.real:
# print(scope.real[-1].raw())
if not mixins:
ident.parse(None)
mixins = scope.mixins(ident.raw())
@@ -68,10 +70,9 @@ class Deferred(Node):
block = scope.blocks(ident.raw())
if not block:
ident.parse(None)
self.caller.parse(None)
block = scope.blocks(ident.raw())
if block:
scope.current = self.caller
scope.current = scope.real[-1] if scope.real else None
res = block.copy_inner(scope)
scope.current = None