Exemplo n.º 1
0
def simple_selector(rule):
    postops = hash, class_, attrib, pseudo
    rule | (_or(NODE_NAME, '*'), star(_or(postops)))
    rule | plus(_or(postops))
    rule.dont_ignore = True
    rule.astAttrs = {
        'node': NODE_NAME,
        'post': postops,
    }
Exemplo n.º 2
0
def simple_selector(rule):
    postops = hash, class_, attrib, pseudo
    rule | (_or(NODE_NAME, '*'), star(_or(postops)))
    rule | plus(_or(postops))
    rule.dont_ignore = True
    rule.astAttrs = {
        'node': NODE_NAME,
        'post': postops,
    }
Exemplo n.º 3
0
def rule_def(rule):
    rule | (CSSSELECTOR, plus(NEWLINE), INDENT,
            plus(_or(statement, attribute, NEWLINE)), _or(DEDENT, EOF))
    rule.astAttrs = {
        'selector': {
            'type': CSSSELECTOR,
            'single': True
        },
        'body': [statement, attribute]
    }
Exemplo n.º 4
0
def attrib(rule):
    rule | ('[', cssid, _or('=', no_ignore('|', '='), no_ignore(
        '~', '=')), _or(cssid, STRING, SSTRING), ']')
    rule.astAttrs = {
        'name': cssid,
        'op': [SYMBOL],
        'value': {
            'type': [cssid, STRING, SSTRING],
            'single': True,
            'start': 1,
        }
    }
Exemplo n.º 5
0
def attrib(rule):
    rule | ('[', cssid, _or('=', no_ignore('|','='), no_ignore('~','=')),
            _or(cssid, STRING, SSTRING), ']')
    rule.astAttrs = {
        'name':cssid,
        'op':[SYMBOL],
        'value':{
            'type':[cssid, STRING, SSTRING],
            'single':True,
            'start':1,
        }
    }
Exemplo n.º 6
0
def declaration(rule):
    rule | (cssid, ':', plus(value), [important], ';')
    rule | (plus(_not(_or(';', '}'))), ';')
    rule.astAttrs = {
        'property': cssid,
        'values': [value],
        'important': important,
    }
Exemplo n.º 7
0
def unit(rule):
    rule | _or(dble_header_body, header_header, header_body, single_header)
    rule.astAttrs = {
        "t1": header_header,
        "t2": header_body,
        "t3": dble_header_body,
        "t4": single_header
    }
Exemplo n.º 8
0
def declaration(rule):
    rule | (cssid, ':', plus(value), [important], ';')
    rule | (plus(_not(_or(';', '}'))), ';')
    rule.astAttrs = {
        'property':cssid,
        'values':[value],
        'important':important,
    }
Exemplo n.º 9
0
def declare(rule):
    rule | ('@', CSSID, '(', [commas(expression)], ')', _or(NEWLINE, EOF))
    rule.astAttrs = {
        'name': {
            'type': CSSID,
            'single': True
        },
        'args': expression
    }
Exemplo n.º 10
0
def atomic(rule):
    rule | (literal, star(_or(post_attr, post_subs, post_call)))
    rule.astAttrs = {
        'literal': {
            'type': literal,
            'single': True
        },
        'posts': (post_attr, post_subs, post_call)
    }
Exemplo n.º 11
0
def attribute(rule):
    rule | (CSSID, ':', value, _or(NEWLINE, EOF))
    rule.astAttrs = {
        'attr': {
            'type': CSSID,
            'single': True
        },
        'value': {
            'type': value,
            'single': True
        }
    }
Exemplo n.º 12
0
def assign(rule):
    rule | (CSSID, '=', value, _or(NEWLINE, EOF))
    rule.astAttrs = {
        'left': {
            'type': CSSID,
            'single': True
        },
        'value': {
            'type': value,
            'single': True
        }
    }
Exemplo n.º 13
0
Arquivo: values.py Projeto: yishh/css
def rgb(rule):
    rule | ('rgb', '(', ((_or(percentage, NUMBER), ',')*3)[:-1], ')')
    rule.astAttrs = {
            'red':{'type':[percentage, NUMBER],
                   'single':True,
                   'start':0},
            'green':{'type':[percentage, NUMBER],
                   'single':True,
                   'start':1},
            'blue':{'type':[percentage, NUMBER],
                   'single':True,
                   'start':2},
            }
Exemplo n.º 14
0
def mul_ex(rule):
    rule | (atomic, star(_or(*'*/'), atomic))
    rule.astAttrs = {
        'left': {
            'type': atomic,
            'single': True
        },
        'ops': SYMBOL,
        'values': {
            'type': atomic,
            'start': 1
        }
    }
Exemplo n.º 15
0
 def meta(rule):
     rule | (next, star(_or(*ops), next))
     rule.astAttrs = {
         'left': {
             'type': next,
             'single': True
         },
         'ops': SYMBOL,
         'values': {
             'type': next,
             'start': 1
         }
     }
