diff options
| author | Martijn Braam <martijn@brixit.nl> | 2020-08-22 15:56:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-22 15:56:05 +0200 |
| commit | 23823a173b01f349b6772b154d1f8447c1f0c0c1 (patch) | |
| tree | 1fb0e7fe0f01a9a268e53e4d0d04d2667700006f /pygments | |
| parent | 180d16a0de6b754c314312f81c3dc0eb3538578e (diff) | |
| download | pygments-git-23823a173b01f349b6772b154d1f8447c1f0c0c1.tar.gz | |
Added BARE schema lexer (#1488)
Diffstat (limited to 'pygments')
| -rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
| -rw-r--r-- | pygments/lexers/bare.py | 100 |
2 files changed, 101 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 1c346c37..9cdddb6a 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -47,6 +47,7 @@ LEXERS = { 'AutoItLexer': ('pygments.lexers.automation', 'AutoIt', ('autoit',), ('*.au3',), ('text/x-autoit',)), 'AutohotkeyLexer': ('pygments.lexers.automation', 'autohotkey', ('ahk', 'autohotkey'), ('*.ahk', '*.ahkl'), ('text/x-autohotkey',)), 'AwkLexer': ('pygments.lexers.textedit', 'Awk', ('awk', 'gawk', 'mawk', 'nawk'), ('*.awk',), ('application/x-awk',)), + 'BareLexer': ('pygments.lexers.bare', 'BARE', ('bare',), ('*.bare',), ()), 'BBCBasicLexer': ('pygments.lexers.basic', 'BBC Basic', ('bbcbasic',), ('*.bbc',), ()), 'BBCodeLexer': ('pygments.lexers.markup', 'BBCode', ('bbcode',), (), ('text/x-bbcode',)), 'BCLexer': ('pygments.lexers.algebra', 'BC', ('bc',), ('*.bc',), ()), diff --git a/pygments/lexers/bare.py b/pygments/lexers/bare.py new file mode 100644 index 00000000..658e7895 --- /dev/null +++ b/pygments/lexers/bare.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.bare + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + Lexer for the BARE schema. + + :copyright: Copyright 2020 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re + +from pygments.lexer import RegexLexer, words, bygroups +from pygments.token import Text, Comment, Keyword, Name, Literal + +__all__ = ['BareLexer'] + + +class BareLexer(RegexLexer): + """ + For `BARE schema <https://baremessages.org>`_ schema source. + + .. versionadded:: 2.7 + """ + name = 'BARE' + filenames = ['*.bare'] + aliases = ['bare'] + + flags = re.MULTILINE | re.UNICODE + + keywords = [ + 'type', + 'enum', + 'u8', + 'u16', + 'u32', + 'u64', + 'uint', + 'i8', + 'i16', + 'i32', + 'i64', + 'int', + 'f32', + 'f64', + 'bool', + 'void', + 'data', + 'string', + 'optional', + 'map' + ] + + tokens = { + 'root': [ + (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+{)', bygroups(Keyword, Text, Name.Class, Text), 'struct'), + (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+\()', bygroups(Keyword, Text, Name.Class, Text), 'union'), + (r'(type)(\s+)([A-Z][a-zA-Z0-9]+)(\s+)', bygroups(Keyword, Text, Name, Text), 'typedef'), + (r'(enum)(\s+)([A-Z][a-zA-Z0-9]+)(\s+{)', bygroups(Keyword, Text, Name.Class, Text), 'enum'), + (r'#.*?$', Comment), + (r'\s+', Text), + ], + 'struct': [ + (r'{', Text, '#push'), + (r'}', Text, '#pop'), + (r'([a-zA-Z0-9]+)(:\s*)', bygroups(Name.Attribute, Text), 'typedef'), + (r'\s+', Text), + ], + 'union': [ + (r'\)', Text, '#pop'), + (r'\s*\|\s*', Text), + (r'[A-Z][a-zA-Z0-9]+', Name.Class), + (words(keywords), Keyword), + (r'\s+', Text), + ], + 'typedef': [ + (r'\[\]', Text), + (r'#.*?$', Comment, '#pop'), + (r'(\[)(\d+)(\])', bygroups(Text, Literal, Text)), + (r'<|>', Text), + (r'\(', Text, 'union'), + (r'(\[)([a-z][a-z-A-Z0-9]+)(\])', bygroups(Text, Keyword, Text)), + (r'(\[)([A-Z][a-z-A-Z0-9]+)(\])', bygroups(Text, Name.Class, Text)), + (r'([A-Z][a-z-A-Z0-9]+)', Name.Class), + (words(keywords), Keyword), + (r'\n', Text, '#pop'), + (r'{', Text, 'struct'), + (r'\s+', Text), + (r'\d+', Literal), + ], + 'enum': [ + (r'{', Text, '#push'), + (r'}', Text, '#pop'), + (r'([A-Z][A-Z0-9_]*)(\s*=\s*)(\d+)', bygroups(Name.Attribute, Text, Literal)), + (r'([A-Z][A-Z0-9_]*)', bygroups(Name.Attribute)), + (r'#.*?$', Comment), + (r'\s+', Text), + ], + } |
