Revision 29547

Date:
2010/01/17 01:05:46
Author:
diakopter
Revision Log:
[sprixel] implement : in patterns (modifier to repetition quantifiers or other alternations)
Files:

Legend:

 
Added
 
Removed
 
Modified
  • src/perl6/sprixel/jsemit.js

     
    430 430 };
    431 431 gdoublec.prototype.root = doublec;
    432 432
    433 function singlec(l) { return new gsinglec(l) }
    434 function gsinglec(l) { // grammar 'single colon (fail if backtracked over)' builder
    435 // note: a Perl 6 parser generator must wrap the prior atom in this, just like
    436 // the repetition operators.
    437 gts.call(this); // call the parent constructor
    438 this.b = true;
    439 this.l = l;
    440 if (!l.b) { // fake the labels
    441 this.l.done = new gtr();
    442 this.l.notd = new gtr();
    443 }
    444 this.init = new gtr();
    445 this.bt = new gtr();
    446 this.notd = new gtr();
    447 this.done = new gtr();
    448 }
    449 derives(gsinglec, gts);
    450 gsinglec.prototype.emit = function(c) {
    451 c.r.push(
    452 casel(this.init),
    453 d
    454 );
    455 this.l.emit(c);
    456 c.r.push(
    457 casel(this.l.done),
    458 a,
    459 gotol(this.done),
    460
    461 casel(this.l.notd),
    462 // val("t.i.l=t"), // don't need to save it since we're never backtracking.
    463 a,
    464 gotol(this.notd),
    465
    466 casel(this.l.fail),
    467 // backtrack does the same thing as fail
    468 casel(this.bt),
    469 a,
    470 gotol(this.fail)
    471 );
    472 };
    473 gsinglec.prototype.toString = function() {
    474 return 'singlec('+this.l+')';
    475 };
    476 gsinglec.prototype.root = singlec;
    477
    433 478 function gend() { // grammar "end anchor" parser builder
    434 479 gts.call(this); // call the parent constructor
    435 480 this.b = false;
     
    1862 1907
    1863 1908 var g = new Grammar('doublectest');
    1864 1909 g.addPattern('TOP', calt(alt(seq(lit('if'),doublec(),lit('not')),lit('ify'))));
    1865 g.compile(); g.parse(utf32str('verify'));
    1910 g.compile(); g.parse(utf32str('ify'));
    1866 1911
    1867 1912 var g = new Grammar('doublectest');
    1868 1913 g.addPattern('TOP', alt(calt(alt(seq(lit('if'),doublec(),lit('not')),lit('ify'))),lit('ify')));
    1869 1914 g.compile(); g.parse(utf32str('ify'));
    1870 1915
    1916 var g = new Grammar('singlectest');
    1917 g.addPattern('TOP', seq(singlec(star(cc('a'))),cc('a')));
    1918 g.compile(); g.parse(utf32str('aa'));
    1871 1919
    1872 1920 /*
    1873 1921 var sw = new Date();