2012-01-28 14:52:09 +00:00
|
|
|
"""
|
|
|
|
"""
|
2012-02-26 15:50:07 +00:00
|
|
|
from lesscpy.lessc import utility
|
2012-01-28 14:52:09 +00:00
|
|
|
class Node(object):
|
2012-03-03 15:16:29 +00:00
|
|
|
def __init__(self, p, ln=0):
|
2012-02-25 17:08:08 +00:00
|
|
|
self.tokens = p
|
2012-02-26 15:50:07 +00:00
|
|
|
self.lineno = ln
|
2012-02-26 16:36:13 +00:00
|
|
|
self.parsed = False
|
2012-02-19 20:38:19 +00:00
|
|
|
|
2012-01-28 14:52:09 +00:00
|
|
|
def parse(self, scope):
|
2012-02-25 17:08:08 +00:00
|
|
|
return self
|
2012-02-26 15:50:07 +00:00
|
|
|
|
|
|
|
def process(self, tokens, scope):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
while True:
|
|
|
|
tokens = list(utility.flatten(tokens))
|
|
|
|
done = True
|
|
|
|
if any(t for t in tokens if hasattr(t, 'parse')):
|
|
|
|
tokens = [t.parse(scope)
|
|
|
|
if hasattr(t, 'parse')
|
|
|
|
else t
|
|
|
|
for t in tokens]
|
|
|
|
done = False
|
|
|
|
if any(t for t in tokens if utility.is_variable(t)):
|
|
|
|
tokens = self.replace_variables(tokens, scope)
|
|
|
|
done = False
|
|
|
|
if done: break
|
|
|
|
return tokens
|
|
|
|
|
|
|
|
def replace_variables(self, tokens, scope):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return [scope.swap(t)
|
|
|
|
if utility.is_variable(t)
|
|
|
|
else t
|
|
|
|
for t in tokens]
|
2012-02-25 17:08:08 +00:00
|
|
|
|
2012-03-03 09:58:47 +00:00
|
|
|
def fmt(self, fills):
|
2012-02-26 15:50:07 +00:00
|
|
|
raise ValueError('No defined format')
|