forked from secondlife/lsl-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeywords.py
More file actions
121 lines (105 loc) · 5.03 KB
/
Copy pathkeywords.py
File metadata and controls
121 lines (105 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""Generators for viewer syntax/keywords XML files."""
from __future__ import annotations
import llsd
from lsl_definitions.generators.base import register
from lsl_definitions.lsl import LSLDefinitions
from lsl_definitions.slua import SLuaDefinitions
@register("syntax")
def dump_syntax(definitions: LSLDefinitions, *, pretty: bool = False) -> bytes:
"""Generate LSL syntax XML for viewer"""
header_comment = b"""<!-- LSL (Linden Scripting Language) keywords file for Second Life Viewer.
This file is auto-generated by https://github.com/secondlife/lsl-definitions. -->"""
syntax = {
"controls": definitions.controls.copy(),
"types": definitions.types.copy(),
"constants": {},
"events": {},
"functions": {},
"llsd-lsl-syntax-version": 2,
}
for event in sorted(definitions.events.values(), key=lambda x: x.name):
if event.private:
continue
syntax["events"][event.name] = event.to_dict()
for func in sorted(definitions.functions.values(), key=lambda x: x.name):
if func.private:
continue
syntax["functions"][func.name] = func.to_dict()
for const in sorted(definitions.constants.values(), key=lambda x: x.name):
if const.private:
continue
syntax["constants"][const.name] = const.to_dict()
# This one's a little weird because it's not a "real" constant, but it's expected to be in the
# constants section even though it has no value or type. It allows default to have a tooltip
# and a distinct color.
syntax["constants"]["default"] = syntax["controls"].pop("default")
if pretty:
output = llsd.LLSDXMLPrettyFormatter(indent_atom=b" ").format(syntax)
header_comment = b"\n" + header_comment
else:
output = llsd.format_xml(syntax)
start_offset = output.find(b"?>") + 2
output = output[:start_offset] + header_comment + output[start_offset:]
return output
@register("slua_syntax")
def dump_slua_syntax(
definitions: LSLDefinitions,
slua_definitions: SLuaDefinitions,
*,
pretty: bool = False,
) -> bytes:
"""Generate SLua syntax XML for viewer"""
ll_module = slua_definitions.modules["ll"]
header_comment = b"""<!-- SLua (Server Lua) keywords file for Second Life Viewer.
This file is auto-generated by https://github.com/secondlife/lsl-definitions. -->"""
syntax = {
"controls": slua_definitions.controls.copy(),
"types": slua_definitions.builtin_types.copy(),
"constants": {},
"events": {},
"functions": {},
"llsd-lsl-syntax-version": 2,
}
# types
for class_ in sorted(slua_definitions.base_classes.values(), key=lambda x: x.name):
syntax["types"][class_.name] = class_.to_keywords_dict()
for alias in sorted(slua_definitions.type_aliases.values(), key=lambda x: x.name):
if alias.export:
syntax["types"][alias.name] = alias.to_keywords_dict()
for class_ in sorted(slua_definitions.classes.values(), key=lambda x: x.name):
syntax["types"][class_.name] = class_.to_keywords_dict()
# events
for event in sorted(definitions.events.values(), key=lambda x: x.name):
if event.slua_removed:
continue
syntax["events"][event.name] = event.to_slua_dict(slua_definitions)
# functions
for func in sorted(slua_definitions.functions.values(), key=lambda x: x.name):
if not func.local_only and not func.slua_removed:
syntax["functions"][func.name] = func.to_keywords_dict()
for module in sorted(slua_definitions.modules.values(), key=lambda x: x.name):
if module.name not in {"ll", "llcompat"}:
syntax["functions"].update(module.to_keywords_functions_dict())
syntax["functions"].update(ll_module.to_keywords_functions_dict())
for func in sorted(definitions.functions.values(), key=lambda x: x.name):
if not func.private and not func.slua_removed:
syntax["functions"][func.compute_slua_name()] = func.to_slua_dict(slua_definitions)
# constants
for const in slua_definitions.builtin_constants.values():
syntax["constants"][const.name] = const.to_keywords_dict()
for module in sorted(slua_definitions.modules.values(), key=lambda x: x.name):
syntax["constants"].update(module.to_keywords_constants_dict())
for const in sorted(definitions.constants.values(), key=lambda x: x.name):
if not const.private and not const.slua_removed:
syntax["constants"][const.name] = const.to_slua_dict(slua_definitions)
for const in slua_definitions.global_constants.values():
if const.name not in syntax["constants"] and not const.private:
syntax["constants"][const.name] = const.to_keywords_dict()
if pretty:
output = llsd.LLSDXMLPrettyFormatter(indent_atom=b" ").format(syntax)
header_comment = b"\n" + header_comment
else:
output = llsd.format_xml(syntax)
start_offset = output.find(b"?>") + 2
output = output[:start_offset] + header_comment + output[start_offset:]
return output