Revision 29549

Date:
2010/01/17 01:54:40
Author:
diakopter
Revision Log:
[sprixel] implement <.prior>
Files:

Legend:

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

     
    333 333 };
    334 334 glit.prototype.root = lit;
    335 335
    336 function prior() { return new gprior() }
    337 function gprior() { // grammar '<.prior> (literal constant string of last successful match)' parser builder
    338 gts.call(this); // call the parent constructor
    339 this.b = false;
    340 }
    341 derives(gprior, gts);
    342 var sprixel$$last_match;
    343 function sprixel$$get_last_match_str() {
    344 return (typeof sprixel$$last_match == 'undefined' ? 'sprixel$$last_match' : sprixel$$last_match).toString();
    345 }
    346 gprior.prototype.emit = function(c) {
    347 c.r.push(cond(ne(val('(cp=sprixel$$get_last_match_str())'),val("i.substr(o,cp.length)")),[[
    348 gotol(this.fail)
    349 ],[
    350 add_assign(o,val('cp.length'))
    351 ]]));
    352 };
    353 gprior.prototype.toString = function() {
    354 return 'prior()';
    355 };
    356 gprior.prototype.root = prior;
    357
    336 358 function cc() { return new gcc(arguments) }
    337 359 function gcc(chars) { // grammar 'character class' parser builder
    338 360 gts.call(this); // call the parent constructor
     
    1753 1775 Grammar.prototype.parse = function(input) {
    1754 1776 if (!this.compiled)
    1755 1777 this.compile();
    1756 return this.parser(input,this,0,0,{});
    1778 var res = this.parser(input,this,0,0,{});
    1779 if (typeof res != 'undefined')
    1780 return sprixel$$last_match = res;
    1781 // TODO: return Failure
    1757 1782 }
    1758 1783 Grammar.prototype.next = function(input,t,o) {
    1759 1784 return this.parser(input,this,-3,o,t);
     
    1784 1809 return this;
    1785 1810 return this.grammar.next(this.input,this.t,this.offset);
    1786 1811 }
    1812 Match.prototype.toString = function() {
    1813 return this.input.substr(0,this.offset);
    1814 }
    1787 1815
    1788 1816 // steal some macros/combinators from jsmeta
    1789 1817 function opt(l) { return either(l,empty()) }
     
    1944 1972 var g = new Grammar('singlectest');
    1945 1973 g.addPattern('TOP', seq(singlec(star(cc('a'))),cc('a')));
    1946 1974 g.compile(); g.parse(utf32str('aa'));
    1947 */
    1948 dbg=1;
    1949 1975
    1950 1976 var g = new Grammar('committest');
    1951 1977 g.addPattern('TOP', seq(star(cc('a')),commit(),cc('a')));
    1952 1978 g.compile(); g.parse(utf32str('aa'));
    1979 */
    1953 1980
    1981 var g = new Grammar('priortest');
    1982 g.addPattern('TOP', star(cc('a')));
    1983 g.compile(); g.parse(utf32str('aa'));
    1984 var g = new Grammar('priortest');
    1985 g.addPattern('TOP', repeat(prior(),2,2));
    1986 g.compile(); g.parse(utf32str('aaaa'));
    1987
    1988
    1954 1989 /*
    1955 1990 var sw = new Date();
    1956 1991 g.compile();