summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/jison_ext.js
blob: 0608034e7cd781f8a0f4050ffa9b26a454da9403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var Lexer = function() {};

Lexer.prototype = {
  setInput: function(input) {
    this.input = input;
    this.yylineno = 0;
  },

  setupLex: function() {
    this.yyleng = 0;
    this.yytext = '';
  },

  getchar: function(n) {
    n = n || 1;
    var char = "";

    for(var i=0; i<n; i++) {
      char += this.input[0];
      this.yytext += this.input[0];
      this.yyleng++;

      if(char === "\n") this.yylineno++;

      this.input = this.input.slice(1);
    }
    return char;
  },

  readchar: function(n) {
    n = n || 1;
    var char;

    for(var i=0; i<n; i++) {
      char = this.input[i];
      if(char === "\n") this.yylineno++;
    }

    this.input = this.input.slice(n);
  },

  peek: function(n) {
    return this.input.slice(0, n || 1);
  }
};

var Visitor = function() {};

Visitor.prototype = {
  accept: function(object) {
    return this[object.type](object);
  }
}

if(exports) {
  exports.Lexer = Lexer;
  exports.Visitor = Visitor;
}