Exemplo n.º 16
0
def expression(rule):
    rule | (mul_ex, star(_or(*'-+'), mul_ex))
    rule.astAttrs = {
        'left': {
            'type': mul_ex,
            'single': True
        },
        'ops': SYMBOL,
        'values': {
            'type': mul_ex,
            'start': 1
        }
    }
Exemplo n.º 17
0
def compilationUnit(rule):
	rule | (annotations, 
			_or(
				(
					packageDeclaration,
					star(importDeclaration),
					star(typeDeclaration)
				) ,
				(
					classOrInterfaceDeclaration, star(typeDeclaration)
				)
			)
		) | (
			[packageDeclaration], 
			star(importDeclaration), 
			star(typeDeclaration)
		    )	

	rule.astAttrs = { 'packageDeclaration' : packageDeclaration , 'imports' : [importDeclaration] , 'typeDeclarations' : [classOrInterfaceDeclaration] + [typeDeclaration] }
Exemplo n.º 18
0
def statement(rule):
	rule | block \
	     | (ASSERT, expression, [':', expression], ';') \
         | ('if', parExpression, statement, ['else', statement]) \
		 | ('for', '(', forControl, ')', statement) \
	     | ('while', parExpression, statement) \
	     | ('do', statement, 'while', parExpression, ';') \
	     | ('try', 
			block, 
				_or(
					(catches,'finally',block), 
					catches, 
					('finally', block)
				    )
		) \
	    | ('switch', parExpression, '{', switchBlockStatementGroups, '}') \
	    | ('synchronized', parExpression, block) \
	    | ('return', [expression, ';']) \
	    | ('throw', expression, ';') \
	    | ('break', [Identifier], ';') \
	    | ('continue', [Identifier], ';') \
	    |  ';' \
	    |  (statementExpression, ';') \
	    |  (Identifier, ':', statement)
Exemplo n.º 19
0
def start(rule):
    rule | plus(_or(STRING, ID, NUMBER))
    rule.astAttrs = {'values': [STRING, ID, NUMBER]}
Exemplo n.º 20
0
def atomic(rule):
    rule | (literal, star(_or(post_attr, post_subs, post_call)))
    rule.astAttrs = {'literal':{'type':literal, 'single':True}, 'posts':(post_attr, post_subs, post_call)}
Exemplo n.º 21
0
def expression(rule):
    rule | (mul_ex, star(_or(*'-+'), mul_ex))
    rule.astAttrs = {'left': {'type':mul_ex, 'single':True}, 'ops': SYMBOL, 'values': {'type':mul_ex, 'start':1}}
Exemplo n.º 22
0
def attribute(rule):
    rule | (CSSID, ':', value, _or(NEWLINE, EOF))
    rule.astAttrs = {'attr': {'type':CSSID, 'single':True}, 'value': {'type':value, 'single':True}}
Exemplo n.º 23
0
def rule_def(rule):
    rule | (CSSSELECTOR, plus(NEWLINE), INDENT, plus(_or(statement, attribute, NEWLINE)), _or(DEDENT, EOF))
    rule.astAttrs = {'selector': {'type':CSSSELECTOR, 'single':True}, 'body': [statement, attribute]}
Exemplo n.º 24
0
def selector(rule):
    rule | (simple_selector, star([_or('+', '>')], simple_selector))
    rule.astAttrs = {
        'parts': [simple_selector, SYMBOL],
    }
Exemplo n.º 25
0
def start(rule):
    rule | (star(_or(statement, NEWLINE)))
    rule.astAttrs = {'body': statement}
Exemplo n.º 26
0
def primaryExpression(rule):
	rule | (primary, star(selector), [_or(('+','+'),('-','-'))])
	rule.astAttrs = { 'primary' : primary, 'selector' : [selector], 'op' : [SYMBOL] }
Exemplo n.º 27
0
def define(rule):
    rule | (name, _or(':', '='), value)
    rule.astAttrs = {'name':name, 'value':value}
Exemplo n.º 28
0
def creator(rule):
	rule | (nonWildcardTypeArguments, createdName, classCreatorRest) |   (createdName , _or(arrayCreatorRest , classCreatorRest))
Exemplo n.º 29
0
def castExpression(rule):
	rule | ('(', primitiveType, ')', unaryExpression) \
	     | ('(', _or(_type , expression), ')', unaryExpressionNotPlusMinus)
	
	rule.astAttrs = { 'primitive' : primitiveType, 'unary' : unaryExpression, 'type' : _type, 'expr' : expression, 'unarynotplus' : unaryExpressionNotPlusMinus }
Exemplo n.º 30
0
def arrayCreatorRest(rule):
    rule | ('[', _or((']', star('[',']'), arrayInitializer) ,(expression, ']', star('[', expression, ']'), star('[' , ']'))))
Exemplo n.º 31
0
def start(rule):
    rule | (star(_or(statement, NEWLINE)))
    rule.astAttrs = {'body': statement}
