annotate MoinMoin/support/pygments/lexers/go.py @ 6097:815981fad7fd

upgrade pygments from 1.6 to 2.1.3
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Sep 2016 23:55:33 +0200
parents
children
rev   line source
6097
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 pygments.lexers.go
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 Lexers for the Google Go language.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 :license: BSD, see LICENSE for details.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 import re
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 from pygments.lexer import RegexLexer, bygroups, words
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 Number, Punctuation
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 __all__ = ['GoLexer']
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 class GoLexer(RegexLexer):
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 """
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 For `Go <http://golang.org>`_ source.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 .. versionadded:: 1.2
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 """
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 name = 'Go'
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 filenames = ['*.go']
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 aliases = ['go']
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 mimetypes = ['text/x-gosrc']
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 flags = re.MULTILINE | re.UNICODE
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 tokens = {
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 'root': [
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 (r'\n', Text),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 (r'\s+', Text),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 (r'\\\n', Text), # line continuations
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 (r'//(.*?)\n', Comment.Single),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 (r'(import|package)\b', Keyword.Namespace),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 (r'(var|func|struct|map|chan|type|interface|const)\b',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 Keyword.Declaration),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 (words((
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 'break', 'default', 'select', 'case', 'defer', 'go',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 'else', 'goto', 'switch', 'fallthrough', 'if', 'range',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 'continue', 'for', 'return'), suffix=r'\b'),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 Keyword),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 (r'(true|false|iota|nil)\b', Keyword.Constant),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 # It seems the builtin types aren't actually keywords, but
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 # can be used as functions. So we need two declarations.
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 (words((
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 'uint', 'uint8', 'uint16', 'uint32', 'uint64',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 'int', 'int8', 'int16', 'int32', 'int64',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 'float', 'float32', 'float64',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 'complex64', 'complex128', 'byte', 'rune',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 'string', 'bool', 'error', 'uintptr',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 'print', 'println', 'panic', 'recover', 'close', 'complex',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 'real', 'imag', 'len', 'cap', 'append', 'copy', 'delete',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 'new', 'make'), suffix=r'\b(\()'),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 bygroups(Name.Builtin, Punctuation)),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 (words((
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 'uint', 'uint8', 'uint16', 'uint32', 'uint64',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 'int', 'int8', 'int16', 'int32', 'int64',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 'float', 'float32', 'float64',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 'complex64', 'complex128', 'byte', 'rune',
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67 'string', 'bool', 'error', 'uintptr'), suffix=r'\b'),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 Keyword.Type),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 # imaginary_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 (r'\d+i', Number),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 (r'\d+\.\d*([Ee][-+]\d+)?i', Number),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 (r'\.\d+([Ee][-+]\d+)?i', Number),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 (r'\d+[Ee][-+]\d+i', Number),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 # float_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 (r'\d+(\.\d+[eE][+\-]?\d+|'
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 r'\.\d*|[eE][+\-]?\d+)', Number.Float),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 (r'\.\d+([eE][+\-]?\d+)?', Number.Float),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 # int_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 # -- octal_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 (r'0[0-7]+', Number.Oct),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 # -- hex_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 (r'0[xX][0-9a-fA-F]+', Number.Hex),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 # -- decimal_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 (r'(0|[1-9][0-9]*)', Number.Integer),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 # char_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""",
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 String.Char),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 # StringLiteral
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 # -- raw_string_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 (r'`[^`]*`', String),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 # -- interpreted_string_lit
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 (r'"(\\\\|\\"|[^"])*"', String),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 # Tokens
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|'
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 r'|<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])', Operator),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 (r'[|^<>=!()\[\]{}.,;:]', Punctuation),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 # identifier
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 (r'[^\W\d]\w*', Name.Other),
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 ]
815981fad7fd upgrade pygments from 1.6 to 2.1.3
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 }