Revision 29548

Date:
2010/01/17 01:33:59
Author:
diakopter
Revision Log:
[sprixel] implement <commit>.
implement character_class.toString().
refactor sequence and alternation combinators to build breadth-first
instead of depth-first instructions.
Files:

Legend:

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

     
    356 356 );
    357 357 };
    358 358 gcc.prototype.toString = function() {
    359 return 'cc('+this.chars+')';
    359 var chars = this.chars[0].toProgramString();
    360 for (var i=1;i<this.chars.length;++i)
    361 chars += "','"+this.chars[i].toProgramString();
    362 return "cc('"+chars+"')";
    360 363 };
    361 364 gcc.prototype.regen = function(grammar) {
    362 365 return new gcc(this.chars);
     
    475 478 };
    476 479 gsinglec.prototype.root = singlec;
    477 480
    481 function commit() { return new gcommit() }
    482 function gcommit() { // grammar 'commit (fail entire match)' builder
    483 gts.call(this); // call the parent constructor
    484 this.b = true;
    485 this.init = new gtr();
    486 this.bt = new gtr();
    487 this.notd = new gtr();
    488 this.done = new gtr();
    489 }
    490 derives(gcommit, gts);
    491 gcommit.prototype.emit = function(c) {
    492 c.r.push(
    493 casel(this.init),
    494 d,
    495 dval('print("in commit")'),
    496 gotol(this.notd),
    497
    498 casel(this.bt),
    499 dval('print("backtracking commit")'),
    500 val("gl=1;break") // do not pass Go. do not collect 200 Perl 6 implementations.
    501 );
    502 };
    503 gcommit.prototype.toString = function() {
    504 return 'commit()';
    505 };
    506 gcommit.prototype.root = commit;
    507
    478 508 function gend() { // grammar "end anchor" parser builder
    479 509 gts.call(this); // call the parent constructor
    480 510 this.b = false;
     
    1689 1719 // we know which ones are recursive.
    1690 1720 for (var name in this.pats) {
    1691 1721 var pat = this.pats[name];
    1722 if (dbg)
    1723 print('compiling pattern '+name.toQuotedString()+' '+pat.l);
    1692 1724 if (pat.isRecursive && pat!==this.TOP) {
    1693 if (dbg)
    1694 print('compiling pattern '+name.toQuotedString());
    1695 1725 // reset the cancellable alternations counter.
    1696 1726 // TODO: comment following line if it's not needed.
    1697 1727 calt_count = 0;
     
    1768 1798 function seq() {
    1769 1799 return arguments.length == 1
    1770 1800 ? arguments[0]
    1771 : both(
    1801 : both(arguments[0],
    1772 1802 arguments.length > 2
    1773 ? seq.apply(null, popArgs.apply(null,arguments))
    1774 : arguments[0]
    1775 , arguments[arguments.length - 1]);
    1803 ? seq.apply(null, Array.prototype.slice.call(arguments, 1))
    1804 : arguments[1]
    1805 );
    1776 1806 }
    1777 1807 function alt() {
    1778 1808 return arguments.length == 1
    1779 1809 ? arguments[0]
    1780 : either(
    1810 : either(arguments[0],
    1781 1811 arguments.length > 2
    1782 ? alt.apply(null, popArgs.apply(null,arguments))
    1783 : arguments[0]
    1784 , arguments[arguments.length - 1]);
    1812 ? alt.apply(null, Array.prototype.slice.call(arguments, 1))
    1813 : arguments[1]
    1814 );
    1785 1815 }
    1786 1816 function lits() {
    1787 1817 var args = Array(arguments.length);
     
    1902 1932 ), plus(pref('backw'))),
    1903 1933 ows()
    1904 1934 ));
    1905 */
    1906 dbg=0;
    1907 1935
    1908 1936 var g = new Grammar('doublectest');
    1909 1937 g.addPattern('TOP', calt(alt(seq(lit('if'),doublec(),lit('not')),lit('ify'))));
     
    1916 1944 var g = new Grammar('singlectest');
    1917 1945 g.addPattern('TOP', seq(singlec(star(cc('a'))),cc('a')));
    1918 1946 g.compile(); g.parse(utf32str('aa'));
    1947 */
    1948 dbg=1;
    1919 1949
    1950 var g = new Grammar('committest');
    1951 g.addPattern('TOP', seq(star(cc('a')),commit(),cc('a')));
    1952 g.compile(); g.parse(utf32str('aa'));
    1953
    1920 1954 /*
    1921 1955 var sw = new Date();
    1922 1956 g.compile();