def expect_in_parens(contents): return [ rule( match=r'\(', scope='punctuation.section.group.begin.sql', set=[ expect(r'\)', 'punctuation.section.group.end.sql'), contents, ], ), rule(match=r'(?=\S)', pop=True), ]
def assignment( delim: str = "=", mode: str = "list", include_main: str = "main", ) -> Any: return rule( match="({{argument_key}}*)\\s*(%s)" % delim, captures={1: scopes.KEY, 2: scopes.EQUALS}, push=[ rule(meta_content_scope=scopes.VALUE), rule(include="generic.{}.pop-at-end-of-assignment/".format(mode)), rule(include="generic.dimension"), rule(include=include_main), ], )
def heredoc(start, end): return rule( match=r"(?i)q\'%s" % start, scope='punctuation.definition.string.begin.sql', set=[ rule(meta_include_prototype=False), rule(meta_scope='string.quoted.heredoc.sql'), rule( match=r"%s\'" % end, scope='punctuation.definition.string.end.sql', pop=True, ), ], )
def expect_identifier(scope): return [ rule(match=r'{{unquoted_identifier}}', scope=scope, pop=True), rule( match=r'(")([^"]+)(")', scope='string.quoted.double.sql', captures={ '1': 'punctuation.definition.string.begin.sql', '2': scope, '3': 'punctuation.definition.string.end.sql', }, pop=True, ), pop_unless(r'{{general_identifier}}'), ]
def group_markup(name: str) -> List[Any]: fallback = "markup.italic.{}.context".format(name) content_scope = MAPS["markup_group"].get(name, fallback) return [ rule( match=r"\{", scope=scopes.BEGIN_BRACE, set=[ rule(meta_scope=scopes.BRACES_ARGUMENT), rule(meta_content_scope=content_scope), rule(include="argument.group.main/"), ], ), rule(include="generic.pop-if-no-nearby-group/"), ]
def list_of(context): return [ rule(match=r'', set=[ [ rule( match=',', scope='punctuation.separator.comma.sql', push=context, ), rule(include='else-pop') ], context, ]) ]
def identifier(scope): return [ rule(match=r'{{var_name}}', scope=scope, pop=True), rule( match=r'"', scope="punctuation.definition.string.begin.sql", set=[ rule(meta_scope="meta.string.sql"), rule(meta_content_scope=scope), rule(match=r'"', scope="punctuation.definition.string.end.sql", pop=True), ], ), ]
def list_heading(name: str) -> List[Any]: content_scope = scopes.ALL( scopes.VALUE, scopes.META_TITLE, "entity.name.section.{}.context".format(name), scopes.MARKUP_HEADING, ) return [ rule( match=r"\[", scope=scopes.BEGIN_BRACKET, set=[ rule(meta_scope=scopes.BRACKETS_ARGUMENT), rule( match=r"\b(title)\s*(=)", captures={1: scopes.KEY, 2: scopes.EQUALS}, push=[ rule(meta_content_scope=content_scope), rule(include="argument.list.heading.common/"), ], ), rule(include="argument.list.main/"), ], ), rule(include="generic.pop-if-no-nearby-list/"), ]
def group_heading(name: str) -> List[Any]: content_scope = scopes.ALL( scopes.META_TITLE, "entity.name.section.{}.context".format(name), scopes.MARKUP_HEADING, ) return [ rule( match=r"\{", scope=scopes.BEGIN_BRACE, set=[ rule(meta_scope=scopes.BRACES_ARGUMENT), rule(meta_content_scope=content_scope.format(name)), rule(include="argument.group.main/"), ], ), rule(include="generic.pop-if-no-nearby-group/"), ]
def verbatim_helper(name: str = "", arg: str = None) -> Any: arg_ = ( "argument.list.close*/" if arg is None else "argument.list.{}.close*/".format(arg) ) return rule( match="", push=["verbatim.main.{}.aux/".format(name), arg_], )
def block_stop( name: str = "", meta_content_scope: str = "", meta_include_prototype: Optional[bool] = None, include: Optional[str] = None, ) -> Any: include_rule = [] if include is None else [rule(include=include)] prototype_rule = ( [] if meta_include_prototype is None else [rule(meta_include_prototype=meta_include_prototype)] ) return rule( match="", set=prototype_rule + [ rule(meta_content_scope=meta_content_scope), rule(match=r"(?=\\stop{}\b)".format(name), pop=True), ] + include_rule, )
def units_context(ignored): data = load_data('units') return [ rule( match=unit + r'{{identifier_end}}', scope='storage.type.unit.css', pop=True, ) for unit in data ]
def end(keyword=None): if bool(keyword): next_context = expect_keyword(keyword, 'keyword.control.sql') else: next_context = expect_identifier('variable.other.label.sql') return rule( match=word('END'), scope='keyword.control.sql', set=next_context, )
def expect(expr, scope, set_context=None): ret = [ rule(match=expr, scope=scope), # { "match": r'(?=\S)', "pop": True }, pop_unless(expr) ] if set_context: ret[0]['set'] = set_context else: ret[0]['pop'] = True return ret
def control_sequence_group_markup( name: str = "", push_scoping: Optional[str] = None, ) -> Any: rule_base = { "match": r"(\{)\s*((\\)%s)\b" % name, "captures": { 1: scopes.BEGIN_BRACE, 2: scopes.CONTROL_WORD_NORMAL, 3: scopes.BACKSLASH, }, } if push_scoping is not None: rule_base["push"] = "scoping.group.{}.main/".format(push_scoping) return rule(**rule_base)
def _control_sequence( name: str, scope: str, name_map: Optional[str] = None, name_pre: str = "", name_post: str = "", backslash: str = scopes.BACKSLASH, **kwargs ) -> Any: if name_map in MAPS: name = MAPS[name_map].get(name, name) rule_base = _control_sequence_aux( name_pre + name + name_post, scope, backslash=backslash, ) for k, v in kwargs.items(): if v is not None: rule_base[k] = v return rule(**rule_base)
def embed_language_in_tag(tag, match, embed, file): return rule( match= r'(?i)(?=text/{0}(?!{{unquoted_attribute_value}})|\'text/{0}\'|"text/{0}")' .format(match), set=[ [ rule(meta_content_scope='meta.tag.%s.begin.html' % tag), rule(include='%s-common' % tag), rule(match='>', scope='punctuation.definition.tag.end.html', set=[ rule(include='%s-close-tag' % tag), rule( match=r'', embed=(file if file else 'scope:%s' % embed), embed_scope=('%s.embedded.html' % embed), escape=r'(?i)(?=(?:-->\s*)?</%s)' % tag, ) ]), ], 'tag-generic-attribute-meta', 'tag-generic-attribute-value', ])
def quantity_rule(unit, subscope): return rule( match='{{number}}(%s){{identifier_end}}' % unit, scope='constant.numeric.%s.css' % subscope, captures={1: 'keyword.other.unit.%s.css' % subscope}, )
def empty_context(*args): return [rule(match='', pop=True)]
def pop_on(expr): return rule(match=r'(?=\s*(?:%s))' % expr, pop=True)
def pop_unless(expr): return rule(match=r'(?=\s*(?!%s)\S)' % expr, pop=True)
def meta_set(scope): return [ rule(meta_scope=scope), rule(clear_scopes=1), rule(match=r'', pop=True), ]
def expect_identifier(scope): return identifier(scope) + [rule(match=r'(?=\S)', pop=True)]
def all(*contexts): return [rule(include=context) for context in contexts]