Skip to content

ajax.stx

pdmosses/webdsl-statix/webdslstatix/trans/static-semantics/ui/ajax.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module static-semantics/ui/ajax

imports
  static-semantics/types/built-ins

  static-semantics/ui/template-calls

  static-semantics/webdsl-ui
  static-semantics/webdsl

rules // placeholders and ajax

  templateElementOk(s, _, , TEPlaceholder(PlaceholderHtml(_, ph, elems))) :-
    declarePlaceholder(s_pha, ph),
    templateElementsOk(s, s_pha, elems).

  templateElementOk(, _, s_pha, TEPlaceholder(PlaceholderHtmlExp(_, e, elems))) :-
    typeCompatible(typeOfExp(s, e), string(s)) | error $[Expression should be compatible with String],
    templateElementsOk(s, s_pha, elems).

  templateElementOk(s, _, , TEPlaceholder(Placeholder(ph, elems))) :-
    declarePlaceholder(s_pha, ph),
    templateElementsOk(s, s_pha, elems).

  templateElementOk(, _, s_pha, TEPlaceholder(PlaceholderExp(e, elems))) :-
    typeCompatible(typeOfExp(s, e), string(s)) | error $[Expression should be compatible with String],
    templateElementsOk(s, s_pha, elems).

  templateElementOk(s, _, , TEPlaceholderWithAjaxCall(PlaceholderAjaxHtml(_, ph, tc))) :-
    declarePlaceholder(s_pha, ph),
    templateCallOk(s, s_pha, tc).

  templateElementOk(, _, s_pha, TEPlaceholderWithAjaxCall(PlaceholderAjaxHtmlExp(_, e, tc))) :-
    typeCompatible(typeOfPlaceholderExp(s, e), string(s)) | error $[Expression should be compatible with String],
    templateCallOk(s, s_pha, tc).

  templateElementOk(s, _, , TEPlaceholderWithAjaxCall(PlaceholderAjax(ph, tc))) :-
    declarePlaceholder(s_pha, ph),
    templateCallOk(s, s_pha, tc).

  templateElementOk(, _, s_pha, TEPlaceholderWithAjaxCall(PlaceholderAjaxExp(e, tc))) :-
    typeCompatible(typeOfPlaceholderExp(s, e), string(s)) | error $[Expression should be compatible with String],
    templateCallOk(s, s_pha, tc).

rules // ajax statements

  stmtOk(s, _, AjaxStatement(stmt), _) :- ajaxStmtOk(s, stmt).

   : scope * AjaxStatement

  ajaxStmtOk(, AjaxReplace(ph, AjaxReplaceTemplateCall())) :-
    ajaxPlaceholderExpressionOk(s, ph),
    ajaxTemplateCallOk(s, s, tc)
      | error $[An ajax-enabled template must be called here] @tc. // correct error message for tests

  ajaxStmtOk(, AjaxAppend(ph, )) :-
    ajaxPlaceholderExpressionOk(s, ph),
    ajaxTemplateCallOk(s, s, tc)
      | error $[An ajax-enabled template must be called here] @tc. // correct error message for tests

  ajaxStmtOk(s, AjaxVisibility(ph, _)) :-
    ajaxPlaceholderExpressionOk(s, ph).

  ajaxStmtOk(s, AjaxRelocate(pc)) :-
    pageCallOk(s, pc).

  ajaxStmtOk(, AjaxRestyle(ph, )) :-
    ajaxPlaceholderExpressionOk(s, ph),
    typeCompatible(typeOfExp(s, e), string(s)) | error $[CSS classname must be compatible with type String] @e.

  ajaxStmtOk(s, AjaxClear(ph)) :-
    ajaxPlaceholderExpressionOk(s, ph).

  ajaxStmtOk(s, AjaxRefresh()).

  ajaxStmtOk(, AjaxRunScript()) :-
    typeCompatible(typeOfExp(s, e), string(s)) | error $[Javascript code must be compatible with type String] @e.

   : scope * Exp
  ajaxPlaceholderExpressionOk(, ) :-
    typeCompatible(typeOfExp(s, e), string(s))
      | error $[Expression should be compatible with type string or a placeholder variable] @e.

  ajaxPlaceholderExpressionOk(, e@Var(ph)) :- {   }
    resolvePlaceholder(s, ph) == r,
    new s_next, s_next -P-> s,
    ajaxPlaceholderExpressionResultOk(s_next, r, e).

   : scope * list((path * (string * TYPE))) * Exp
  ajaxPlaceholderExpressionResultOk(s, r, e) :- false | error $[Unexpected input? r: [r], e: [e]].
  ajaxPlaceholderExpressionResultOk(s, [_ | _], _).

  ajaxPlaceholderExpressionResultOk(, [], ) :-
    typeCompatible(typeOfExp(s, e), string(s)) | error $[Type of expression [e] is not compatible with String or Placeholder] @e.