# -*- coding: utf-8 -*- """ pygments.lexers.custom ~~~~~~~~~~~~~~~~~~~~~ Lexers for custom languages. """ import re from pygments.lexer import RegexLexer, bygroups, using, this from pygments.token import * __all__ = ['ATLLexer', 'SimpleGTLexer'] class ATLLexer(RegexLexer): name = 'ATL' aliases = ['atl'] filenames = ['*.atl'] flags = re.MULTILINE | re.DOTALL #: optional Comment or Whitespace _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' tokens = { 'root': [ # method names (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name r'(\s*)(\()', # signature start bygroups(using(this), Name.Function, Text, Operator)), (r'[^\S\n]+', Text), (r'--.*?\n', Comment.Single), (r'(create|from|to|using|mapsTo|rule|helper|refining|' r'def|if|then|else|endif|and|or|not|do|' r'let|in|distinct|foreach)\b', Keyword), (r'(entrypoint|endpoint|context|lazy|unique|nodefault|' r'abstract)\b', Keyword.Declaration), (r'(OclAny|OclUndefined|Bag|Boolean|Collection|Integer|OrderedSet|Real|Sequence|Set|String)\b', Keyword.Type), (r'(true|false|#[a-zA-Z0-9_.]+)\b', Keyword.Constant), (r'#"[a-zA-Z0-9_.]+"', Keyword.Constant), (r'(module|library)(\s+)', bygroups(Keyword.Declaration, Text), 'module'), (r'(query)(\s+)', bygroups(Keyword.Declaration, Text), 'query'), (r'(uses)(\s+)', bygroups(Keyword.Declaration, Text), 'uses'), (r"'(\\\\|\\'|[^'])*'", String), (r'"', Text, 'quoted'), (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'[0-9]+L?', Number.Integer), (r'\n', Text) ], 'module': [ (r'[a-zA-Z0-9_.]+\*?', Name.Class), (r'[^\S\n]+', Text), (r';', Text, '#pop') ], 'query': [ (r'[a-zA-Z0-9_.]+\*?', Name.Class), (r'[^\S\n]+', Text), (r'=', Operator, '#pop') ], 'uses': [ (r'[a-zA-Z0-9_.]+\*?', Name.Namespace), (r'[^\S\n]+', Text), (r';', Text, '#pop') ], 'quoted': [ (r'[a-zA-Z0-9_.:]+\*?"', Text, '#pop') ] } class SimpleGTLexer(RegexLexer): name = 'SimpleGT' aliases = ['simplegt'] filenames = ['*.simplegt'] flags = re.MULTILINE | re.DOTALL #: optional Comment or Whitespace _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' tokens = { 'root': [ # method names (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name r'(\s*)(\()', # signature start bygroups(using(this), Name.Function, Text, Operator)), (r'[^\S\n]+', Text), (r'--.*?\n', Comment.Single), (r'(transform|from|to|rule|' r'not|abstract|extends|' r'in|before)\b', Keyword), (r'(true|false|#[a-zA-Z0-9_.]+)\b', Keyword.Constant), (r'#"[a-zA-Z0-9_.]+"', Keyword.Constant), (r'(module)(\s+)', bygroups(Keyword.Declaration, Text), 'module'), (r'(import)(\s+)', bygroups(Keyword.Declaration, Text), 'import'), (r"'(\\\\|\\'|[^'])*'", String), (r'"', Text, 'quoted'), (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name), (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator), (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'[0-9]+L?', Number.Integer), (r'\n', Text) ], 'module': [ (r'[a-zA-Z0-9_.]+\*?', Name.Class), (r'[^\S\n]+', Text), (r'debug?', Keyword), (r';', Text, '#pop') ], 'import': [ (r'[a-zA-Z0-9_.]+\*?', Name.Namespace), (r'[^\S\n]+', Text), (r';', Text, '#pop') ], 'quoted': [ (r'[a-zA-Z0-9_.:]+\*?"', Text, '#pop') ] }