Check-in [27e97d3b88]

Not logged in

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

Overview
Comment:Fixed an old but unnoticed bug in the parsing of termlists, introduced by the change from atoms being their own type to being 0-arity compounds.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:27e97d3b8891a262aba902a15c1f890626a58e4d
User & Date: andy 2015-04-14 12:55:12
Context
2015-04-14
12:55
Fixed a bug in the prototype chain for Terms, added a term equality function. check-in: 0ae8435916 user: andy tags: trunk
12:55
Fixed an old but unnoticed bug in the parsing of termlists, introduced by the change from atoms being their own type to being 0-arity compounds. check-in: 27e97d3b88 user: andy tags: trunk
12:54
Additional styles for rules, derivations (relying on the new classes in `term_render`). check-in: 526989d708 user: andy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/syntax.peg.

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
   * Convert nested conjunctions, of the form a , (b , (c , ...))
   * into the list [a,b,c,...].
   * The parser will generate conjunctions for the list of terms inside a
   * [] or the argument list to a compound. So in those contexts we have to 
   * convert it back into what it really is. 
   */
  function conjToList(c) {
    if(c.tt() !== 'compound')
      return [c]; // Not compound, nothing to do
    else if(c.head.name === ",") {
      var l = c.body[0], r = c.body[1];
      return [l].concat(conjToList(r));
    }
  }


  /* cleanupTerm(t)
................................................................................
definition 
  = l:(ruleName)? p:predicate         { return new parser.Predicate(p); }
  / i:infixDecl                       { 
      registerOp('infix', i); 
      return new parser.Operator('infix', i); }

// Predicate definitions can optionally have rule names attached to them
ruleName = '{' l:$((!'}')+) '}'       { return l; }

infixDecl = 'infix' __ op:(Atom / Symbol) __ '.'       { return op; }

predicate 
  = t:term __ '.'   { return t; }

term = t:infix  { return cleanupTerm(t); }
................................................................................
  = "-" &TAILS __ v:base { return new terms.Compound("-", [v]); }
  / "!" &TAILS __ v:base { return new terms.Compound("!", [v]); }
  / base

base 
  = compound
  / '[' __ ts:termList? __ ']'   { 
      return ts === null ? makeList([]) : makeList(ts); }
  / "(" __ t:term __ ")" { return t; }
  / a:Atom { return new terms.Atom(a); }
  / Variable

compound 
  = head:Atom __ "(" __ args:termList? __ ")" {
      // It's OK to pass null to Compound as the arguments; it will be







|

|







 







|







 







|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
   * Convert nested conjunctions, of the form a , (b , (c , ...))
   * into the list [a,b,c,...].
   * The parser will generate conjunctions for the list of terms inside a
   * [] or the argument list to a compound. So in those contexts we have to 
   * convert it back into what it really is. 
   */
  function conjToList(c) {
    if(c.tt() === 'variable' || c.isAtom())
      return [c]; // Not compound, nothing to do
    else if(c.head === ",") {
      var l = c.body[0], r = c.body[1];
      return [l].concat(conjToList(r));
    }
  }


  /* cleanupTerm(t)
................................................................................
definition 
  = l:(ruleName)? p:predicate         { return new parser.Predicate(p); }
  / i:infixDecl                       { 
      registerOp('infix', i); 
      return new parser.Operator('infix', i); }

// Predicate definitions can optionally have rule names attached to them
ruleName = '"' l:$((!'}')+) '"'       { return l; }

infixDecl = 'infix' __ op:(Atom / Symbol) __ '.'       { return op; }

predicate 
  = t:term __ '.'   { return t; }

term = t:infix  { return cleanupTerm(t); }
................................................................................
  = "-" &TAILS __ v:base { return new terms.Compound("-", [v]); }
  / "!" &TAILS __ v:base { return new terms.Compound("!", [v]); }
  / base

base 
  = compound
  / '[' __ ts:termList? __ ']'   { 
      return ts !== undefined ? makeList([]) : makeList(ts); }
  / "(" __ t:term __ ")" { return t; }
  / a:Atom { return new terms.Atom(a); }
  / Variable

compound 
  = head:Atom __ "(" __ args:termList? __ ")" {
      // It's OK to pass null to Compound as the arguments; it will be

Changes to src/syntax.peg.js.

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
....
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722

                return pr;
              },
        peg$c6 = function(l, p) { return new parser.Predicate(p); },
        peg$c7 = function(i) { 
              registerOp('infix', i); 
              return new parser.Operator('infix', i); },
        peg$c8 = "{",
        peg$c9 = { type: "literal", value: "{", description: "\"{\"" },
        peg$c10 = void 0,
        peg$c11 = "}",
        peg$c12 = { type: "literal", value: "}", description: "\"}\"" },
        peg$c13 = function(l) { return l; },
        peg$c14 = "infix",
        peg$c15 = { type: "literal", value: "infix", description: "\"infix\"" },
        peg$c16 = ".",
................................................................................
        peg$c81 = { type: "literal", value: "!", description: "\"!\"" },
        peg$c82 = function(v) { return new terms.Compound("!", [v]); },
        peg$c83 = "[",
        peg$c84 = { type: "literal", value: "[", description: "\"[\"" },
        peg$c85 = "]",
        peg$c86 = { type: "literal", value: "]", description: "\"]\"" },
        peg$c87 = function(ts) { 
              return ts === null ? makeList([]) : makeList(ts); },
        peg$c88 = "(",
        peg$c89 = { type: "literal", value: "(", description: "\"(\"" },
        peg$c90 = ")",
        peg$c91 = { type: "literal", value: ")", description: "\")\"" },
        peg$c92 = function(a) { return new terms.Atom(a); },
        peg$c93 = function(head, args) {
              // It's OK to pass null to Compound as the arguments; it will be
................................................................................

      if (cached) {
        peg$currPos = cached.nextPos;
        return cached.result;
      }

      s0 = peg$currPos;
      if (input.charCodeAt(peg$currPos) === 123) {
        s1 = peg$c8;
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c9); }
      }
      if (s1 !== peg$FAILED) {
................................................................................
          s3 = peg$c0;
        }
        if (s3 !== peg$FAILED) {
          s3 = input.substring(s2, peg$currPos);
        }
        s2 = s3;
        if (s2 !== peg$FAILED) {
          if (input.charCodeAt(peg$currPos) === 125) {
            s3 = peg$c11;
            peg$currPos++;
          } else {
            s3 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c12); }
          }
          if (s3 !== peg$FAILED) {
            peg$reportedPos = s0;
            s1 = peg$c13(s2);
            s0 = s1;
          } else {
            peg$currPos = s0;
................................................................................
       * Convert nested conjunctions, of the form a , (b , (c , ...))
       * into the list [a,b,c,...].
       * The parser will generate conjunctions for the list of terms inside a
       * [] or the argument list to a compound. So in those contexts we have to 
       * convert it back into what it really is. 
       */
      function conjToList(c) {
        if(c.tt() !== 'compound')
          return [c]; // Not compound, nothing to do
        else if(c.head.name === ",") {
          var l = c.body[0], r = c.body[1];
          return [l].concat(conjToList(r));
        }
      }


      /* cleanupTerm(t)







|
|







 







|







 







|







 







|
|



|







 







|

|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
....
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722

                return pr;
              },
        peg$c6 = function(l, p) { return new parser.Predicate(p); },
        peg$c7 = function(i) { 
              registerOp('infix', i); 
              return new parser.Operator('infix', i); },
        peg$c8 = "\"",
        peg$c9 = { type: "literal", value: "\"", description: "\"\\\"\"" },
        peg$c10 = void 0,
        peg$c11 = "}",
        peg$c12 = { type: "literal", value: "}", description: "\"}\"" },
        peg$c13 = function(l) { return l; },
        peg$c14 = "infix",
        peg$c15 = { type: "literal", value: "infix", description: "\"infix\"" },
        peg$c16 = ".",
................................................................................
        peg$c81 = { type: "literal", value: "!", description: "\"!\"" },
        peg$c82 = function(v) { return new terms.Compound("!", [v]); },
        peg$c83 = "[",
        peg$c84 = { type: "literal", value: "[", description: "\"[\"" },
        peg$c85 = "]",
        peg$c86 = { type: "literal", value: "]", description: "\"]\"" },
        peg$c87 = function(ts) { 
              return ts !== undefined ? makeList([]) : makeList(ts); },
        peg$c88 = "(",
        peg$c89 = { type: "literal", value: "(", description: "\"(\"" },
        peg$c90 = ")",
        peg$c91 = { type: "literal", value: ")", description: "\")\"" },
        peg$c92 = function(a) { return new terms.Atom(a); },
        peg$c93 = function(head, args) {
              // It's OK to pass null to Compound as the arguments; it will be
................................................................................

      if (cached) {
        peg$currPos = cached.nextPos;
        return cached.result;
      }

      s0 = peg$currPos;
      if (input.charCodeAt(peg$currPos) === 34) {
        s1 = peg$c8;
        peg$currPos++;
      } else {
        s1 = peg$FAILED;
        if (peg$silentFails === 0) { peg$fail(peg$c9); }
      }
      if (s1 !== peg$FAILED) {
................................................................................
          s3 = peg$c0;
        }
        if (s3 !== peg$FAILED) {
          s3 = input.substring(s2, peg$currPos);
        }
        s2 = s3;
        if (s2 !== peg$FAILED) {
          if (input.charCodeAt(peg$currPos) === 34) {
            s3 = peg$c8;
            peg$currPos++;
          } else {
            s3 = peg$FAILED;
            if (peg$silentFails === 0) { peg$fail(peg$c9); }
          }
          if (s3 !== peg$FAILED) {
            peg$reportedPos = s0;
            s1 = peg$c13(s2);
            s0 = s1;
          } else {
            peg$currPos = s0;
................................................................................
       * Convert nested conjunctions, of the form a , (b , (c , ...))
       * into the list [a,b,c,...].
       * The parser will generate conjunctions for the list of terms inside a
       * [] or the argument list to a compound. So in those contexts we have to 
       * convert it back into what it really is. 
       */
      function conjToList(c) {
        if(c.tt() === 'variable' || c.isAtom())
          return [c]; // Not compound, nothing to do
        else if(c.head === ",") {
          var l = c.body[0], r = c.body[1];
          return [l].concat(conjToList(r));
        }
      }


      /* cleanupTerm(t)