-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathroledecl.py
More file actions
executable file
·76 lines (54 loc) · 1.67 KB
/
Copy pathroledecl.py
File metadata and controls
executable file
·76 lines (54 loc) · 1.67 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
from ast.node import Node as Node
from ast.role import get_role_name as role_get_name
NAME_INDEX = 0
ALIAS_INDEX = 1
class RoleDecl(Node):
#name = None # string
#alias = None # string
def __init__(self, name, alias):
super(RoleDecl, self).__init__()
self.name = name
self.alias = alias
def pretty_print(self):
# self.alias is None for no alias
return _pretty_print_aux(self.name, self.alias)
def has_alias(self):
return self.alias is not None
def project(projector, node_):
name = get_role_name(node_)
alias = None
if has_alias(node_):
alias = get_alias_name(node_)
return projector.nf.roledecl(name, alias)
#return projector.nf.roledecl(name, None)
def has_alias(node_):
return node_.getChildCount() > 1 # Factor out constant?
def get_role_name(node_):
return role_get_name(get_role_child(node_))
def get_alias_name(node_):
if has_alias(node_):
return role_get_name(get_alias_child(node_))
else:
return None
##
# Section 4.1 -- role declaration name
def get_declaration_name(node_):
if node_.getChildCount() > 1:
return get_alias_name(node_)
else:
return get_role_name(node_)
def pretty_print(node_):
role = get_role_name(node_)
alias = None
if has_alias(node_):
alias = get_alias_name(node_)
return _pretty_print_aux(role, alias)
def _pretty_print_aux(name, alias):
text = 'role ' + name
if alias is not None:
text = text + ' as ' + alias
return text
def get_role_child(node_):
return node_.getChild(NAME_INDEX)
def get_alias_child(node_):
return node_.getChild(ALIAS_INDEX)