示例#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,
    }
示例#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,
    }
示例#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]
    }
示例#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,
        }
    }
示例#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,
        }
    }
示例#6
0
def declaration(rule):
    rule | (cssid, ':', plus(value), [important], ';')
    rule | (plus(_not(_or(';', '}'))), ';')
    rule.astAttrs = {
        'property': cssid,
        'values': [value],
        'important': important,
    }
示例#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
    }
示例#8
0
def declaration(rule):
    rule | (cssid, ':', plus(value), [important], ';')
    rule | (plus(_not(_or(';', '}'))), ';')
    rule.astAttrs = {
        'property':cssid,
        'values':[value],
        'important':important,
    }
示例#9
0
def declare(rule):
    rule | ('@', CSSID, '(', [commas(expression)], ')', _or(NEWLINE, EOF))
    rule.astAttrs = {
        'name': {
            'type': CSSID,
            'single': True
        },
        'args': expression
    }
示例#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)
    }
示例#11
0
def attribute(rule):
    rule | (CSSID, ':', value, _or(NEWLINE, EOF))
    rule.astAttrs = {
        'attr': {
            'type': CSSID,
            'single': True
        },
        'value': {
            'type': value,
            'single': True
        }
    }
示例#12
0
def assign(rule):
    rule | (CSSID, '=', value, _or(NEWLINE, EOF))
    rule.astAttrs = {
        'left': {
            'type': CSSID,
            'single': True
        },
        'value': {
            'type': value,
            'single': True
        }
    }
示例#13
0
文件: values.py 项目: 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},
            }
示例#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
        }
    }
示例#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
         }
     }
示例#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
        }
    }
示例#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] }
示例#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)
示例#19
0
def start(rule):
    rule | plus(_or(STRING, ID, NUMBER))
    rule.astAttrs = {'values': [STRING, ID, NUMBER]}
示例#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)}
示例#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}}
示例#22
0
def attribute(rule):
    rule | (CSSID, ':', value, _or(NEWLINE, EOF))
    rule.astAttrs = {'attr': {'type':CSSID, 'single':True}, 'value': {'type':value, 'single':True}}
示例#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]}
示例#24
0
def selector(rule):
    rule | (simple_selector, star([_or('+', '>')], simple_selector))
    rule.astAttrs = {
        'parts': [simple_selector, SYMBOL],
    }
示例#25
0
def start(rule):
    rule | (star(_or(statement, NEWLINE)))
    rule.astAttrs = {'body': statement}
示例#26
0
def primaryExpression(rule):
	rule | (primary, star(selector), [_or(('+','+'),('-','-'))])
	rule.astAttrs = { 'primary' : primary, 'selector' : [selector], 'op' : [SYMBOL] }
示例#27
0
def define(rule):
    rule | (name, _or(':', '='), value)
    rule.astAttrs = {'name':name, 'value':value}
示例#28
0
def creator(rule):
	rule | (nonWildcardTypeArguments, createdName, classCreatorRest) |   (createdName , _or(arrayCreatorRest , classCreatorRest))
示例#29
0
def castExpression(rule):
	rule | ('(', primitiveType, ')', unaryExpression) \
	     | ('(', _or(_type , expression), ')', unaryExpressionNotPlusMinus)
	
	rule.astAttrs = { 'primitive' : primitiveType, 'unary' : unaryExpression, 'type' : _type, 'expr' : expression, 'unarynotplus' : unaryExpressionNotPlusMinus }
示例#30
0
def arrayCreatorRest(rule):
    rule | ('[', _or((']', star('[',']'), arrayInitializer) ,(expression, ']', star('[', expression, ']'), star('[' , ']'))))
示例#31
0
def start(rule):
    rule | (star(_or(statement, NEWLINE)))
    rule.astAttrs = {'body': statement}
示例#32
0
def start(rule):
    rule | star(_or(section, NEWLINE))
    rule.astAttrs = {'sections':[section]}
示例#33
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING))
示例#34
0
def four_sub(rule):
    rule | (ID, _or('+', '=', '-'), ID, _or(NEWLINE, EOF))
示例#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]}
示例#36
0
def section(rule):
    rule | (head, star(_or(define, NEWLINE)))
    rule.astAttrs = {'head':head, 'body':[define]}
示例#37
0
def selector(rule):
    rule | _or(CSSID, SYMBOL)
    rule.astAttrs = {'items': (CSSID, SYMBOL, WHITE)}
示例#38
0
def value(rule):
    rule | (ID, star('-', _or(INT, ID)))
    rule.dont_ignore = True
示例#39
0
def assign(rule):
    rule | (CSSID, '=', value, _or(NEWLINE, EOF))
    rule.astAttrs = {'left': {'type':CSSID, 'single':True}, 'value': {'type':value, 'single':True}}
示例#40
0
文件: lithon.py 项目: pheuter/Lithon
def program(rule):
  rule | (star(_or(expression,NEWLINE)),EOF)
  rule.astAttrs = {'body': [expression]}
示例#41
0
def declare(rule):
    rule | ('@', CSSID, '(', [commas(expression)], ')', _or(NEWLINE, EOF))
    rule.astAttrs = {'name': {'type':CSSID, 'single':True}, 'args': expression}
示例#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
示例#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}}
示例#44
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING, star(_not(_or(';','}')))), ';')
    rule | star(_not(_or(';','}')))
示例#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}}
示例#46
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING))
示例#47
0
def value(rule):
    rule | (ID, star('-', _or(INT, ID)))
    rule.dont_ignore = True
示例#48
0
def charset(rule):
    rule | (no_ignore('@', 'charset'), _or(STRING, SSTRING), ';')
    rule.pass_single = True
示例#49
0
def four_sub(rule):
    rule | (ID, _or("+", "=", "-"), ID, _or(NEWLINE, EOF))
示例#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}
示例#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 }
示例#52
0
def name(rule):
    rule | plus(_or(ID, NUMBER, WHITE))
    rule.astAttrs = {'words':[ID, NUMBER, WHITE]}
示例#53
0
def at(rule):
    rule | (no_ignore('@', ID), _or(STRING, SSTRING, star(_not(_or(';','}')))), ';')
    rule | star(_not(_or(';','}')))
示例#54
0
def value(rule):
    rule | plus(_or(CSSID, NUMBER, CSSFN))
    rule.astAttrs = {'items': (CSSID, NUMBER, CSSFN)}