package lexers import ( . "github.com/alecthomas/chroma" // nolint ) // Python3 lexer. var Python3 = Register(MustNewLexer( &Config{ Name: "Python 3", Aliases: []string{"python3", "py3"}, Filenames: []string{}, MimeTypes: []string{"text/x-python3", "application/x-python3"}, }, Rules{ "root": { {`\n`, Text, nil}, {`^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil}, {`^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')`, ByGroups(Text, LiteralStringAffix, LiteralStringDoc), nil}, {`[^\S\n]+`, Text, nil}, {`\A#!.+$`, CommentHashbang, nil}, {`#.*$`, CommentSingle, nil}, {`[]{}:(),;[]`, Punctuation, nil}, {`\\\n`, Text, nil}, {`\\`, Text, nil}, {`(in|is|and|or|not)\b`, OperatorWord, nil}, {`!=|==|<<|>>|[-~+/*%=<>&^|.]`, Operator, nil}, Include("keywords"), {`(def)((?:\s|\\\s)+)`, ByGroups(Keyword, Text), Push("funcname")}, {`(class)((?:\s|\\\s)+)`, ByGroups(Keyword, Text), Push("classname")}, {`(from)((?:\s|\\\s)+)`, ByGroups(KeywordNamespace, Text), Push("fromimport")}, {`(import)((?:\s|\\\s)+)`, ByGroups(KeywordNamespace, Text), Push("import")}, Include("builtins"), Include("magicfuncs"), Include("magicvars"), Include("backtick"), {`([rR]|[uUbB][rR]|[rR][uUbB])(""")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("tdqs")}, {`([rR]|[uUbB][rR]|[rR][uUbB])(''')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("tsqs")}, {`([rR]|[uUbB][rR]|[rR][uUbB])(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("dqs")}, {`([rR]|[uUbB][rR]|[rR][uUbB])(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Push("sqs")}, {`([uUbB]?)(""")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Combined("stringescape", "tdqs")}, {`([uUbB]?)(''')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Combined("stringescape", "tsqs")}, {`([uUbB]?)(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Combined("stringescape", "dqs")}, {`([uUbB]?)(')`, ByGroups(LiteralStringAffix, LiteralStringSingle), Combined("stringescape", "sqs")}, Include("name"), Include("numbers"), }, "keywords": { {Words(``, `\b`, `assert`, `async`, `await`, `break`, `continue`, `del`, `elif`, `else`, `except`, `finally`, `for`, `global`, `if`, `lambda`, `pass`, `raise`, `nonlocal`, `return`, `try`, `while`, `yield`, `yield from`, `as`, `with`), Keyword, nil}, {Words(``, `\b`, `True`, `False`, `None`), KeywordConstant, nil}, }, "builtins": { {Words(`(?=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[E-GXb-gnosx%]?)?\}`, LiteralStringInterpol, nil}, {`[^\\\'"%{\n]+`, LiteralStringSingle, nil}, {`[\'"\\]`, LiteralStringSingle, nil}, {`%|(\{{1,2})`, LiteralStringSingle, nil}, }, "strings-double": { {`%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]`, LiteralStringInterpol, nil}, {`\{((\w+)((\.\w+)|(\[[^\]]+\]))*)?(\![sra])?(\:(.?[<>=\^])?[-+ ]?#?0?(\d+)?,?(\.\d+)?[E-GXb-gnosx%]?)?\}`, LiteralStringInterpol, nil}, {`[^\\\'"%{\n]+`, LiteralStringDouble, nil}, {`[\'"\\]`, LiteralStringDouble, nil}, {`%|(\{{1,2})`, LiteralStringDouble, nil}, }, "dqs": { {`"`, LiteralStringDouble, Pop(1)}, {`\\\\|\\"|\\\n`, LiteralStringEscape, nil}, Include("strings-double"), }, "sqs": { {`'`, LiteralStringSingle, Pop(1)}, {`\\\\|\\'|\\\n`, LiteralStringEscape, nil}, Include("strings-single"), }, "tdqs": { {`"""`, LiteralStringDouble, Pop(1)}, Include("strings-double"), {`\n`, LiteralStringDouble, nil}, }, "tsqs": { {`'''`, LiteralStringSingle, Pop(1)}, Include("strings-single"), {`\n`, LiteralStringSingle, nil}, }, }, ))