Exemplo n.º 32
0
def start(rule):
    rule | star(_or(section, NEWLINE))
    rule.astAttrs = {'sections':[section]}
Exemplo n.º 33
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING))
Exemplo n.º 34
0
def four_sub(rule):
    rule | (ID, _or('+', '=', '-'), ID, _or(NEWLINE, EOF))
Exemplo n.º 35
0
def value(rule):
    rule | (star(_or(*not_newline)), _or(EOF, (NEWLINE, [INDENT, star(star(_or(*not_newline)), _or(NEWLINE, EOF)), _or(DEDENT, EOF)])))
    rule.astAttrs = {'text':list(not_newline)+[NEWLINE]}
Exemplo n.º 36
0
def section(rule):
    rule | (head, star(_or(define, NEWLINE)))
    rule.astAttrs = {'head':head, 'body':[define]}
Exemplo n.º 37
0
def selector(rule):
    rule | _or(CSSID, SYMBOL)
    rule.astAttrs = {'items': (CSSID, SYMBOL, WHITE)}
Exemplo n.º 38
0
def value(rule):
    rule | (ID, star('-', _or(INT, ID)))
    rule.dont_ignore = True
Exemplo n.º 39
0
def assign(rule):
    rule | (CSSID, '=', value, _or(NEWLINE, EOF))
    rule.astAttrs = {'left': {'type':CSSID, 'single':True}, 'value': {'type':value, 'single':True}}
Exemplo n.º 40
0
def program(rule):
  rule | (star(_or(expression,NEWLINE)),EOF)
  rule.astAttrs = {'body': [expression]}
Exemplo n.º 41
0
def declare(rule):
    rule | ('@', CSSID, '(', [commas(expression)], ')', _or(NEWLINE, EOF))
    rule.astAttrs = {'name': {'type':CSSID, 'single':True}, 'args': expression}
Exemplo n.º 42
0
def declaration_end(rule):
    rule | (cssid, ':', plus(value), [important], '}')
    rule | (plus(_not(_or(';', '}'))), '}')
    rule.astAttrs = {
        'property': cssid,
        'values': [value],
        'important': important,
    }
    rule.keep_tree = True


declaration_end.astName = 'Declaration'


def important(rule):
    rule | ('!', 'important')
    rule.dont_ignore = True


from values import value, uri

block = '{', star(declaration), _or(declaration_end, '}')

grammar = Grammar(start=style_sheet,
                  tokens=the_tokens,
                  ignore=[WHITE, CMCOMMENT, NEWLINE],
                  ast_tokens=[COLOR, HEXCOLOR, STRING, SSTRING])

# vim: et sw=4 sts=4
Exemplo n.º 43
0
 def meta(rule):
     rule | (next, star(_or(*ops), next))
     rule.astAttrs = {'left': {'type':next, 'single':True}, 'ops': SYMBOL, 'values': {'type':next, 'start':1}}
Exemplo n.º 44
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING, star(_not(_or(';','}')))), ';')
    rule | star(_not(_or(';','}')))
Exemplo n.º 45
0
def mul_ex(rule):
    rule | (atomic, star(_or(*'*/'), atomic))
    rule.astAttrs = {'left': {'type':atomic, 'single':True}, 'ops': SYMBOL, 'values': {'type':atomic, 'start':1}}
Exemplo n.º 46
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING))
Exemplo n.º 47
0
def value(rule):
    rule | (ID, star('-', _or(INT, ID)))
    rule.dont_ignore = True
Exemplo n.º 48
0
def charset(rule):
    rule | (no_ignore('@', 'charset'), _or(STRING, SSTRING), ';')
    rule.pass_single = True
Exemplo n.º 49
0
def four_sub(rule):
    rule | (ID, _or("+", "=", "-"), ID, _or(NEWLINE, EOF))
Exemplo n.º 50
0
def cssid(rule):
    ids = ID, COLOR, NODE_NAME, UNIT
    rule | plus('-', _or(*ids)) | (_or(*ids), star('-', _or(*ids)))
    rule.dont_ignore = True
    rule.astAttrs = {'parts': (SYMBOL, ) + ids}
Exemplo n.º 51
0
def unit(rule):
    rule | _or(dble_header_body , header_header, header_body, single_header)
    rule.astAttrs = { "t1": header_header, "t2": header_body, "t3": dble_header_body, "t4": single_header }
Exemplo n.º 52
0
def name(rule):
    rule | plus(_or(ID, NUMBER, WHITE))
    rule.astAttrs = {'words':[ID, NUMBER, WHITE]}
Exemplo n.º 53
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING, star(_not(_or(';','}')))), ';')
    rule | star(_not(_or(';','}')))
Exemplo n.º 54
0
def value(rule):
    rule | plus(_or(CSSID, NUMBER, CSSFN))
    rule.astAttrs = {'items': (CSSID, NUMBER, CSSFN)}