def style_sheet(rule): rule | ([charset], star(import_), star(section)) rule.astAttrs = { 'charset': charset, 'imports': [import_], 'sections': [section], }
def media(rule): rule | (no_ignore('@', 'media'), commas(cssid, False), '{', star(ruleset), '}') rule.astAttrs = { 'media': [cssid], 'rulesets': [ruleset], }
def primary(rule): rule | parExpression \ | ('this', star('.', Identifier), [identifierSuffix]) \ | ('super', superSuffix) \ | literal \ | ('new', creator) \ | (Identifier, star('.' ,Identifier), [identifierSuffix]) \ | (primitiveType, star('[', ']'), '.', 'class') \ | ('void', '.', 'class') rule.astAttrs = { 'parExpression' : parExpression, 'superSuffix' : superSuffix, 'literal' : literal, 'creator' : creator, 'id' : [Identifier], 'primitive' : primitiveType, 'suffix' : identifierSuffix }
def declare(rule): rule | (selectors, '{', star(attr), '}') rule.astAttrs = { 'selectors': { 'type': selectors, 'single': True }, 'body': attr }
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, }
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) }
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] }
def mul_ex(rule): rule | (atomic, star(_or(*'*/'), atomic)) rule.astAttrs = { 'left': { 'type': atomic, 'single': True }, 'ops': SYMBOL, 'values': { 'type': atomic, 'start': 1 } }
def meta(rule): rule | (next, star(_or(*ops), next)) rule.astAttrs = { 'left': { 'type': next, 'single': True }, 'ops': SYMBOL, 'values': { 'type': next, 'start': 1 } }
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 } }
def units(rule): rule | plus(star(NEWLINE), [unit], star(NEWLINE)) rule.astAttrs = {"units": [unit]}
def meta(rule): rule | (next, star(_or(*ops), next)) rule.astAttrs = {'left': {'type':next, 'single':True}, 'ops': SYMBOL, 'values': {'type':next, 'start':1}}
def mul_ex(rule): rule | (atomic, star(_or(*'*/'), atomic)) rule.astAttrs = {'left': {'type':atomic, 'single':True}, 'ops': SYMBOL, 'values': {'type':atomic, 'start':1}}
def value(rule): rule | (ID, star('-', _or(INT, ID))) rule.dont_ignore = True
def typeBound(rule): rule | ( _type, star('&', _type))
def anon(rule): rule | ('(','lambda','(',star(ID),')',expression,')') rule.astAttrs = {'args': [ID], 'body': expression}
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
def section(rule): rule | (head, star(_or(define, NEWLINE))) rule.astAttrs = {'head':head, 'body':[define]}
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]}
def interfaceBody(rule): rule | ('{', star(interfaceBodyDeclaration), '}')
def classBody(rule): rule | ('{', star(classBodyDeclaration), '}') rule.astAttrs = { 'decl' : [classBodyDeclaration] }
def enumBodyDeclarations(rule): rule | (';', star(classBodyDeclaration))
def enumConstants(rule): rule | (enumConstant, star(',', enumConstant))
def start_four(rule): rule | star(four_sub)
def start(rule): rule | star(_or(section, NEWLINE)) rule.astAttrs = {'sections':[section]}
def arrayCreatorRest(rule): rule | ('[', _or((']', star('[',']'), arrayInitializer) ,(expression, ']', star('[', expression, ']'), star('[' , ']'))))
def start(rule): rule | (star(_or(statement, NEWLINE))) rule.astAttrs = {'body': statement}
def sexp(rule): rule | ('(',ID,star(expression),')') | ('(',star(expression),')') rule.astAttrs = {'function': ID, 'args': [expression]}
def selector(rule): rule | (simple_selector, star([_or('+', '>')], simple_selector)) rule.astAttrs = { 'parts': [simple_selector, SYMBOL], }
def start(rule): rule | star(declare) rule.astAttrs = {'body': declare}
def start(rule): rule | (RESERVED, star(ID, RESERVED))
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}
def primaryExpression(rule): rule | (primary, star(selector), [_or(('+','+'),('-','-'))]) rule.astAttrs = { 'primary' : primary, 'selector' : [selector], 'op' : [SYMBOL] }
def at(rule): rule | (no_ignore('@', ID), _or(STRING, SSTRING, star(_not(_or(';','}')))), ';') rule | star(_not(_or(';','}')))
def start_one(rule): rule | star(ID)
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)}
def program(rule): rule | (star(_or(expression,NEWLINE)),EOF) rule.astAttrs = {'body': [expression]}
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}}
def quote(rule): rule | ('\'','(',star(expression),')') rule.astAttrs = {'values':[expression]}
def define(rule): rule | ('(','define','(',ID,star(ID),')',plus(expression),')') rule.astAttrs = {'args': [ID], 'body': [expression]}
def typeParameters(rule): rule | ('<', typeParameter, star(',', typeParameter), '>')
def uri_contents(rule): rule | star(_not(')')) rule.dont_ignore = True rule.astAttrs = { 'items':the_tokens, }