Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.plib.statement
:synopsis: Statement node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
from .node import Node
from lesscpy.lessc import utility
class Statement(Node):
"""Represents CSS statement (@import, @charset...)
"""
def parse(self, scope):
"""Parse node
args:
scope (Scope): current scope
raises:
SyntaxError
returns:
self
"""
self.parsed = list(utility.flatten(self.tokens))
if self.parsed[0] == '@import':
if len(self.parsed) > 4:
# Media @import
"""
Base process Node
Copyright (c)
See LICENSE for details.
"""
import lesscpy.lessc.utility as utility
from .node import Node
class Process(Node):
def __init__(self, p):
self._p = list(p)
self.lines = [j for j in [p.lineno(i)
for i in range(len(self._p))]
if j]
self.scope = None
self.parsed = {}
def process_tokens(self, tokens):
"""
"""
while True:
done = True
if any(t for t in tokens if hasattr(t, 'parse')):
tokens = [t.parse(self.scope) if hasattr(t, 'parse')
else t
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.plib.string
:synopsis: Less interpolated string node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
import re
from .node import Node
from lesscpy.lessc import utility
class String(Node):
def parse(self, scope):
"""Parse node
args:
scope (Scope): current scope
raises:
SyntaxError
returns:
str
"""
self.scope = scope
return re.sub(r'@\{([^\}]+)\}', lambda m: self.swap(m.group(1)), self.tokens)
def swap(self, var):
""" Replace variable
args:
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.plib.property
:synopsis: Property node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
import re
from .node import Node
class Property(Node):
"""Represents CSS property declaration.
"""
def parse(self, scope):
"""Parse node
args:
scope (Scope): current scope
raises:
SyntaxError
returns:
self
"""
if not self.parsed:
if len(self.tokens) > 2:
property, style, _ = self.tokens
self.important = True
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.plib.block
:synopsis: Block parse node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
from .node import Node
from lesscpy.lessc import utility
from lesscpy.plib.identifier import Identifier
class Block(Node):
""" Block node. Represents one parse-block.
Can contain property nodes or other block nodes.
identifier {
propertys
inner blocks
}
"""
def parse(self, scope):
"""Parse block node.
args:
scope (Scope): Current scope
raises:
SyntaxError
returns:
self
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.plib.property
:synopsis: Import node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
from .node import Node
class Import(Node):
"""Represents CSS property declaration.
"""
def parse(self, scope):
"""Parse node
args:
scope (Scope): current scope
raises:
SyntaxError
returns:
parsed
"""
if not self.parsed:
self.parsed = ''.join(self.process(self.tokens, scope))
return self.parsed
.. moduleauthor:: Johann T. Mariusson
"""
import re
import math
try:
from urllib.parse import quote as urlquote
except ImportError:
from urllib import quote as urlquote
from six import string_types
from .node import Node
import lesscpy.lessc.utility as utility
import lesscpy.lessc.color as Color
from lesscpy.lib.colors import lessColors
class Call(Node):
"""Call node. Node represents a function call.
All builtin none-color functions are in this node.
This node attempts calls on built-ins and lets non-builtins
through.
increment(3px) --> 4px
unknown(3px) --> unknown(3px)
"""
def parse(self, scope):
"""Parse Node within scope.
the functions ~( and e( map to self.escape
and %( maps to self.sformat
args:
scope (Scope): Current scope
"""
name = ''.join(self.tokens[0])
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
import sys
import copy
import itertools
from .node import Node
from .block import Block
from .expression import Expression
from .variable import Variable
from lesscpy.lessc import utility
class Mixin(Node):
""" Mixin Node. Represents callable mixin types.
"""
def parse(self, scope):
"""Parse node
args:
scope (Scope): current scope
raises:
SyntaxError
returns:
self
"""
self.name, args, self.guards = self.tokens[0]
self.args = [a for a in utility.flatten(args) if a]
self.body = Block([None, self.tokens[1]], 0)
self.vars = list(
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.plib.identifier
:synopsis: Identifier node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
import re
from .node import Node
from lesscpy.lessc import utility
from lesscpy.lib import reserved
class Identifier(Node):
"""Identifier node. Represents block identifier.
"""
def parse(self, scope):
"""Parse node. Block identifiers are stored as
strings with spaces replaced with ?
args:
scope (Scope): Current scope
raises:
SyntaxError
returns:
self
"""
names = []
name = []
self._subp = ('@media', '@keyframes', '@-moz-keyframes',
.. module:: lesscpy.plib.expression
:synopsis: Expression node.
Copyright (c)
See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson
"""
import operator
from .node import Node
from lesscpy.lessc import utility
from lesscpy.lessc import color
class Expression(Node):
"""Expression node. Parses all expression except
color expressions (handled in the color class)
and unary negation (handled in the NegatedExpression class).
"""
def parse(self, scope):
""" Parse Node
args:
scope (Scope): Scope object
raises:
SyntaxError
returns:
str
"""
assert (len(self.tokens) == 3)
expr = self.process(self.tokens, scope)