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