Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add yyless() ability to lexer (issue #84)

  • Loading branch information...
commit 7505e6c1d708ef384895366b505abf1795e60eaa 1 parent 3fe86e3
Zach Carter authored
Showing with 20 additions and 0 deletions.
  1. +4 −0 lib/jison/lexer.js
  2. +16 −0 tests/lexer/regexplexer.js
4 lib/jison/lexer.js
View
@@ -173,6 +173,10 @@ RegExpLexer.prototype = {
this._more = true;
return this;
},
+ // retain first n characters of the match
+ less: function (n) {
+ this._input = this.match.slice(n) + this._input;
+ },
// displays upcoming input, i.e. for error messages
pastInput: function () {
var past = this.matched.substr(0, this.matched.length - this.match.length);
16 tests/lexer/regexplexer.js
View
@@ -665,3 +665,19 @@ exports["test case insensitivity"] = function() {
assert.equal(lexer.lex(), "CAT");
};
+
+exports["test less"] = function() {
+ var dict = {
+ rules: [
+ ["cat", "this.less(2); return 'CAT';" ],
+ ["t", "return 'T';" ]
+ ],
+ };
+ var input = "cat";
+
+ var lexer = new RegExpLexer(dict);
+ lexer.setInput(input);
+
+ assert.equal(lexer.lex(), "CAT");
+ assert.equal(lexer.lex(), "T");
+};
Please sign in to comment.
Something went wrong with that request. Please try again.