Skip to content

attributes.stx

pdmosses/webdsl-statix/webdslstatix/trans/static-semantics/ui/attributes.stx

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
module 

imports
  static-semantics/types/built-ins

  static-semantics/webdsl-types
  static-semantics/webdsl

signature
  relations
     : string

rules // attribute collection declaration and resolving

   : scope * string
  declareAttributeCollection(, ) :-
    !attributeCollection[c] in s,
    resolveAttributeCollection(s, c) == [_] | error $[Attribute collection with name [c] is defined multiple times. Use "override" modifier to replace existing attribute collections]. // correct error message for tests

   : scope * string -> list((path * string))
  resolveAttributeCollection(s, c) = ps :-
    query attributeCollection
      filter P* F* ((EXTEND? INHERIT*) | (DEF? (IMPORT | IMPORTLIB)?))
      and { c' :- c' == c }
      in s |-> ps.

rules // attributes

   maps attributeOk(*, list(*))
   : scope * Attribute
  attributeOk(s, a@AttributeSelection2Attribute(_)) :- try { false } | warning $[This UI attribute is not implemented yet] @a.
  attributeOk(s, AttributeExpandLocal(_, _, _)) :- try { false } | warning $[This UI attribute is not implemented yet].

  attributeOk(s, Attribute(_, exp)) :- typed(s, exp).
  attributeOk(, XMLAttributesIf(, attributes)) :-
    equalType(typeOfExp(s, c), bool(s)) | error $[Condition should be of type bool] @c,
    attributesOk(s, attributes).

  attributeOk(, XMLAttributesIfElse(, attributes_if, attributes_else)) :-
    equalType(typeOfExp(s, c), bool(s)) | error $[Condition should be of type bool] @c,
    attributesOk(s, attributes_if),
    attributesOk(s, attributes_else).

  attributeOk(s, CommonAttribute2Attribute(ca)) :- commonAttributeOk(s, ca).

   : scope * CommonAttribute
  commonAttributeOk(_, _) :- try { false } | warning $[This common attribute is not yet implemented].
  commonAttributeOk(s, AllAttributes()).
  commonAttributeOk(, AllAttributesExceptExp()) :- {}
    t == typeOfExp(s, exp),
    or(
      typeCompatibleB(string(s), t),
      orB(
        typeCompatibleB(LIST(string(s)), t),
        typeCompatibleB(SET(string(s)), t)
      )
    ) | error $[Attribute names should be of type String, List of String of Set of String, but type [t] given] @exp.

  commonAttributeOk(, AttributesExp()) :- {}
    t == typeOfExp(s, exp),
    or(
      typeCompatibleB(string(s), t),
      orB(
        typeCompatibleB(LIST(string(s)), t),
        typeCompatibleB(SET(string(s)), t)
      )
    ) | error $[Attribute names should be of type String, List of String of Set of String, but type [t] given] @exp.

rules // attribute collections

  defOk(s, AttributeCollection(AttributeCollectionOverrideNone(), c, attrs)) :-
    declareAttributeCollection(s, c).

  defOk(s, AttributeCollection(AttributeCollectionOverride(), , attrs)) :- {}
    resolveAttributeCollection(s, c) == [(_, c')] | error $[Attribute collection with name [c] not defined] @c, // correct error message for tests
    @c.ref := c'.