codekingpro/portable-devtools
114k
1"""2 pygments.lexers.usd3 ~~~~~~~~~~~~~~~~~~~4 5 The module that parses Pixar's Universal Scene Description file format.6 7 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.8 :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups12from pygments.lexer import words as words_13from pygments.lexers._usd_builtins import COMMON_ATTRIBUTES, KEYWORDS, \14 OPERATORS, SPECIAL_NAMES, TYPES15from pygments.token import Comment, Keyword, Name, Number, Operator, \16 Punctuation, String, Text, Whitespace17 18__all__ = ["UsdLexer"]19 20 21def _keywords(words, type_):22 return [(words_(words, prefix=r"\b", suffix=r"\b"), type_)]23 24 25_TYPE = r"(\w+(?:\[\])?)"26_BASE_ATTRIBUTE = r"(\w+(?:\:\w+)*)(?:(\.)(timeSamples))?"27_WHITESPACE = r"([ \t]+)"28 29 30class UsdLexer(RegexLexer):31 """32 A lexer that parses Pixar's Universal Scene Description file format.33 """34 35 name = "USD"36 url = 'https://graphics.pixar.com/usd/release/index.html'37 aliases = ["usd", "usda"]38 filenames = ["*.usd", "*.usda"]39 version_added = '2.6'40 41 tokens = {42 "root": [43 (rf"(custom){_WHITESPACE}(uniform)(\s+){_TYPE}(\s+){_BASE_ATTRIBUTE}(\s*)(=)",44 bygroups(Keyword.Token, Whitespace, Keyword.Token, Whitespace,45 Keyword.Type, Whitespace, Name.Attribute, Text,46 Name.Keyword.Tokens, Whitespace, Operator)),47 (rf"(custom){_WHITESPACE}{_TYPE}(\s+){_BASE_ATTRIBUTE}(\s*)(=)",48 bygroups(Keyword.Token, Whitespace, Keyword.Type, Whitespace,49 Name.Attribute, Text, Name.Keyword.Tokens, Whitespace,50 Operator)),51 (rf"(uniform){_WHITESPACE}{_TYPE}(\s+){_BASE_ATTRIBUTE}(\s*)(=)",52 bygroups(Keyword.Token, Whitespace, Keyword.Type, Whitespace,53 Name.Attribute, Text, Name.Keyword.Tokens, Whitespace,54 Operator)),55 (rf"{_TYPE}{_WHITESPACE}{_BASE_ATTRIBUTE}(\s*)(=)",56 bygroups(Keyword.Type, Whitespace, Name.Attribute, Text,57 Name.Keyword.Tokens, Whitespace, Operator)),58 ] +59 _keywords(KEYWORDS, Keyword.Tokens) +60 _keywords(SPECIAL_NAMES, Name.Builtins) +61 _keywords(COMMON_ATTRIBUTES, Name.Attribute) +62 [(r"\b\w+:[\w:]+\b", Name.Attribute)] +63 _keywords(OPERATORS, Operator) + # more attributes64 [(type_ + r"\[\]", Keyword.Type) for type_ in TYPES] +65 _keywords(TYPES, Keyword.Type) +66 [67 (r"[(){}\[\]]", Punctuation),68 ("#.*?$", Comment.Single),69 (",", Punctuation),70 (";", Punctuation), # ";"s are allowed to combine separate metadata lines71 ("=", Operator),72 (r"[-]*([0-9]*[.])?[0-9]+(?:e[+-]*\d+)?", Number),73 (r"'''(?:.|\n)*?'''", String),74 (r'"""(?:.|\n)*?"""', String),75 (r"'.*?'", String),76 (r'".*?"', String),77 (r"<(\.\./)*([\w/]+|[\w/]+\.\w+[\w:]*)>", Name.Namespace),78 (r"@.*?@", String.Interpol),79 (r'\(.*"[.\\n]*".*\)', String.Doc),80 (r"\A#usda .+$", Comment.Hashbang),81 (r"\s+", Whitespace),82 (r"\w+", Text),83 (r"[_:.]+", Punctuation),84 ],85 }86 