diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/Pygments/py3/pygments/lexers/crystal.py | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/Pygments/py3/pygments/lexers/crystal.py')
-rw-r--r-- | contrib/python/Pygments/py3/pygments/lexers/crystal.py | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/contrib/python/Pygments/py3/pygments/lexers/crystal.py b/contrib/python/Pygments/py3/pygments/lexers/crystal.py index d06ab0c060..99ce7329c8 100644 --- a/contrib/python/Pygments/py3/pygments/lexers/crystal.py +++ b/contrib/python/Pygments/py3/pygments/lexers/crystal.py @@ -4,7 +4,7 @@ Lexer for Crystal. - :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -56,11 +56,11 @@ class CrystalLexer(ExtendedRegexLexer): ctx.pos = match.start(5) ctx.end = match.end(5) - # this may find other heredocs, so limit the recursion depth - if len(heredocstack) < 100: - yield from self.get_tokens_unprocessed(context=ctx) - else: - yield ctx.pos, String.Heredoc, match.group(5) + # this may find other heredocs, so limit the recursion depth + if len(heredocstack) < 100: + yield from self.get_tokens_unprocessed(context=ctx) + else: + yield ctx.pos, String.Heredoc, match.group(5) ctx.pos = match.end() if outermost: @@ -90,9 +90,9 @@ class CrystalLexer(ExtendedRegexLexer): def gen_crystalstrings_rules(): states = {} states['strings'] = [ - (r'\:\w+[!?]?', String.Symbol), - (words(CRYSTAL_OPERATORS, prefix=r'\:'), String.Symbol), - (r":'(\\\\|\\[^\\]|[^'\\])*'", String.Symbol), + (r'\:\w+[!?]?', String.Symbol), + (words(CRYSTAL_OPERATORS, prefix=r'\:'), String.Symbol), + (r":'(\\\\|\\[^\\]|[^'\\])*'", String.Symbol), # This allows arbitrary text after '\ for simplicity (r"'(\\\\|\\'|[^']|\\[^'\\]+)'", String.Char), (r':"', String.Symbol, 'simple-sym'), @@ -113,42 +113,42 @@ class CrystalLexer(ExtendedRegexLexer): (end, ttype, '#pop'), ] - # https://crystal-lang.org/docs/syntax_and_semantics/literals/string.html#percent-string-literals + # https://crystal-lang.org/docs/syntax_and_semantics/literals/string.html#percent-string-literals for lbrace, rbrace, bracecc, name in \ ('\\{', '\\}', '{}', 'cb'), \ ('\\[', '\\]', '\\[\\]', 'sb'), \ ('\\(', '\\)', '()', 'pa'), \ - ('<', '>', '<>', 'ab'), \ - ('\\|', '\\|', '\\|', 'pi'): + ('<', '>', '<>', 'ab'), \ + ('\\|', '\\|', '\\|', 'pi'): states[name+'-intp-string'] = [ - (r'\\' + lbrace, String.Other), - ] + (lbrace != rbrace) * [ + (r'\\' + lbrace, String.Other), + ] + (lbrace != rbrace) * [ (lbrace, String.Other, '#push'), - ] + [ + ] + [ (rbrace, String.Other, '#pop'), include('string-intp-escaped'), (r'[\\#' + bracecc + ']', String.Other), (r'[^\\#' + bracecc + ']+', String.Other), ] - states['strings'].append((r'%Q?' + lbrace, String.Other, + states['strings'].append((r'%Q?' + lbrace, String.Other, name+'-intp-string')) states[name+'-string'] = [ (r'\\[\\' + bracecc + ']', String.Other), - ] + (lbrace != rbrace) * [ + ] + (lbrace != rbrace) * [ (lbrace, String.Other, '#push'), - ] + [ + ] + [ (rbrace, String.Other, '#pop'), (r'[\\#' + bracecc + ']', String.Other), (r'[^\\#' + bracecc + ']+', String.Other), ] - # https://crystal-lang.org/docs/syntax_and_semantics/literals/array.html#percent-array-literals - states['strings'].append((r'%[qwi]' + lbrace, String.Other, + # https://crystal-lang.org/docs/syntax_and_semantics/literals/array.html#percent-array-literals + states['strings'].append((r'%[qwi]' + lbrace, String.Other, name+'-string')) states[name+'-regex'] = [ (r'\\[\\' + bracecc + ']', String.Regex), - ] + (lbrace != rbrace) * [ + ] + (lbrace != rbrace) * [ (lbrace, String.Regex, '#push'), - ] + [ + ] + [ (rbrace + '[imsx]*', String.Regex, '#pop'), include('string-intp'), (r'[\\#' + bracecc + ']', String.Regex), @@ -164,16 +164,16 @@ class CrystalLexer(ExtendedRegexLexer): (r'#.*?$', Comment.Single), # keywords (words(''' - abstract asm begin break case do else elsif end ensure extend if in - include next of private protected require rescue return select self super - then unless until when while with yield + abstract asm begin break case do else elsif end ensure extend if in + include next of private protected require rescue return select self super + then unless until when while with yield '''.split(), suffix=r'\b'), Keyword), - (words(''' - previous_def forall out uninitialized __DIR__ __FILE__ __LINE__ - __END_LINE__ - '''.split(), prefix=r'(?<!\.)', suffix=r'\b'), Keyword.Pseudo), - # https://crystal-lang.org/docs/syntax_and_semantics/is_a.html - (r'\.(is_a\?|nil\?|responds_to\?|as\?|as\b)', Keyword.Pseudo), + (words(''' + previous_def forall out uninitialized __DIR__ __FILE__ __LINE__ + __END_LINE__ + '''.split(), prefix=r'(?<!\.)', suffix=r'\b'), Keyword.Pseudo), + # https://crystal-lang.org/docs/syntax_and_semantics/is_a.html + (r'\.(is_a\?|nil\?|responds_to\?|as\?|as\b)', Keyword.Pseudo), (words(['true', 'false', 'nil'], suffix=r'\b'), Keyword.Constant), # start of function, class and module names (r'(module|lib)(\s+)([a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*)', @@ -181,23 +181,23 @@ class CrystalLexer(ExtendedRegexLexer): (r'(def|fun|macro)(\s+)((?:[a-zA-Z_]\w*::)*)', bygroups(Keyword, Whitespace, Name.Namespace), 'funcname'), (r'def(?=[*%&^`~+-/\[<>=])', Keyword, 'funcname'), - (r'(annotation|class|struct|union|type|alias|enum)(\s+)((?:[a-zA-Z_]\w*::)*)', + (r'(annotation|class|struct|union|type|alias|enum)(\s+)((?:[a-zA-Z_]\w*::)*)', bygroups(Keyword, Whitespace, Name.Namespace), 'classname'), - # https://crystal-lang.org/api/toplevel.html - (words(''' - instance_sizeof offsetof pointerof sizeof typeof - '''.split(), prefix=r'(?<!\.)', suffix=r'\b'), Keyword.Pseudo), + # https://crystal-lang.org/api/toplevel.html + (words(''' + instance_sizeof offsetof pointerof sizeof typeof + '''.split(), prefix=r'(?<!\.)', suffix=r'\b'), Keyword.Pseudo), # macros - (r'(?<!\.)(debugger\b|p!|pp!|record\b|spawn\b)', Name.Builtin.Pseudo), + (r'(?<!\.)(debugger\b|p!|pp!|record\b|spawn\b)', Name.Builtin.Pseudo), # builtins (words(''' - abort at_exit caller exit gets loop main p pp print printf puts - raise rand read_line sleep spawn sprintf system + abort at_exit caller exit gets loop main p pp print printf puts + raise rand read_line sleep spawn sprintf system '''.split(), prefix=r'(?<!\.)', suffix=r'\b'), Name.Builtin), - # https://crystal-lang.org/api/Object.html#macro-summary - (r'(?<!\.)(((class_)?((getter|property)\b[!?]?|setter\b))|' - r'(def_(clone|equals|equals_and_hash|hash)|delegate|forward_missing_to)\b)', - Name.Builtin.Pseudo), + # https://crystal-lang.org/api/Object.html#macro-summary + (r'(?<!\.)(((class_)?((getter|property)\b[!?]?|setter\b))|' + r'(def_(clone|equals|equals_and_hash|hash)|delegate|forward_missing_to)\b)', + Name.Builtin.Pseudo), # normal heredocs (r'(?<!\w)(<<-?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)', heredoc_callback), @@ -269,17 +269,17 @@ class CrystalLexer(ExtendedRegexLexer): (r'\$-[0adFiIlpvw]', Name.Variable.Global), (r'::', Operator), include('strings'), - # https://crystal-lang.org/reference/syntax_and_semantics/literals/char.html + # https://crystal-lang.org/reference/syntax_and_semantics/literals/char.html (r'\?(\\[MC]-)*' # modifiers - r'(\\([\\abefnrtv#"\']|[0-7]{1,3}|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|u\{[a-fA-F0-9 ]+\})|\S)' + r'(\\([\\abefnrtv#"\']|[0-7]{1,3}|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|u\{[a-fA-F0-9 ]+\})|\S)' r'(?!\w)', String.Char), - (r'[A-Z][A-Z_]+\b(?!::|\.)', Name.Constant), + (r'[A-Z][A-Z_]+\b(?!::|\.)', Name.Constant), # macro expansion (r'\{%', String.Interpol, 'in-macro-control'), (r'\{\{', String.Interpol, 'in-macro-expr'), - # annotations - (r'(@\[)(\s*)([A-Z]\w*(::[A-Z]\w*)*)', + # annotations + (r'(@\[)(\s*)([A-Z]\w*(::[A-Z]\w*)*)', bygroups(Operator, Whitespace, Name.Decorator), 'in-annot'), # this is needed because Crystal attributes can look # like keywords (class) or like this: ` ?!? @@ -317,9 +317,9 @@ class CrystalLexer(ExtendedRegexLexer): (r'#\{', String.Interpol, 'in-intp'), ], 'string-escaped': [ - # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html - (r'\\([\\abefnrtv#"\']|[0-7]{1,3}|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|u\{[a-fA-F0-9 ]+\})', - String.Escape) + # https://crystal-lang.org/reference/syntax_and_semantics/literals/string.html + (r'\\([\\abefnrtv#"\']|[0-7]{1,3}|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|u\{[a-fA-F0-9 ]+\})', + String.Escape) ], 'string-intp-escaped': [ include('string-intp'), @@ -349,7 +349,7 @@ class CrystalLexer(ExtendedRegexLexer): 'in-macro-control': [ (r'\{%', String.Interpol, '#push'), (r'%\}', String.Interpol, '#pop'), - (r'(for|verbatim)\b', Keyword), + (r'(for|verbatim)\b', Keyword), include('root'), ], 'in-macro-expr': [ @@ -357,7 +357,7 @@ class CrystalLexer(ExtendedRegexLexer): (r'\}\}', String.Interpol, '#pop'), include('root'), ], - 'in-annot': [ + 'in-annot': [ (r'\[', Operator, '#push'), (r'\]', Operator, '#pop'), include('root'), |