Check-in [0ce4e1a109]

Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The REPL example now uses the client-side parser to check inputs for syntactical correctness.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0ce4e1a1092177ea64c67aabf29de404b6f0278c
User & Date: andy 2015-04-14 13:51:03
Context
2015-04-14
14:00
Better rendering of goals vs. terms. Subgoals of AND, OR, and IMP are now rendered as goals rather than terms. check-in: 8cf949cd23 user: andy tags: trunk
13:51
The REPL example now uses the client-side parser to check inputs for syntactical correctness. check-in: 0ce4e1a109 user: andy tags: trunk
13:50
Fixed a couple other bugs related to atoms-as-compounds. Changed the definition of symbolic tokens to *not* include commas, as it was misparsing things like `a,` as a single token. check-in: 5423c478ca user: andy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/repl.html.

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
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140




141
142
143
144
145
146
147
...
148
149
150
151
152
153
154
155
156
157
158








159
160
161


162
163
164
165
166
167

168





169
170
171
172
173
174
175
      }

      // Test the conversion of JS terms, to strings, to Prolog, to JSON,
      // and finally back to JS terms
      function term_test(s) {
          var t = arend.parser.parse(s, { startRule: "term" });
          var query = arend.terms.toPrologString(t);
          console.log(query + "\n" + t.toString());

          (new Pengine({
              application: "repl",
              ask: "identity(" + query + ",Result)",
              onsuccess: function() {
                var json = this.data[0]['Result'];
                var term = arend.terms.fromJSON(json);

                console.log(arend.terms.toPrologString(term));

              }
          }))
      }

      function handleSuccess() {
          $("#controls button").prop('disabled',false);

          // The data returned by the server takes the form of an array of
          // logic variable bindings. The array is used because multiple
          // (non-deterministic) results may be returned in a "chunk" (although
          // this has to be enabled, so we will never get more than one result).
          // Variable bindings are represented as an object mapping variable 
          // names to (JSON) terms. So in our case we have
          // [{ "Result" : json... }]
................................................................................
          repl.rawPrint(renderer.renderProof(solution)); 

          var subst = solution.body[2];
          repl.rawPrint("<div class='subst'>" + 
                        renderer.renderSubst(subst) +
                        "</div>");

          repl.locked = false;
      }

      function handleFailure() {
          repl.print("False: No (more) solutions");
          repl.locked = false;
          $("#controls button").prop('disabled',false);
      }

      function handleError() {
          repl.print(this.data);




          repl.locked = false;
          $("#controls button").prop('disabled',false);
      }

      function processInput(s) {
        repl.locked = true;
        repl.echo(s);
................................................................................

        // Make controls visible (they are initially hidden), but disabled
        // We don't want the user clicking them while the request is still
        // in progress. (After the request has returned they will be enabled.)
        $("#controls").show();
        $("#controls button").prop('disabled',true);


        // Queries come with a trailing . which is not part of the term that
        // we want to send to Prolog, so we strip it off.
        s = s.trim(); // Remove leading/trailing spaces.








        s = s.substring(0,s.length - 1);

        // Parse the input into a (JS) term


        //var term = arend.parser.parse(s, {startRule: 'term'});

        // Convert JS term to JSON
        //json = arend.terms.toJSON(term);

        // Send to PEngine for processing

        query(s);





      }

      // Render all the rules in the specification and append them to 
      // #specification.
      function renderSpecification() {
        
        var spec = $("#specification");







|








|
>





<
<







 







|




|
<




>
>
>
>







 







<



>
>
>
>
>
>
>
>
|

|
>
>
|
<
<
|

|
>
|
>
>
>
>
>







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
...
122
123
124
125
126
127
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173


174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
      }

      // Test the conversion of JS terms, to strings, to Prolog, to JSON,
      // and finally back to JS terms
      function term_test(s) {
          var t = arend.parser.parse(s, { startRule: "term" });
          var query = arend.terms.toPrologString(t);
          console.log("Input: " + query);

          (new Pengine({
              application: "repl",
              ask: "identity(" + query + ",Result)",
              onsuccess: function() {
                var json = this.data[0]['Result'];
                var term = arend.terms.fromJSON(json);

                console.log("Prolog: " + arend.terms.toPrologString(term));
                console.log("Normal: " + term.toString());
              }
          }))
      }

      function handleSuccess() {


          // The data returned by the server takes the form of an array of
          // logic variable bindings. The array is used because multiple
          // (non-deterministic) results may be returned in a "chunk" (although
          // this has to be enabled, so we will never get more than one result).
          // Variable bindings are represented as an object mapping variable 
          // names to (JSON) terms. So in our case we have
          // [{ "Result" : json... }]
................................................................................
          repl.rawPrint(renderer.renderProof(solution)); 

          var subst = solution.body[2];
          repl.rawPrint("<div class='subst'>" + 
                        renderer.renderSubst(subst) +
                        "</div>");

          unlock();
      }

      function handleFailure() {
          repl.print("False: No (more) solutions");
          unlock()

      }

      function handleError() {
          repl.print(this.data);
          unlock()
      }

      function unlock() {
          repl.locked = false;
          $("#controls button").prop('disabled',false);
      }

      function processInput(s) {
        repl.locked = true;
        repl.echo(s);
................................................................................

        // Make controls visible (they are initially hidden), but disabled
        // We don't want the user clicking them while the request is still
        // in progress. (After the request has returned they will be enabled.)
        $("#controls").show();
        $("#controls button").prop('disabled',true);


        // Queries come with a trailing . which is not part of the term that
        // we want to send to Prolog, so we strip it off.
        s = s.trim(); // Remove leading/trailing spaces.

        // Check to make sure the . is actually there.
        if(!s.endsWith(".")) {
            repl.print("Syntax error: queries must end with '.'");
            unlock()
            return;
        }
        else
            s = s.substring(0,s.length - 1);

        // Parse the input into a (JS) term, and then convert it to a 
        // Prolog-compatible term string
        try {
            var t = arend.parser.parse(s, { startRule: "term" });


            var q = arend.terms.toPrologString(t);

            // Send to PEngine for processing
            console.log("Query: " + q);
            query(q);
        }
        catch(e) {
            repl.print("Syntax error");
            unlock();
        }
      }

      // Render all the rules in the specification and append them to 
      // #specification.
      function renderSpecification() {
        
        var spec = $("#specification");