Пример #1
0
from greencss.lexer.parsers.parsers import _, A, inf, W
from greencss.lexer.tokens.charclasses import alpha, alnum, digit, hexdigit, space, delim
from greencss.lexer.parsers.filters import join
from greencss.lexer.parsers.compound import alter
from greencss.lexer.parsers.literals import lit

spaces = space * inf
delims = delim * inf
identifier = (alpha - alnum * inf) / join
flag = ('!' - _('not-').opt - alnum * (1, inf)) / join
flags = flag - (spaces / 0 - flag) * inf

uinteger = digit * (1, inf) / join
integer = (_('-').opt - uinteger) / join
number = (integer - ('.' - uinteger).opt) / join

color_unit = ((digit * (1, 3) / join - _('%').opt) /
              (lambda c: int(c[0]) * 255 // 100
               if len(c) > 1 else int(c[0])) == (lambda c: 0 <= c[0] <= 255))
color_args = color_unit - (W(',') / 0 - color_unit) * 2
color_hunit = (hexdigit * 2 / join /
               (lambda c: int(c[0], 16)) == (lambda c: 0 <= c[0] <= 255))
color = ((_('#') / 'rgb' - color_hunit * 3) |
         ((_('rgb') | _('hls') | _('hsv') | _('yiq')) - _('(') / 0 -
          color_args - _(')') / 0))
pcall = identifier - (A ^ space).braced / join
string = A.quoted

_units = [
    'em', 'ex', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'deg', 'rad'
    'grad', 'ms', 's', 'Hz', 'kHz', '%'
Пример #2
0
__all__ = ['space', 'delim', 'alpha', 'alnum', 'digit', 'hexdigit']

from greencss.lexer.parsers.parsers import _
delim = _([' \t\n\r'])
space = _([' \t'])
alpha = _(['A','Z', 'a','z', '_-'])
alnum = _(['A','Z', 'a','z', '0','9', '_-'])
digit = _(['0','9'])
hexdigit = _(['0','9', 'A','F', 'a','f'])
Пример #3
0
from greencss.lexer.tokens.basic import identifier, pcall, number, unit, color, string, spaces, alpha
from greencss.lexer.tokens import Variable, Macro, Values, Expression, PseudoCall, MethodCall
from greencss.lexer.tokens import Value, Color, String
from greencss.lexer.parsers.parsers import _, EOL, inf
from greencss.lexer.parsers.filters import join

varval = (_('$')/0 - identifier) / Variable.get

_vallist = _(lambda inp: vallist(inp))
mcall = _('.')/0 - identifier - (_('(')/0 - (spaces/0 - _vallist).opt - _(')')/0)
word = alpha * (1, inf) / join
value = ((
        number - unit.opt >> Value      | 
        string            >> String     | 
        (color | word)    >> Color      | 
        pcall             >> PseudoCall | 
        identifier        >> Value      | 
        varval
        ) - mcall.opt) / MethodCall

expression_tail = spaces/0 - ['*/+-'] - spaces/0 - (_('(')< spaces/0 - value >_(')'))
expression = (
        _('(')< value - expression_tail * inf >_(')')
            #== (lambda t: t.count('(') == t.count(')'))
        ) >> Expression

values = (
        (expression - ((_(',').opt - spaces)/0 - expression) * inf)
        ) >> Values
vallist = expression.commalist >> Values
Пример #4
0
from greencss.lexer.tokens import Selector, Property, ComplexProperty, Variable, Macro, Rule, Arguments, IncludeFile, Metablock, Flags
from greencss.lexer.tokens.basic import identifier, spaces, digit, flags
from greencss.lexer.parsers.parsers import _, EOL, W, inf, A
from greencss.lexer.tokens.expressions import value, values, cmacrocall, vallist
from greencss.lexer.tokens.basic import string
from greencss.lexer.parsers.filters import join

shebang = ('#!' - (A^EOL)*inf - EOL)/0
comment = (_('/*')< A*inf >_('*/'))/0

vardef = identifier - W('=')/0 - value - EOL >> Variable

_cproperty = _(lambda inp: cproperty(inp))

cpholdr = _('&')
cid = ('#' - identifier) / join
cclass = ('.' - identifier) / join
cpclass = (':' - identifier) / join

sign = _(['+-'])
number = digit*(1,inf)
nthchild_arg = (
        sign.opt - number |
        sign.opt - number - 'n' - sign - number |
        'even' |
        'odd'
        ) / join
nthchild = (':nth-' - _('last-').opt - (_('child')|_('of-type')) - '(' - nthchild_arg - ')') / join

ctag = identifier | cpholdr
cmodifier = cid | cclass | cpclass | nthchild
Пример #5
0
from greencss.lexer.parsers.parsers import _, A, inf, W
from greencss.lexer.tokens.charclasses import alpha, alnum, digit, hexdigit, space, delim
from greencss.lexer.parsers.filters import join
from greencss.lexer.parsers.compound import alter
from greencss.lexer.parsers.literals import lit

spaces = space * inf
delims = delim * inf
identifier = (alpha - alnum * inf) / join
flag = ('!' - _('not-').opt - alnum * (1, inf)) / join
flags = flag - (spaces/0 - flag) * inf

uinteger = digit * (1, inf) / join
integer = (_('-').opt - uinteger) / join
number = (integer - ('.' - uinteger).opt) / join

color_unit = (
        (digit * (1, 3) / join - _('%').opt)
            / (lambda c: int(c[0])*255//100 if len(c) > 1 else int(c[0]))
            == (lambda c: 0 <= c[0] <= 255)
        )
color_args = color_unit - (W(',')/0 - color_unit) * 2
color_hunit = (
        hexdigit * 2 / join
            / (lambda c: int(c[0], 16))
            == (lambda c: 0 <= c[0] <= 255)
        )
color = (
        (_('#')/'rgb' - color_hunit * 3) |
        ((_('rgb')|_('hls')|_('hsv')|_('yiq')) - _('(')/0 - color_args - _(')')/0)
        )
Пример #6
0
from greencss.lexer.tokens import Selector, Property, ComplexProperty, Variable, Macro, Rule, Arguments, IncludeFile, Metablock, Flags
from greencss.lexer.tokens.basic import identifier, spaces, digit, flags
from greencss.lexer.parsers.parsers import _, EOL, W, inf, A
from greencss.lexer.tokens.expressions import value, values, cmacrocall, vallist
from greencss.lexer.tokens.basic import string
from greencss.lexer.parsers.filters import join

shebang = ('#!' - (A ^ EOL) * inf - EOL) / 0
comment = (_('/*') < A * inf > _('*/')) / 0

vardef = identifier - W('=') / 0 - value - EOL >> Variable

_cproperty = _(lambda inp: cproperty(inp))

cpholdr = _('&')
cid = ('#' - identifier) / join
cclass = ('.' - identifier) / join
cpclass = (':' - identifier) / join

sign = _(['+-'])
number = digit * (1, inf)
nthchild_arg = (sign.opt - number | sign.opt - number - 'n' - sign - number
                | 'even' | 'odd') / join
nthchild = (':nth-' - _('last-').opt -
            (_('child') | _('of-type')) - '(' - nthchild_arg - ')') / join

ctag = identifier | cpholdr
cmodifier = cid | cclass | cpclass | nthchild
catom = ((cmodifier * (1, inf)) | (ctag - cmodifier * inf)) / join

cexpression_tail = spaces / ' ' - (['+>'] - spaces / ' ').opt - catom