diff options
Diffstat (limited to 'pygments/lexers/gdscript.py')
-rw-r--r-- | pygments/lexers/gdscript.py | 287 |
1 files changed, 65 insertions, 222 deletions
diff --git a/pygments/lexers/gdscript.py b/pygments/lexers/gdscript.py index f5054f46..25849af2 100644 --- a/pygments/lexers/gdscript.py +++ b/pygments/lexers/gdscript.py @@ -37,11 +37,9 @@ class GDScriptLexer(RegexLexer): def innerstring_rules(ttype): return [ # the old style '%s' % (...) string formatting - ( - r"%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?" - "[hlL]?[E-GXc-giorsux%]", - String.Interpol, - ), + (r"%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?" + "[hlL]?[E-GXc-giorsux%]", + String.Interpol), # backslashes, quotes and formatting signs must be parsed one at a time (r'[^\\\'"%\n]+', ttype), (r'[\'"\\]', ttype), @@ -53,239 +51,84 @@ class GDScriptLexer(RegexLexer): tokens = { "root": [ (r"\n", Whitespace), - ( - r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")', - bygroups(Whitespace, String.Affix, String.Doc), - ), - ( - r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')", - bygroups(Whitespace, String.Affix, String.Doc), - ), + (r'^(\s*)([rRuUbB]{,2})("""(?:.|\n)*?""")', + bygroups(Whitespace, String.Affix, String.Doc)), + (r"^(\s*)([rRuUbB]{,2})('''(?:.|\n)*?''')", + bygroups(Whitespace, String.Affix, String.Doc)), (r"[^\S\n]+", Whitespace), (r"#.*$", Comment.Single), (r"[]{}:(),;[]", Punctuation), (r"(\\)(\n)", bygroups(Text, Whitespace)), (r"\\", Text), (r"(in|and|or|not)\b", Operator.Word), - ( - r"!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||[-~+/*%=<>&^.!|$]", - Operator, - ), + (r"!=|==|<<|>>|&&|\+=|-=|\*=|/=|%=|&=|\|=|\|\||[-~+/*%=<>&^.!|$]", + Operator), include("keywords"), (r"(func)(\s+)", bygroups(Keyword, Whitespace), "funcname"), (r"(class)(\s+)", bygroups(Keyword, Whitespace), "classname"), include("builtins"), - ( - '([rR]|[uUbB][rR]|[rR][uUbB])(""")', - bygroups(String.Affix, String.Double), - "tdqs", - ), - ( - "([rR]|[uUbB][rR]|[rR][uUbB])(''')", - bygroups(String.Affix, String.Single), - "tsqs", - ), - ( - '([rR]|[uUbB][rR]|[rR][uUbB])(")', - bygroups(String.Affix, String.Double), - "dqs", - ), - ( - "([rR]|[uUbB][rR]|[rR][uUbB])(')", - bygroups(String.Affix, String.Single), - "sqs", - ), - ( - '([uUbB]?)(""")', - bygroups(String.Affix, String.Double), - combined("stringescape", "tdqs"), - ), - ( - "([uUbB]?)(''')", - bygroups(String.Affix, String.Single), - combined("stringescape", "tsqs"), - ), - ( - '([uUbB]?)(")', - bygroups(String.Affix, String.Double), - combined("stringescape", "dqs"), - ), - ( - "([uUbB]?)(')", - bygroups(String.Affix, String.Single), - combined("stringescape", "sqs"), - ), + ('([rR]|[uUbB][rR]|[rR][uUbB])(""")', + bygroups(String.Affix, String.Double), + "tdqs"), + ("([rR]|[uUbB][rR]|[rR][uUbB])(''')", + bygroups(String.Affix, String.Single), + "tsqs"), + ('([rR]|[uUbB][rR]|[rR][uUbB])(")', + bygroups(String.Affix, String.Double), + "dqs"), + ("([rR]|[uUbB][rR]|[rR][uUbB])(')", + bygroups(String.Affix, String.Single), + "sqs"), + ('([uUbB]?)(""")', + bygroups(String.Affix, String.Double), + combined("stringescape", "tdqs")), + ("([uUbB]?)(''')", + bygroups(String.Affix, String.Single), + combined("stringescape", "tsqs")), + ('([uUbB]?)(")', + bygroups(String.Affix, String.Double), + combined("stringescape", "dqs")), + ("([uUbB]?)(')", + bygroups(String.Affix, String.Single), + combined("stringescape", "sqs")), include("name"), include("numbers"), ], "keywords": [ - ( - words( - ( - "and", - "in", - "not", - "or", - "as", - "breakpoint", - "class", - "class_name", - "extends", - "is", - "func", - "setget", - "signal", - "tool", - "const", - "enum", - "export", - "onready", - "static", - "var", - "break", - "continue", - "if", - "elif", - "else", - "for", - "pass", - "return", - "match", - "while", - "remote", - "master", - "puppet", - "remotesync", - "mastersync", - "puppetsync", - ), - suffix=r"\b", - ), - Keyword, - ), + (words(("and", "in", "not", "or", "as", "breakpoint", "class", + "class_name", "extends", "is", "func", "setget", "signal", + "tool", "const", "enum", "export", "onready", "static", + "var", "break", "continue", "if", "elif", "else", "for", + "pass", "return", "match", "while", "remote", "master", + "puppet", "remotesync", "mastersync", "puppetsync"), + suffix=r"\b"), Keyword), ], "builtins": [ - ( - words( - ( - "Color8", - "ColorN", - "abs", - "acos", - "asin", - "assert", - "atan", - "atan2", - "bytes2var", - "ceil", - "char", - "clamp", - "convert", - "cos", - "cosh", - "db2linear", - "decimals", - "dectime", - "deg2rad", - "dict2inst", - "ease", - "exp", - "floor", - "fmod", - "fposmod", - "funcref", - "hash", - "inst2dict", - "instance_from_id", - "is_inf", - "is_nan", - "lerp", - "linear2db", - "load", - "log", - "max", - "min", - "nearest_po2", - "pow", - "preload", - "print", - "print_stack", - "printerr", - "printraw", - "prints", - "printt", - "rad2deg", - "rand_range", - "rand_seed", - "randf", - "randi", - "randomize", - "range", - "round", - "seed", - "sign", - "sin", - "sinh", - "sqrt", - "stepify", - "str", - "str2var", - "tan", - "tan", - "tanh", - "type_exist", - "typeof", - "var2bytes", - "var2str", - "weakref", - "yield", - ), - prefix=r"(?<!\.)", - suffix=r"\b", - ), - Name.Builtin, - ), - (r"((?<!\.)(self|false|true)|(PI|TAU|NAN|INF)" r")\b", Name.Builtin.Pseudo), - ( - words( - ( - "bool", - "int", - "float", - "String", - "NodePath", - "Vector2", - "Rect2", - "Transform2D", - "Vector3", - "Rect3", - "Plane", - "Quat", - "Basis", - "Transform", - "Color", - "RID", - "Object", - "NodePath", - "Dictionary", - "Array", - "PackedByteArray", - "PackedInt32Array", - "PackedInt64Array", - "PackedFloat32Array", - "PackedFloat64Array", - "PackedStringArray", - "PackedVector2Array", - "PackedVector3Array", - "PackedColorArray", - "null", - "void", - ), - prefix=r"(?<!\.)", - suffix=r"\b", - ), - Name.Builtin.Type, - ), + (words(("Color8", "ColorN", "abs", "acos", "asin", "assert", "atan", + "atan2", "bytes2var", "ceil", "char", "clamp", "convert", + "cos", "cosh", "db2linear", "decimals", "dectime", "deg2rad", + "dict2inst", "ease", "exp", "floor", "fmod", "fposmod", + "funcref", "hash", "inst2dict", "instance_from_id", "is_inf", + "is_nan", "lerp", "linear2db", "load", "log", "max", "min", + "nearest_po2", "pow", "preload", "print", "print_stack", + "printerr", "printraw", "prints", "printt", "rad2deg", + "rand_range", "rand_seed", "randf", "randi", "randomize", + "range", "round", "seed", "sign", "sin", "sinh", "sqrt", + "stepify", "str", "str2var", "tan", "tan", "tanh", + "type_exist", "typeof", "var2bytes", "var2str", "weakref", + "yield"), prefix=r"(?<!\.)", suffix=r"\b"), + Name.Builtin), + (r"((?<!\.)(self|false|true)|(PI|TAU|NAN|INF)" r")\b", + Name.Builtin.Pseudo), + (words(("bool", "int", "float", "String", "NodePath", "Vector2", + "Rect2", "Transform2D", "Vector3", "Rect3", "Plane", "Quat", + "Basis", "Transform", "Color", "RID", "Object", "NodePath", + "Dictionary", "Array", "PackedByteArray", "PackedInt32Array", + "PackedInt64Array", "PackedFloat32Array", "PackedFloat64Array", + "PackedStringArray", "PackedVector2Array", "PackedVector3Array", + "PackedColorArray", "null", "void"), + prefix=r"(?<!\.)", suffix=r"\b"), + Name.Builtin.Type), ], "numbers": [ (r"(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?", Number.Float), |