rana-cli/wakatime/packages/pygments/lexers/qvt.py

153 lines
6 KiB
Python
Raw Normal View History

2016-06-13 14:41:17 +00:00
# -*- coding: utf-8 -*-
"""
pygments.lexers.qvt
~~~~~~~~~~~~~~~~~~~
Lexer for QVT Operational language.
2017-02-14 07:25:51 +00:00
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
2016-06-13 14:41:17 +00:00
:license: BSD, see LICENSE for details.
"""
2017-02-14 07:25:51 +00:00
from pygments.lexer import RegexLexer, bygroups, include, combined, default, \
words
2016-06-13 14:41:17 +00:00
from pygments.token import Text, Comment, Operator, Keyword, Punctuation, \
Name, String, Number
__all__ = ['QVToLexer']
class QVToLexer(RegexLexer):
"""
For the `QVT Operational Mapping language <http://www.omg.org/spec/QVT/1.1/>`_.
Reference for implementing this: «Meta Object Facility (MOF) 2.0
Query/View/Transformation Specification», Version 1.1 - January 2011
(http://www.omg.org/spec/QVT/1.1/), see §8.4, «Concrete Syntax» in
particular.
Notable tokens assignments:
- Name.Class is assigned to the identifier following any of the following
keywords: metamodel, class, exception, primitive, enum, transformation
or library
- Name.Function is assigned to the names of mappings and queries
- Name.Builtin.Pseudo is assigned to the pre-defined variables 'this',
'self' and 'result'.
"""
# With obvious borrowings & inspiration from the Java, Python and C lexers
name = 'QVTO'
aliases = ['qvto', 'qvt']
filenames = ['*.qvto']
tokens = {
'root': [
(r'\n', Text),
(r'[^\S\n]+', Text),
(r'(--|//)(\s*)(directive:)?(.*)$',
bygroups(Comment, Comment, Comment.Preproc, Comment)),
# Uncomment the following if you want to distinguish between
# '/*' and '/**', à la javadoc
2017-02-14 07:25:51 +00:00
# (r'/[*]{2}(.|\n)*?[*]/', Comment.Multiline),
2016-06-13 14:41:17 +00:00
(r'/[*](.|\n)*?[*]/', Comment.Multiline),
(r'\\\n', Text),
(r'(and|not|or|xor|##?)\b', Operator.Word),
2017-02-14 07:25:51 +00:00
(r'(:{1,2}=|[-+]=)\b', Operator.Word),
(r'(@|<<|>>)\b', Keyword), # stereotypes
(r'!=|<>|==|=|!->|->|>=|<=|[.]{3}|[+/*%=<>&|.~]', Operator),
2016-06-13 14:41:17 +00:00
(r'[]{}:(),;[]', Punctuation),
(r'(true|false|unlimited|null)\b', Keyword.Constant),
(r'(this|self|result)\b', Name.Builtin.Pseudo),
(r'(var)\b', Keyword.Declaration),
(r'(from|import)\b', Keyword.Namespace, 'fromimport'),
2017-02-14 07:25:51 +00:00
(r'(metamodel|class|exception|primitive|enum|transformation|'
r'library)(\s+)(\w+)',
2016-06-13 14:41:17 +00:00
bygroups(Keyword.Word, Text, Name.Class)),
2017-02-14 07:25:51 +00:00
(r'(exception)(\s+)(\w+)',
bygroups(Keyword.Word, Text, Name.Exception)),
2016-06-13 14:41:17 +00:00
(r'(main)\b', Name.Function),
2017-02-14 07:25:51 +00:00
(r'(mapping|helper|query)(\s+)',
bygroups(Keyword.Declaration, Text), 'operation'),
2016-06-13 14:41:17 +00:00
(r'(assert)(\s+)\b', bygroups(Keyword, Text), 'assert'),
(r'(Bag|Collection|Dict|OrderedSet|Sequence|Set|Tuple|List)\b',
Keyword.Type),
include('keywords'),
('"', String, combined('stringescape', 'dqs')),
("'", String, combined('stringescape', 'sqs')),
include('name'),
include('numbers'),
2017-02-14 07:25:51 +00:00
# (r'([a-zA-Z_]\w*)(::)([a-zA-Z_]\w*)',
2016-06-13 14:41:17 +00:00
# bygroups(Text, Text, Text)),
2017-02-14 07:25:51 +00:00
],
2016-06-13 14:41:17 +00:00
'fromimport': [
(r'(?:[ \t]|\\\n)+', Text),
2017-02-14 07:25:51 +00:00
(r'[a-zA-Z_][\w.]*', Name.Namespace),
default('#pop'),
],
2016-06-13 14:41:17 +00:00
'operation': [
(r'::', Text),
2017-02-14 07:25:51 +00:00
(r'(.*::)([a-zA-Z_]\w*)([ \t]*)(\()',
bygroups(Text, Name.Function, Text, Punctuation), '#pop')
],
2016-06-13 14:41:17 +00:00
'assert': [
(r'(warning|error|fatal)\b', Keyword, '#pop'),
2017-02-14 07:25:51 +00:00
default('#pop'), # all else: go back
],
2016-06-13 14:41:17 +00:00
'keywords': [
2017-02-14 07:25:51 +00:00
(words((
'abstract', 'access', 'any', 'assert', 'blackbox', 'break',
'case', 'collect', 'collectNested', 'collectOne', 'collectselect',
'collectselectOne', 'composes', 'compute', 'configuration',
'constructor', 'continue', 'datatype', 'default', 'derived',
'disjuncts', 'do', 'elif', 'else', 'end', 'endif', 'except',
'exists', 'extends', 'forAll', 'forEach', 'forOne', 'from', 'if',
'implies', 'in', 'inherits', 'init', 'inout', 'intermediate',
'invresolve', 'invresolveIn', 'invresolveone', 'invresolveoneIn',
'isUnique', 'iterate', 'late', 'let', 'literal', 'log', 'map',
'merges', 'modeltype', 'new', 'object', 'one', 'ordered', 'out',
'package', 'population', 'property', 'raise', 'readonly',
'references', 'refines', 'reject', 'resolve', 'resolveIn',
'resolveone', 'resolveoneIn', 'return', 'select', 'selectOne',
'sortedBy', 'static', 'switch', 'tag', 'then', 'try', 'typedef',
'unlimited', 'uses', 'when', 'where', 'while', 'with', 'xcollect',
'xmap', 'xselect'), suffix=r'\b'), Keyword),
2016-06-13 14:41:17 +00:00
],
# There is no need to distinguish between String.Single and
# String.Double: 'strings' is factorised for 'dqs' and 'sqs'
'strings': [
(r'[^\\\'"\n]+', String),
# quotes, percents and backslashes must be parsed one at a time
(r'[\'"\\]', String),
],
'stringescape': [
(r'\\([\\btnfr"\']|u[0-3][0-7]{2}|u[0-7]{1,2})', String.Escape)
],
2017-02-14 07:25:51 +00:00
'dqs': [ # double-quoted string
2016-06-13 14:41:17 +00:00
(r'"', String, '#pop'),
(r'\\\\|\\"', String.Escape),
include('strings')
],
2017-02-14 07:25:51 +00:00
'sqs': [ # single-quoted string
2016-06-13 14:41:17 +00:00
(r"'", String, '#pop'),
(r"\\\\|\\'", String.Escape),
include('strings')
],
'name': [
2017-02-14 07:25:51 +00:00
('[a-zA-Z_]\w*', Name),
2016-06-13 14:41:17 +00:00
],
# numbers: excerpt taken from the python lexer
'numbers': [
(r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
(r'\d+[eE][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer)
],
2017-02-14 07:25:51 +00:00
}